diff --git a/.eslintrc.yml b/.eslintrc.yml index 39ace7e..d0dcfc2 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -9,7 +9,6 @@ parserOptions: rules: indent: ["warn", 2] max-len: ["warn", 100] - no-console: 0 no-undef: "error" no-unused-vars: ["error", {"varsIgnorePattern": "^_"}] no-use-before-define: 0 diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 360c812..ce652cb 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -46,7 +46,7 @@ jobs: id: setup-beam uses: ./ with: - version-file: __tests__/.tool-versions + version-file: test/.tool-versions version-type: strict unit_tests_windows: diff --git a/.github/workflows/hexpm-mirrors.yml b/.github/workflows/hexpm-mirrors.yml index b87d1da..2bc5493 100644 --- a/.github/workflows/hexpm-mirrors.yml +++ b/.github/workflows/hexpm-mirrors.yml @@ -35,24 +35,3 @@ jobs: https://mirror.invalid https://cdn.jsdelivr.net/hex https://builds.hex.pm - - test-invalid-mirror: - name: Test errors with mirror - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - name: Use erlef/setup-beam - id: failing-setup-beam - uses: ./ - continue-on-error: true - with: - otp-version: '24.3.4.6' - elixir-version: 'v1.13.4' - install-rebar: true - install-hex: true - hexpm-mirrors: https://mirror.invalid - - name: Report unexpected success - if: ${{ steps.failing-setup-beam.outcome == 'success' }} - run: | - echo "Action is expected to fail" - exit 1 diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 6e07fd1..b0b0638 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -53,7 +53,7 @@ jobs: os: 'ubuntu-latest' - elixir-version: 'v1.4' otp-version: '20' - rebar3-version: '3.6.0' + rebar3-version: '3.15.0' os: 'ubuntu-20.04' - elixir-version: 'v1.4' otp-version: '20' @@ -165,23 +165,23 @@ jobs: if: ${{matrix.combo.elixir-version}} - name: Run Elixir/Mix project tests run: | - cd test-projects/elixir_mix + cd test/projects/elixir_mix mix deps.get mix test if: ${{matrix.combo.elixir-version}} - name: Run Erlang/rebar3 project tests run: | - cd test-projects/erlang_rebar3 + cd test/projects/erlang_rebar3 rebar3 ct if: ${{matrix.combo.rebar3-version}} - name: Format Gleam project (without installing Erlang/OTP) run: | - cd test-projects/gleam_gleam + cd test/projects/gleam_gleam gleam format if: ${{ matrix.combo.gleam-version && !matrix.combo.otp-version }} - name: Run Gleam project tests (without `rebar3`) run: | - cd test-projects/gleam_gleam + cd test/projects/gleam_gleam gleam test if: ${{ matrix.combo.gleam-version && matrix.combo.otp-version && !matrix.combo.rebar3-version }} - name: Run escript diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 6f51869..350c770 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -79,7 +79,7 @@ jobs: if: ${{matrix.combo.rebar3-version}} - name: rebar3 from Rust run: | - cd test-projects/rust_rebar3_cmd + cd test/projects/rust_rebar3_cmd cargo test -- --nocapture if: ${{matrix.combo.rebar3-version}} - name: mix version and help (CLI) @@ -90,13 +90,13 @@ jobs: if: ${{matrix.combo.elixir-version}} - name: Run Elixir/Mix project tests run: | - cd test-projects/elixir_mix + cd test/projects/elixir_mix mix deps.get mix test if: ${{matrix.combo.elixir-version}} - name: Run Erlang/rebar3 project tests run: | - cd test-projects/erlang_rebar3 + cd test/projects/erlang_rebar3 rebar3 ct if: ${{matrix.combo.rebar3-version}} - name: Run escript diff --git a/.gitignore b/.gitignore index cf5dea3..40e3512 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ node_modules/** dist/.github/workflows -__tests__/.tool-versions +test/.tool-versions diff --git a/MATCHER_NOTICE.md b/MATCHER_NOTICE.md index ab9ac8a..40d3f1f 100644 --- a/MATCHER_NOTICE.md +++ b/MATCHER_NOTICE.md @@ -1,6 +1,6 @@ # Elixir Problem Matchers -Elixir Problem Matchers in [elixir-matchers.json](.github/elixir-matchers.json) +Elixir Problem Matchers in [elixir-matchers.json](matchers/elixir-matchers.json) are adapted from [here](https://github.com/fr1zle/vscode-elixir/blob/45eddb589acd7ac98e0c7305d1c2b24668ca709a/package.json#L70-L118), available under the [MIT license](https://github.com/fr1zle/vscode-elixir/blob/45eddb589acd7ac98e0c7305d1c2b24668ca709a/LICENSE.md): diff --git a/.github/elixir-matchers.json b/dist/elixir-matchers.json similarity index 100% rename from .github/elixir-matchers.json rename to dist/elixir-matchers.json diff --git a/dist/index.js b/dist/index.js index 8fd3f68..b110276 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7303,13 +7303,11 @@ async function main() { async function installOTP(otpSpec, osVersion, hexMirrors) { const otpVersion = await getOTPVersion(otpSpec, osVersion, hexMirrors) - console.log( - `##[group]Installing Erlang/OTP ${otpVersion} - built on ${osVersion}`, - ) + core.startGroup(`Installing Erlang/OTP ${otpVersion} - built on ${osVersion}`) await installer.installOTP(osVersion, otpVersion, hexMirrors) core.setOutput('otp-version', otpVersion) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/otp/bin`) - console.log('##[endgroup]') + core.endGroup() return otpVersion } @@ -7323,19 +7321,17 @@ async function maybeInstallElixir(elixirSpec, otpSpec, hexMirrors) { otpSpec, hexMirrors, ) - console.log(`##[group]Installing Elixir ${elixirVersion}`) + core.startGroup(`Installing Elixir ${elixirVersion}`) await installer.installElixir(elixirVersion, hexMirrors) core.setOutput('elixir-version', elixirVersion) const disableProblemMatchers = getInput('disable_problem_matchers', false) if (disableProblemMatchers === 'false') { - const matchersPath = __nccwpck_require__.ab + ".github" - console.log( - `##[add-matcher]${path.join(matchersPath, 'elixir-matchers.json')}`, - ) + const elixirMatchers = __nccwpck_require__.ab + "elixir-matchers.json" + core.info(`##[add-matcher]${elixirMatchers}`) } core.addPath(`${os.homedir()}/.mix/escripts`) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/elixir/bin`) - console.log('##[endgroup]') + core.endGroup() installed = true } @@ -7363,9 +7359,9 @@ async function mix(shouldMix, what, hexMirrors) { if (shouldMix === 'true') { const cmd = 'mix' const args = [`local.${what}`, '--force'] - console.log(`##[group]Running ${cmd} ${args}`) + core.startGroup(`Running ${cmd} ${args}`) await mixWithMirrors(cmd, args, hexMirrors) - console.log('##[endgroup]') + core.endGroup() } } @@ -7374,11 +7370,11 @@ async function maybeInstallGleam(gleamSpec) { if (gleamSpec) { const gleamVersion = await getGleamVersion(gleamSpec) - console.log(`##[group]Installing Gleam ${gleamVersion}`) + core.startGroup(`Installing Gleam ${gleamVersion}`) await installer.installGleam(gleamVersion) core.setOutput('gleam-version', gleamVersion) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/gleam/bin`) - console.log('##[endgroup]') + core.endGroup() installed = true } @@ -7396,11 +7392,11 @@ async function maybeInstallRebar3(rebar3Spec) { } else { rebar3Version = await getRebar3Version(rebar3Spec) } - console.log(`##[group]Installing rebar3 ${rebar3Version}`) + core.startGroup(`Installing rebar3 ${rebar3Version}`) await installer.installRebar3(rebar3Version) core.setOutput('rebar3-version', rebar3Version) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/rebar3/bin`) - console.log('##[endgroup]') + core.endGroup() installed = true } @@ -7493,16 +7489,16 @@ async function getRebar3Version(r3Spec) { async function getOTPVersions(osVersion, hexMirrors) { let otpVersionsListings + let originListing if (process.platform === 'linux') { - otpVersionsListings = await getWithMirrors( - `/builds/otp/${osVersion}/builds.txt`, - hexMirrors, - ) + originListing = `/builds/otp/${osVersion}/builds.txt` + otpVersionsListings = await getWithMirrors(originListing, hexMirrors) } else if (process.platform === 'win32') { - const originListing = + originListing = 'https://api.github.com/repos/erlang/otp/releases?per_page=100' otpVersionsListings = await get(originListing, [1, 2, 3]) } + debugLog(`OTP versions listings from ${originListing}`, otpVersionsListings) const otpVersions = new Map() @@ -7519,7 +7515,7 @@ async function getOTPVersions(osVersion, hexMirrors) { }) } else if (process.platform === 'win32') { otpVersionsListings.forEach((otpVersionsListing) => { - jsonParse(otpVersionsListing) + jsonParseAsList(otpVersionsListing) .map((x) => x.assets) .flat() .filter((x) => x.name.match(/^otp_win64_.*.exe$/)) @@ -7566,7 +7562,7 @@ async function getGleamVersions() { ) const gleamVersionsListing = [] resultJSONs.forEach((resultJSON) => { - jsonParse(resultJSON) + jsonParseAsList(resultJSON) .map((x) => x.tag_name) .sort() .forEach((v) => gleamVersionsListing.push(v)) @@ -7581,7 +7577,7 @@ async function getRebar3Versions() { ) const rebar3VersionsListing = [] resultJSONs.forEach((resultJSON) => { - jsonParse(resultJSON) + jsonParseAsList(resultJSON) .map((x) => x.tag_name) .sort() .forEach((v) => rebar3VersionsListing.push(v)) @@ -7772,7 +7768,7 @@ function parseVersionFile(versionFilePath0) { `The specified version file, ${versionFilePath0}, does not exist`, ) } - console.log(`##[group]Parsing version file at ${versionFilePath0}`) + core.startGroup(`Parsing version file at ${versionFilePath0}`) const appVersions = new Map() const versions = fs.readFileSync(versionFilePath, 'utf8') // For the time being we parse .tool-versions @@ -7784,31 +7780,43 @@ function parseVersionFile(versionFilePath0) { const app = appVersion[1] if (['erlang', 'elixir', 'gleam', 'rebar'].includes(app)) { const [, , version] = appVersion - console.log(`Consuming ${app} at version ${version}`) + core.info(`Consuming ${app} at version ${version}`) appVersions.set(app, version) } } }) if (!appVersions.size) { - console.log('There was apparently nothing to consume') + core.info('There was apparently nothing to consume') } else { - console.log('... done!') + core.info('... done!') } - console.log('##[endgroup]') + core.endGroup() return appVersions } -function jsonParse(maybeJson) { +function jsonParseAsList(maybeJson) { try { - return JSON.parse(maybeJson) + const obj = JSON.parse(maybeJson) + if (!Array.isArray(obj)) { + throw new Error('expected a list!') + } + return obj } catch (exc) { throw new Error( - `Got an exception when trying to parse non-JSON ${maybeJson}: ${exc}`, + `Got an exception when trying to parse non-JSON list ${maybeJson}: ${exc}`, ) } } +function debugLog(groupName, message) { + if (process.env.RUNNER_DEBUG) { + core.startGroup(`Debugging for ${groupName}`) + core.debug(message) + core.endGroup() + } +} + module.exports = { getOTPVersion, getElixirVersion, diff --git a/matchers/elixir-matchers.json b/matchers/elixir-matchers.json new file mode 100644 index 0000000..df01df6 --- /dev/null +++ b/matchers/elixir-matchers.json @@ -0,0 +1,62 @@ +{ + "problemMatcher": [ + { + "owner": "elixir-mixCompileError", + "severity": "error", + "pattern": [ + { + "regexp": "^\\*\\* \\((\\w+)\\) (.*):(\\d+): (.*)$", + "file": 2, + "line": 3, + "message": 0 + } + ] + }, + { + "owner": "elixir-mixCompileWarning", + "severity": "warning", + "pattern": [ + { + "regexp": "^warning: (.*)$", + "message": 1 + }, + { + "regexp": "^ (.*):(\\d+).*$", + "file": 1, + "line": 2 + } + ] + }, + { + "owner": "elixir-mixTestFailure", + "severity": "error", + "pattern": [ + { + "regexp": "^\\s*\\d+\\) (.*)$", + "message": 1 + }, + { + "regexp": "^\\s*(.*):(\\d+)$", + "file": 1, + "line": 2 + } + ] + }, + { + "owner": "elixir-credoOutputDefault", + "severity": "warning", + "pattern": [ + { + "regexp": "^\u2503\\s\\[\\w\\]\\s[\u2191|\u2197|\u2192|\u2198|\u2193]\\s(.*)$", + "message": 1 + }, + { + "regexp": "^\u2503\\s{7}(.*):(\\d+):(\\d+)\\s.*$", + "file": 1, + "line": 2, + "column": 3 + } + ] + } + ] +} diff --git a/package-lock.json b/package-lock.json index 1de8078..7f75f52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "dependencies": { "@actions/core": "1.10.0", "@actions/exec": "1.1.1", - "@actions/http-client": "^2.1.0", + "@actions/http-client": "2.1.0", "semver": "7.3.8" }, "devDependencies": { diff --git a/package.json b/package.json index 52967c3..a7d1a0b 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,12 @@ "private": true, "scripts": { "build": "ncc build src/setup-beam.js --no-cache", - "format": "prettier src/**/*.js --write && prettier __tests__/**/*.js --write", - "jslint": "eslint src/**/*.js && eslint __tests__/**/*.js", + "format": "prettier src/**/*.js --write && prettier test/**/*.js --write", + "jslint": "eslint src/**/*.js && eslint test/**/*.js", "licenses": "yarn licenses generate-disclaimer > 3RD_PARTY_LICENSES", "markdownlint": "markdownlint *.md", "shellcheck": "shellcheck src/install-*.sh .github/workflows/*.sh", - "test": "node __tests__/setup-beam.test.js && node ./__tests__/problem-matchers.test.js", + "test": "node test/setup-beam.test.js && node ./test/problem-matchers.test.js", "yamllint": "yamllint .github/workflows/**.yml && yamllint .*.yml && yamllint *.yml", "build-dist": "npm install && npm run build && npm run format && npm run markdownlint && npm run shellcheck && npm run yamllint && npm run jslint" }, diff --git a/src/setup-beam.js b/src/setup-beam.js index 9e73f1a..75f08e9 100644 --- a/src/setup-beam.js +++ b/src/setup-beam.js @@ -58,13 +58,11 @@ async function main() { async function installOTP(otpSpec, osVersion, hexMirrors) { const otpVersion = await getOTPVersion(otpSpec, osVersion, hexMirrors) - console.log( - `##[group]Installing Erlang/OTP ${otpVersion} - built on ${osVersion}`, - ) + core.startGroup(`Installing Erlang/OTP ${otpVersion} - built on ${osVersion}`) await installer.installOTP(osVersion, otpVersion, hexMirrors) core.setOutput('otp-version', otpVersion) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/otp/bin`) - console.log('##[endgroup]') + core.endGroup() return otpVersion } @@ -78,19 +76,22 @@ async function maybeInstallElixir(elixirSpec, otpSpec, hexMirrors) { otpSpec, hexMirrors, ) - console.log(`##[group]Installing Elixir ${elixirVersion}`) + core.startGroup(`Installing Elixir ${elixirVersion}`) await installer.installElixir(elixirVersion, hexMirrors) core.setOutput('elixir-version', elixirVersion) const disableProblemMatchers = getInput('disable_problem_matchers', false) if (disableProblemMatchers === 'false') { - const matchersPath = path.join(__dirname, '..', '.github') - console.log( - `##[add-matcher]${path.join(matchersPath, 'elixir-matchers.json')}`, + const elixirMatchers = path.join( + __dirname, + '..', + 'matchers', + 'elixir-matchers.json', ) + core.info(`##[add-matcher]${elixirMatchers}`) } core.addPath(`${os.homedir()}/.mix/escripts`) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/elixir/bin`) - console.log('##[endgroup]') + core.endGroup() installed = true } @@ -118,9 +119,9 @@ async function mix(shouldMix, what, hexMirrors) { if (shouldMix === 'true') { const cmd = 'mix' const args = [`local.${what}`, '--force'] - console.log(`##[group]Running ${cmd} ${args}`) + core.startGroup(`Running ${cmd} ${args}`) await mixWithMirrors(cmd, args, hexMirrors) - console.log('##[endgroup]') + core.endGroup() } } @@ -129,11 +130,11 @@ async function maybeInstallGleam(gleamSpec) { if (gleamSpec) { const gleamVersion = await getGleamVersion(gleamSpec) - console.log(`##[group]Installing Gleam ${gleamVersion}`) + core.startGroup(`Installing Gleam ${gleamVersion}`) await installer.installGleam(gleamVersion) core.setOutput('gleam-version', gleamVersion) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/gleam/bin`) - console.log('##[endgroup]') + core.endGroup() installed = true } @@ -151,11 +152,11 @@ async function maybeInstallRebar3(rebar3Spec) { } else { rebar3Version = await getRebar3Version(rebar3Spec) } - console.log(`##[group]Installing rebar3 ${rebar3Version}`) + core.startGroup(`Installing rebar3 ${rebar3Version}`) await installer.installRebar3(rebar3Version) core.setOutput('rebar3-version', rebar3Version) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/rebar3/bin`) - console.log('##[endgroup]') + core.endGroup() installed = true } @@ -248,16 +249,16 @@ async function getRebar3Version(r3Spec) { async function getOTPVersions(osVersion, hexMirrors) { let otpVersionsListings + let originListing if (process.platform === 'linux') { - otpVersionsListings = await getWithMirrors( - `/builds/otp/${osVersion}/builds.txt`, - hexMirrors, - ) + originListing = `/builds/otp/${osVersion}/builds.txt` + otpVersionsListings = await getWithMirrors(originListing, hexMirrors) } else if (process.platform === 'win32') { - const originListing = + originListing = 'https://api.github.com/repos/erlang/otp/releases?per_page=100' otpVersionsListings = await get(originListing, [1, 2, 3]) } + debugLog(`OTP versions listings from ${originListing}`, otpVersionsListings) const otpVersions = new Map() @@ -274,7 +275,7 @@ async function getOTPVersions(osVersion, hexMirrors) { }) } else if (process.platform === 'win32') { otpVersionsListings.forEach((otpVersionsListing) => { - jsonParse(otpVersionsListing) + jsonParseAsList(otpVersionsListing) .map((x) => x.assets) .flat() .filter((x) => x.name.match(/^otp_win64_.*.exe$/)) @@ -321,7 +322,7 @@ async function getGleamVersions() { ) const gleamVersionsListing = [] resultJSONs.forEach((resultJSON) => { - jsonParse(resultJSON) + jsonParseAsList(resultJSON) .map((x) => x.tag_name) .sort() .forEach((v) => gleamVersionsListing.push(v)) @@ -336,7 +337,7 @@ async function getRebar3Versions() { ) const rebar3VersionsListing = [] resultJSONs.forEach((resultJSON) => { - jsonParse(resultJSON) + jsonParseAsList(resultJSON) .map((x) => x.tag_name) .sort() .forEach((v) => rebar3VersionsListing.push(v)) @@ -527,7 +528,7 @@ function parseVersionFile(versionFilePath0) { `The specified version file, ${versionFilePath0}, does not exist`, ) } - console.log(`##[group]Parsing version file at ${versionFilePath0}`) + core.startGroup(`Parsing version file at ${versionFilePath0}`) const appVersions = new Map() const versions = fs.readFileSync(versionFilePath, 'utf8') // For the time being we parse .tool-versions @@ -539,31 +540,43 @@ function parseVersionFile(versionFilePath0) { const app = appVersion[1] if (['erlang', 'elixir', 'gleam', 'rebar'].includes(app)) { const [, , version] = appVersion - console.log(`Consuming ${app} at version ${version}`) + core.info(`Consuming ${app} at version ${version}`) appVersions.set(app, version) } } }) if (!appVersions.size) { - console.log('There was apparently nothing to consume') + core.info('There was apparently nothing to consume') } else { - console.log('... done!') + core.info('... done!') } - console.log('##[endgroup]') + core.endGroup() return appVersions } -function jsonParse(maybeJson) { +function jsonParseAsList(maybeJson) { try { - return JSON.parse(maybeJson) + const obj = JSON.parse(maybeJson) + if (!Array.isArray(obj)) { + throw new Error('expected a list!') + } + return obj } catch (exc) { throw new Error( - `Got an exception when trying to parse non-JSON ${maybeJson}: ${exc}`, + `Got an exception when trying to parse non-JSON list ${maybeJson}: ${exc}`, ) } } +function debugLog(groupName, message) { + if (process.env.RUNNER_DEBUG) { + core.startGroup(`Debugging for ${groupName}`) + core.debug(message) + core.endGroup() + } +} + module.exports = { getOTPVersion, getElixirVersion, diff --git a/__tests__/problem-matchers.test.js b/test/problem-matchers.test.js similarity index 95% rename from __tests__/problem-matchers.test.js rename to test/problem-matchers.test.js index e8d0d78..5e21011 100644 --- a/__tests__/problem-matchers.test.js +++ b/test/problem-matchers.test.js @@ -1,5 +1,6 @@ const assert = require('assert') -const { problemMatcher } = require('../.github/elixir-matchers.json') +const core = require('@actions/core') +const { problemMatcher } = require('../matchers/elixir-matchers.json') async function all() { await testElixirMixCompileError() @@ -76,6 +77,6 @@ async function testElixirCredoOutputDefault() { all() .then(() => process.exit(0)) .catch((err) => { - console.error(err) + core.error(err) process.exit(1) }) diff --git a/test-projects/elixir_mix/.formatter.exs b/test/projects/elixir_mix/.formatter.exs similarity index 100% rename from test-projects/elixir_mix/.formatter.exs rename to test/projects/elixir_mix/.formatter.exs diff --git a/test-projects/elixir_mix/.gitignore b/test/projects/elixir_mix/.gitignore similarity index 100% rename from test-projects/elixir_mix/.gitignore rename to test/projects/elixir_mix/.gitignore diff --git a/test-projects/elixir_mix/README.md b/test/projects/elixir_mix/README.md similarity index 100% rename from test-projects/elixir_mix/README.md rename to test/projects/elixir_mix/README.md diff --git a/test-projects/elixir_mix/lib/test.ex b/test/projects/elixir_mix/lib/test.ex similarity index 100% rename from test-projects/elixir_mix/lib/test.ex rename to test/projects/elixir_mix/lib/test.ex diff --git a/test-projects/elixir_mix/mix.exs b/test/projects/elixir_mix/mix.exs similarity index 100% rename from test-projects/elixir_mix/mix.exs rename to test/projects/elixir_mix/mix.exs diff --git a/test-projects/elixir_mix/mix.lock b/test/projects/elixir_mix/mix.lock similarity index 100% rename from test-projects/elixir_mix/mix.lock rename to test/projects/elixir_mix/mix.lock diff --git a/test-projects/elixir_mix/test/test_helper.exs b/test/projects/elixir_mix/test/test_helper.exs similarity index 100% rename from test-projects/elixir_mix/test/test_helper.exs rename to test/projects/elixir_mix/test/test_helper.exs diff --git a/test-projects/elixir_mix/test/test_test.exs b/test/projects/elixir_mix/test/test_test.exs similarity index 100% rename from test-projects/elixir_mix/test/test_test.exs rename to test/projects/elixir_mix/test/test_test.exs diff --git a/test-projects/erlang_rebar3/.gitignore b/test/projects/erlang_rebar3/.gitignore similarity index 100% rename from test-projects/erlang_rebar3/.gitignore rename to test/projects/erlang_rebar3/.gitignore diff --git a/test-projects/erlang_rebar3/LICENSE b/test/projects/erlang_rebar3/LICENSE similarity index 100% rename from test-projects/erlang_rebar3/LICENSE rename to test/projects/erlang_rebar3/LICENSE diff --git a/test-projects/erlang_rebar3/README.md b/test/projects/erlang_rebar3/README.md similarity index 100% rename from test-projects/erlang_rebar3/README.md rename to test/projects/erlang_rebar3/README.md diff --git a/test-projects/erlang_rebar3/rebar.config b/test/projects/erlang_rebar3/rebar.config similarity index 100% rename from test-projects/erlang_rebar3/rebar.config rename to test/projects/erlang_rebar3/rebar.config diff --git a/test-projects/erlang_rebar3/rebar.lock b/test/projects/erlang_rebar3/rebar.lock similarity index 100% rename from test-projects/erlang_rebar3/rebar.lock rename to test/projects/erlang_rebar3/rebar.lock diff --git a/test-projects/erlang_rebar3/src/mylib.app.src b/test/projects/erlang_rebar3/src/mylib.app.src similarity index 100% rename from test-projects/erlang_rebar3/src/mylib.app.src rename to test/projects/erlang_rebar3/src/mylib.app.src diff --git a/test-projects/erlang_rebar3/src/mylib.erl b/test/projects/erlang_rebar3/src/mylib.erl similarity index 100% rename from test-projects/erlang_rebar3/src/mylib.erl rename to test/projects/erlang_rebar3/src/mylib.erl diff --git a/test-projects/erlang_rebar3/test/mylib_SUITE.erl b/test/projects/erlang_rebar3/test/mylib_SUITE.erl similarity index 100% rename from test-projects/erlang_rebar3/test/mylib_SUITE.erl rename to test/projects/erlang_rebar3/test/mylib_SUITE.erl diff --git a/test-projects/gleam_gleam/.github/workflows/test.yml b/test/projects/gleam_gleam/.github/workflows/test.yml similarity index 100% rename from test-projects/gleam_gleam/.github/workflows/test.yml rename to test/projects/gleam_gleam/.github/workflows/test.yml diff --git a/test-projects/gleam_gleam/.gitignore b/test/projects/gleam_gleam/.gitignore similarity index 100% rename from test-projects/gleam_gleam/.gitignore rename to test/projects/gleam_gleam/.gitignore diff --git a/test-projects/gleam_gleam/README.md b/test/projects/gleam_gleam/README.md similarity index 100% rename from test-projects/gleam_gleam/README.md rename to test/projects/gleam_gleam/README.md diff --git a/test-projects/gleam_gleam/gleam.toml b/test/projects/gleam_gleam/gleam.toml similarity index 100% rename from test-projects/gleam_gleam/gleam.toml rename to test/projects/gleam_gleam/gleam.toml diff --git a/test-projects/gleam_gleam/manifest.toml b/test/projects/gleam_gleam/manifest.toml similarity index 100% rename from test-projects/gleam_gleam/manifest.toml rename to test/projects/gleam_gleam/manifest.toml diff --git a/test-projects/gleam_gleam/src/gleam_gleam.gleam b/test/projects/gleam_gleam/src/gleam_gleam.gleam similarity index 100% rename from test-projects/gleam_gleam/src/gleam_gleam.gleam rename to test/projects/gleam_gleam/src/gleam_gleam.gleam diff --git a/test-projects/gleam_gleam/test/gleam_gleam_test.gleam b/test/projects/gleam_gleam/test/gleam_gleam_test.gleam similarity index 100% rename from test-projects/gleam_gleam/test/gleam_gleam_test.gleam rename to test/projects/gleam_gleam/test/gleam_gleam_test.gleam diff --git a/test-projects/rust_rebar3_cmd/.gitignore b/test/projects/rust_rebar3_cmd/.gitignore similarity index 100% rename from test-projects/rust_rebar3_cmd/.gitignore rename to test/projects/rust_rebar3_cmd/.gitignore diff --git a/test-projects/rust_rebar3_cmd/Cargo.lock b/test/projects/rust_rebar3_cmd/Cargo.lock similarity index 100% rename from test-projects/rust_rebar3_cmd/Cargo.lock rename to test/projects/rust_rebar3_cmd/Cargo.lock diff --git a/test-projects/rust_rebar3_cmd/Cargo.toml b/test/projects/rust_rebar3_cmd/Cargo.toml similarity index 100% rename from test-projects/rust_rebar3_cmd/Cargo.toml rename to test/projects/rust_rebar3_cmd/Cargo.toml diff --git a/test-projects/rust_rebar3_cmd/src/main.rs b/test/projects/rust_rebar3_cmd/src/main.rs similarity index 100% rename from test-projects/rust_rebar3_cmd/src/main.rs rename to test/projects/rust_rebar3_cmd/src/main.rs diff --git a/__tests__/setup-beam.test.js b/test/setup-beam.test.js similarity index 91% rename from __tests__/setup-beam.test.js rename to test/setup-beam.test.js index 2496823..d05c8b7 100644 --- a/__tests__/setup-beam.test.js +++ b/test/setup-beam.test.js @@ -4,9 +4,11 @@ simulateInput('rebar3-version', '3.20') simulateInput('install-rebar', 'true') simulateInput('install-hex', 'true') simulateInput('github-token', process.env.GITHUB_TOKEN) +simulateInput('hexpm-mirrors', ['https://builds.hex.pm']) const assert = require('assert') const fs = require('fs') +const core = require('@actions/core') const setupBeam = require('../src/setup-beam') const installer = require('../src/installer') @@ -174,6 +176,7 @@ async function testElixirVersions() { let expected let spec let otpVersion + let before const hexMirrors = ['https://repo.hex.pm'] spec = '1.1.x' @@ -194,37 +197,37 @@ async function testElixirVersions() { got = await setupBeam.getElixirVersion(spec, otpVersion, hexMirrors) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'strict') + before = simulateInput('version-type', 'strict') spec = '1.14.0' otpVersion = 'master' expected = 'v1.14.0' got = await setupBeam.getElixirVersion(spec, otpVersion, hexMirrors) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'loose') + simulateInput('version-type', before) - simulateInput('version-type', 'strict') + before = simulateInput('version-type', 'strict') spec = 'v1.11.0-rc.0' otpVersion = 'OTP-23' expected = 'v1.11.0-rc.0-otp-23' got = await setupBeam.getElixirVersion(spec, otpVersion, hexMirrors) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'loose') + simulateInput('version-type', before) - simulateInput('version-type', 'strict') + before = simulateInput('version-type', 'strict') spec = 'v1.11.0' otpVersion = '22.3.4.2' expected = 'v1.11.0-otp-22' got = await setupBeam.getElixirVersion(spec, otpVersion, hexMirrors) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'loose') + simulateInput('version-type', before) - simulateInput('version-type', 'strict') + before = simulateInput('version-type', 'strict') spec = 'main' otpVersion = '23.1' expected = 'main-otp-23' got = await setupBeam.getElixirVersion(spec, otpVersion, hexMirrors) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'loose') + simulateInput('version-type', before) } async function testGleamVersions() { @@ -245,13 +248,13 @@ async function testGleamVersions() { got = await setupBeam.getGleamVersion(spec, otpVersion) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'strict') + const before = simulateInput('version-type', 'strict') spec = 'v0.14.0-rc2' otpVersion = 'OTP-22' expected = 'v0.14.0-rc2' got = await setupBeam.getGleamVersion(spec, otpVersion) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'loose') + simulateInput('version-type', before) } async function testRebar3Versions() { @@ -279,6 +282,7 @@ async function testGetVersionFromSpec() { let got let expected let spec + let before const versions = [ '3.2.30.5', '3.2.3.5', @@ -320,19 +324,19 @@ async function testGetVersionFromSpec() { got = setupBeam.getVersionFromSpec(spec, versions) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'strict') + before = simulateInput('version-type', 'strict') spec = '1' expected = '1' got = setupBeam.getVersionFromSpec(spec, versions) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'loose') + simulateInput('version-type', before) - simulateInput('version-type', 'strict') + before = simulateInput('version-type', 'strict') spec = '1.0' expected = '1.0' got = setupBeam.getVersionFromSpec(spec, versions) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'loose') + simulateInput('version-type', before) spec = '2' expected = '2.10' @@ -359,12 +363,12 @@ async function testGetVersionFromSpec() { got = setupBeam.getVersionFromSpec(spec, versions) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'strict') + before = simulateInput('version-type', 'strict') spec = '24.0-rc3' expected = '24.0-rc3' got = setupBeam.getVersionFromSpec(spec, versions) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'loose') + simulateInput('version-type', before) spec = '24.0-rc2' expected = '24.0-rc2' @@ -391,24 +395,24 @@ async function testGetVersionFromSpec() { got = setupBeam.getVersionFromSpec(spec, versions) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'strict') + before = simulateInput('version-type', 'strict') spec = 'master' expected = 'master' got = setupBeam.getVersionFromSpec(spec, versions) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'loose') + simulateInput('version-type', before) spec = 'master' expected = 'master' got = setupBeam.getVersionFromSpec(spec, versions) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'strict') + before = simulateInput('version-type', 'strict') spec = '22.3.4.2' expected = '22.3.4.2' got = setupBeam.getVersionFromSpec(spec, versions) assert.deepStrictEqual(got, expected) - simulateInput('version-type', 'loose') + simulateInput('version-type', before) } async function testParseVersionFile() { @@ -427,7 +431,7 @@ elixir ${elixir} # comment, with space not-gleam 0.23 # not picked up gleam ${gleam} rebar ${rebar3}` - const filename = '__tests__/.tool-versions' + const filename = 'test/.tool-versions' fs.writeFileSync(filename, toolVersions) process.env.GITHUB_WORKSPACE = '' const appVersions = setupBeam.parseVersionFile(filename) @@ -454,13 +458,13 @@ rebar ${rebar3}` } function unsimulateInput(key) { - const before = process.env[input(key)] - simulateInput(key, '') - return before + return simulateInput(key, '') } function simulateInput(key, value) { + const before = process.env[input(key)] process.env[input(key)] = value + return before } function input(key) { @@ -470,6 +474,6 @@ function input(key) { all() .then(() => process.exit(0)) .catch((err) => { - console.error(err) + core.error(err) process.exit(1) })