From 9283f857f115cde44f2031cd545cad363fb5274d Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Mon, 12 Jul 2021 18:35:08 +0100 Subject: [PATCH] Improve warning message for missing ImageOS env. variable (self-hosted runners) (#59) --- .github/workflows/action.yml | 20 ++++++++++++++++---- README.md | 29 +++++++++++++++++++++++++++++ __tests__/setup-beam.test.js | 2 +- dist/index.js | 13 ++++++++++++- src/setup-beam.js | 13 ++++++++++++- 5 files changed, 70 insertions(+), 7 deletions(-) diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index b30a304..1e9e468 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: '12' + node-version: 12 - run: npm install -g npm - run: npm install - run: npm run build @@ -31,12 +31,24 @@ jobs: - name: Check if build left artifacts run: git diff --exit-code - unit_test: - name: Unit tests + unit_tests_ubuntu: + name: Unit tests (Ubuntu) runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 - with: {node-version: '12'} + with: + node-version: 12 - run: npm ci - run: npm test + + unit_tests_windows: + name: Unit tests (Windows) + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 12 + - run: npm install --production + - run: npm test diff --git a/README.md b/README.md index f232fb3..d24b36a 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,35 @@ and Erlang/OTP. **Note** *: prior to 23, Windows builds are only available for minor versions, e.g. 21.0, 21.3, 22.0, etc. +### Self-hosted runners + +Self-hosted runners need to set env. variable `ImageOS` to one of the following, since the action +uses that to download assets: + +| ImageOS | Operating system +|- |- +| ubuntu16 | ubuntu-16.04 +| ubuntu18 | ubuntu-18.04 +| ubuntu20 | ubuntu-20.04 +| win16 | windows-2016 +| win19 | windows-2019 + +as per the following example: + +```yaml +... + +jobs: + test: + runs-on: self-hosted + env: + ImageOS: ubuntu20 # equivalent to runs-on ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - uses: erlef/setup-beam@v1 + ... +``` + ### Basic example (Erlang/OTP + Elixir, on Ubuntu) ```yaml diff --git a/__tests__/setup-beam.test.js b/__tests__/setup-beam.test.js index 394b03a..7dfca90 100644 --- a/__tests__/setup-beam.test.js +++ b/__tests__/setup-beam.test.js @@ -136,7 +136,7 @@ async function testOTPVersions() { spec = '23.2.x' osVersion = 'windows-2016' - expected = '23.2.7.4' + expected = '23.2.7' got = await setupBeam.getOTPVersion(spec, osVersion) assert.deepStrictEqual(got, expected) diff --git a/dist/index.js b/dist/index.js index 6a97199..3b76cec 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5001,8 +5001,19 @@ function getRunnerOSVersion() { win16: 'windows-2016', win19: 'windows-2019', } + const containerFromEnvImageOS = ImageOSToContainer[process.env.ImageOS] - return ImageOSToContainer[process.env.ImageOS] + if (!containerFromEnvImageOS) { + throw new Error( + "Tried to map a target OS from env. variable 'ImageOS', but failed. If you're using a " + + "self-hosted runner, you should set 'env': 'ImageOS': ... to one of the following: " + + "['" + + `${Object.keys(ImageOSToContainer).join("', '")}` + + "']", + ) + } + + return containerFromEnvImageOS } async function get(url0, pageIdxs) { diff --git a/src/setup-beam.js b/src/setup-beam.js index 125f874..0dfee5f 100644 --- a/src/setup-beam.js +++ b/src/setup-beam.js @@ -345,8 +345,19 @@ function getRunnerOSVersion() { win16: 'windows-2016', win19: 'windows-2019', } + const containerFromEnvImageOS = ImageOSToContainer[process.env.ImageOS] - return ImageOSToContainer[process.env.ImageOS] + if (!containerFromEnvImageOS) { + throw new Error( + "Tried to map a target OS from env. variable 'ImageOS', but failed. If you're using a " + + "self-hosted runner, you should set 'env': 'ImageOS': ... to one of the following: " + + "['" + + `${Object.keys(ImageOSToContainer).join("', '")}` + + "']", + ) + } + + return containerFromEnvImageOS } async function get(url0, pageIdxs) {