Ease debugging, fix some CI issues, tweak folder structure (#200)

* Enable debug for OTP versions' listings

* Make it easier to detect

* Prevent error annotation on expected error

The fact that one mirror fails in the above test and others follow
working is test enough for me

A single failing mirror should fail, but it's confusing to have
an error annotation for a success (via continue-on-error) while
not being able to suppress it via GitHub Actions

* Trying to figure out why we have a rebar_core exception

Might simply be that the bug is already fixed and we need to bump rebar3

* Try to debug into non-JSON input

* Prevent error in rebar_core

We're getting Access Denied for
Fetching registry from "https://repo.hex.pm:443/registry.ets.gz?"

* Try to figure out what's breaking tests

* Make jsonParse(...).map failure more understandable

* Ease test maintenance

* Tweak folder structure while moving console._ to core._
This commit is contained in:
Paulo F. Oliveira
2023-05-08 09:31:17 +01:00
committed by GitHub
parent cf692c3264
commit b9783cdeea
42 changed files with 193 additions and 127 deletions
-1
View File
@@ -9,7 +9,6 @@ parserOptions:
rules: rules:
indent: ["warn", 2] indent: ["warn", 2]
max-len: ["warn", 100] max-len: ["warn", 100]
no-console: 0
no-undef: "error" no-undef: "error"
no-unused-vars: ["error", {"varsIgnorePattern": "^_"}] no-unused-vars: ["error", {"varsIgnorePattern": "^_"}]
no-use-before-define: 0 no-use-before-define: 0
+1 -1
View File
@@ -46,7 +46,7 @@ jobs:
id: setup-beam id: setup-beam
uses: ./ uses: ./
with: with:
version-file: __tests__/.tool-versions version-file: test/.tool-versions
version-type: strict version-type: strict
unit_tests_windows: unit_tests_windows:
-21
View File
@@ -35,24 +35,3 @@ jobs:
https://mirror.invalid https://mirror.invalid
https://cdn.jsdelivr.net/hex https://cdn.jsdelivr.net/hex
https://builds.hex.pm 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
+5 -5
View File
@@ -53,7 +53,7 @@ jobs:
os: 'ubuntu-latest' os: 'ubuntu-latest'
- elixir-version: 'v1.4' - elixir-version: 'v1.4'
otp-version: '20' otp-version: '20'
rebar3-version: '3.6.0' rebar3-version: '3.15.0'
os: 'ubuntu-20.04' os: 'ubuntu-20.04'
- elixir-version: 'v1.4' - elixir-version: 'v1.4'
otp-version: '20' otp-version: '20'
@@ -165,23 +165,23 @@ jobs:
if: ${{matrix.combo.elixir-version}} if: ${{matrix.combo.elixir-version}}
- name: Run Elixir/Mix project tests - name: Run Elixir/Mix project tests
run: | run: |
cd test-projects/elixir_mix cd test/projects/elixir_mix
mix deps.get mix deps.get
mix test mix test
if: ${{matrix.combo.elixir-version}} if: ${{matrix.combo.elixir-version}}
- name: Run Erlang/rebar3 project tests - name: Run Erlang/rebar3 project tests
run: | run: |
cd test-projects/erlang_rebar3 cd test/projects/erlang_rebar3
rebar3 ct rebar3 ct
if: ${{matrix.combo.rebar3-version}} if: ${{matrix.combo.rebar3-version}}
- name: Format Gleam project (without installing Erlang/OTP) - name: Format Gleam project (without installing Erlang/OTP)
run: | run: |
cd test-projects/gleam_gleam cd test/projects/gleam_gleam
gleam format gleam format
if: ${{ matrix.combo.gleam-version && !matrix.combo.otp-version }} if: ${{ matrix.combo.gleam-version && !matrix.combo.otp-version }}
- name: Run Gleam project tests (without `rebar3`) - name: Run Gleam project tests (without `rebar3`)
run: | run: |
cd test-projects/gleam_gleam cd test/projects/gleam_gleam
gleam test gleam test
if: ${{ matrix.combo.gleam-version && matrix.combo.otp-version && !matrix.combo.rebar3-version }} if: ${{ matrix.combo.gleam-version && matrix.combo.otp-version && !matrix.combo.rebar3-version }}
- name: Run escript - name: Run escript
+3 -3
View File
@@ -79,7 +79,7 @@ jobs:
if: ${{matrix.combo.rebar3-version}} if: ${{matrix.combo.rebar3-version}}
- name: rebar3 from Rust - name: rebar3 from Rust
run: | run: |
cd test-projects/rust_rebar3_cmd cd test/projects/rust_rebar3_cmd
cargo test -- --nocapture cargo test -- --nocapture
if: ${{matrix.combo.rebar3-version}} if: ${{matrix.combo.rebar3-version}}
- name: mix version and help (CLI) - name: mix version and help (CLI)
@@ -90,13 +90,13 @@ jobs:
if: ${{matrix.combo.elixir-version}} if: ${{matrix.combo.elixir-version}}
- name: Run Elixir/Mix project tests - name: Run Elixir/Mix project tests
run: | run: |
cd test-projects/elixir_mix cd test/projects/elixir_mix
mix deps.get mix deps.get
mix test mix test
if: ${{matrix.combo.elixir-version}} if: ${{matrix.combo.elixir-version}}
- name: Run Erlang/rebar3 project tests - name: Run Erlang/rebar3 project tests
run: | run: |
cd test-projects/erlang_rebar3 cd test/projects/erlang_rebar3
rebar3 ct rebar3 ct
if: ${{matrix.combo.rebar3-version}} if: ${{matrix.combo.rebar3-version}}
- name: Run escript - name: Run escript
+1 -1
View File
@@ -1,3 +1,3 @@
node_modules/** node_modules/**
dist/.github/workflows dist/.github/workflows
__tests__/.tool-versions test/.tool-versions
+1 -1
View File
@@ -1,6 +1,6 @@
# Elixir Problem Matchers # 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), 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): available under the [MIT license](https://github.com/fr1zle/vscode-elixir/blob/45eddb589acd7ac98e0c7305d1c2b24668ca709a/LICENSE.md):
+40 -32
View File
@@ -7303,13 +7303,11 @@ async function main() {
async function installOTP(otpSpec, osVersion, hexMirrors) { async function installOTP(otpSpec, osVersion, hexMirrors) {
const otpVersion = await getOTPVersion(otpSpec, osVersion, hexMirrors) const otpVersion = await getOTPVersion(otpSpec, osVersion, hexMirrors)
console.log( core.startGroup(`Installing Erlang/OTP ${otpVersion} - built on ${osVersion}`)
`##[group]Installing Erlang/OTP ${otpVersion} - built on ${osVersion}`,
)
await installer.installOTP(osVersion, otpVersion, hexMirrors) await installer.installOTP(osVersion, otpVersion, hexMirrors)
core.setOutput('otp-version', otpVersion) core.setOutput('otp-version', otpVersion)
core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/otp/bin`) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/otp/bin`)
console.log('##[endgroup]') core.endGroup()
return otpVersion return otpVersion
} }
@@ -7323,19 +7321,17 @@ async function maybeInstallElixir(elixirSpec, otpSpec, hexMirrors) {
otpSpec, otpSpec,
hexMirrors, hexMirrors,
) )
console.log(`##[group]Installing Elixir ${elixirVersion}`) core.startGroup(`Installing Elixir ${elixirVersion}`)
await installer.installElixir(elixirVersion, hexMirrors) await installer.installElixir(elixirVersion, hexMirrors)
core.setOutput('elixir-version', elixirVersion) core.setOutput('elixir-version', elixirVersion)
const disableProblemMatchers = getInput('disable_problem_matchers', false) const disableProblemMatchers = getInput('disable_problem_matchers', false)
if (disableProblemMatchers === 'false') { if (disableProblemMatchers === 'false') {
const matchersPath = __nccwpck_require__.ab + ".github" const elixirMatchers = __nccwpck_require__.ab + "elixir-matchers.json"
console.log( core.info(`##[add-matcher]${elixirMatchers}`)
`##[add-matcher]${path.join(matchersPath, 'elixir-matchers.json')}`,
)
} }
core.addPath(`${os.homedir()}/.mix/escripts`) core.addPath(`${os.homedir()}/.mix/escripts`)
core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/elixir/bin`) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/elixir/bin`)
console.log('##[endgroup]') core.endGroup()
installed = true installed = true
} }
@@ -7363,9 +7359,9 @@ async function mix(shouldMix, what, hexMirrors) {
if (shouldMix === 'true') { if (shouldMix === 'true') {
const cmd = 'mix' const cmd = 'mix'
const args = [`local.${what}`, '--force'] const args = [`local.${what}`, '--force']
console.log(`##[group]Running ${cmd} ${args}`) core.startGroup(`Running ${cmd} ${args}`)
await mixWithMirrors(cmd, args, hexMirrors) await mixWithMirrors(cmd, args, hexMirrors)
console.log('##[endgroup]') core.endGroup()
} }
} }
@@ -7374,11 +7370,11 @@ async function maybeInstallGleam(gleamSpec) {
if (gleamSpec) { if (gleamSpec) {
const gleamVersion = await getGleamVersion(gleamSpec) const gleamVersion = await getGleamVersion(gleamSpec)
console.log(`##[group]Installing Gleam ${gleamVersion}`) core.startGroup(`Installing Gleam ${gleamVersion}`)
await installer.installGleam(gleamVersion) await installer.installGleam(gleamVersion)
core.setOutput('gleam-version', gleamVersion) core.setOutput('gleam-version', gleamVersion)
core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/gleam/bin`) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/gleam/bin`)
console.log('##[endgroup]') core.endGroup()
installed = true installed = true
} }
@@ -7396,11 +7392,11 @@ async function maybeInstallRebar3(rebar3Spec) {
} else { } else {
rebar3Version = await getRebar3Version(rebar3Spec) rebar3Version = await getRebar3Version(rebar3Spec)
} }
console.log(`##[group]Installing rebar3 ${rebar3Version}`) core.startGroup(`Installing rebar3 ${rebar3Version}`)
await installer.installRebar3(rebar3Version) await installer.installRebar3(rebar3Version)
core.setOutput('rebar3-version', rebar3Version) core.setOutput('rebar3-version', rebar3Version)
core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/rebar3/bin`) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/rebar3/bin`)
console.log('##[endgroup]') core.endGroup()
installed = true installed = true
} }
@@ -7493,16 +7489,16 @@ async function getRebar3Version(r3Spec) {
async function getOTPVersions(osVersion, hexMirrors) { async function getOTPVersions(osVersion, hexMirrors) {
let otpVersionsListings let otpVersionsListings
let originListing
if (process.platform === 'linux') { if (process.platform === 'linux') {
otpVersionsListings = await getWithMirrors( originListing = `/builds/otp/${osVersion}/builds.txt`
`/builds/otp/${osVersion}/builds.txt`, otpVersionsListings = await getWithMirrors(originListing, hexMirrors)
hexMirrors,
)
} else if (process.platform === 'win32') { } else if (process.platform === 'win32') {
const originListing = originListing =
'https://api.github.com/repos/erlang/otp/releases?per_page=100' 'https://api.github.com/repos/erlang/otp/releases?per_page=100'
otpVersionsListings = await get(originListing, [1, 2, 3]) otpVersionsListings = await get(originListing, [1, 2, 3])
} }
debugLog(`OTP versions listings from ${originListing}`, otpVersionsListings)
const otpVersions = new Map() const otpVersions = new Map()
@@ -7519,7 +7515,7 @@ async function getOTPVersions(osVersion, hexMirrors) {
}) })
} else if (process.platform === 'win32') { } else if (process.platform === 'win32') {
otpVersionsListings.forEach((otpVersionsListing) => { otpVersionsListings.forEach((otpVersionsListing) => {
jsonParse(otpVersionsListing) jsonParseAsList(otpVersionsListing)
.map((x) => x.assets) .map((x) => x.assets)
.flat() .flat()
.filter((x) => x.name.match(/^otp_win64_.*.exe$/)) .filter((x) => x.name.match(/^otp_win64_.*.exe$/))
@@ -7566,7 +7562,7 @@ async function getGleamVersions() {
) )
const gleamVersionsListing = [] const gleamVersionsListing = []
resultJSONs.forEach((resultJSON) => { resultJSONs.forEach((resultJSON) => {
jsonParse(resultJSON) jsonParseAsList(resultJSON)
.map((x) => x.tag_name) .map((x) => x.tag_name)
.sort() .sort()
.forEach((v) => gleamVersionsListing.push(v)) .forEach((v) => gleamVersionsListing.push(v))
@@ -7581,7 +7577,7 @@ async function getRebar3Versions() {
) )
const rebar3VersionsListing = [] const rebar3VersionsListing = []
resultJSONs.forEach((resultJSON) => { resultJSONs.forEach((resultJSON) => {
jsonParse(resultJSON) jsonParseAsList(resultJSON)
.map((x) => x.tag_name) .map((x) => x.tag_name)
.sort() .sort()
.forEach((v) => rebar3VersionsListing.push(v)) .forEach((v) => rebar3VersionsListing.push(v))
@@ -7772,7 +7768,7 @@ function parseVersionFile(versionFilePath0) {
`The specified version file, ${versionFilePath0}, does not exist`, `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 appVersions = new Map()
const versions = fs.readFileSync(versionFilePath, 'utf8') const versions = fs.readFileSync(versionFilePath, 'utf8')
// For the time being we parse .tool-versions // For the time being we parse .tool-versions
@@ -7784,31 +7780,43 @@ function parseVersionFile(versionFilePath0) {
const app = appVersion[1] const app = appVersion[1]
if (['erlang', 'elixir', 'gleam', 'rebar'].includes(app)) { if (['erlang', 'elixir', 'gleam', 'rebar'].includes(app)) {
const [, , version] = appVersion const [, , version] = appVersion
console.log(`Consuming ${app} at version ${version}`) core.info(`Consuming ${app} at version ${version}`)
appVersions.set(app, version) appVersions.set(app, version)
} }
} }
}) })
if (!appVersions.size) { if (!appVersions.size) {
console.log('There was apparently nothing to consume') core.info('There was apparently nothing to consume')
} else { } else {
console.log('... done!') core.info('... done!')
} }
console.log('##[endgroup]') core.endGroup()
return appVersions return appVersions
} }
function jsonParse(maybeJson) { function jsonParseAsList(maybeJson) {
try { try {
return JSON.parse(maybeJson) const obj = JSON.parse(maybeJson)
if (!Array.isArray(obj)) {
throw new Error('expected a list!')
}
return obj
} catch (exc) { } catch (exc) {
throw new Error( 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 = { module.exports = {
getOTPVersion, getOTPVersion,
getElixirVersion, getElixirVersion,
+62
View File
@@ -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
}
]
}
]
}
+1 -1
View File
@@ -9,7 +9,7 @@
"dependencies": { "dependencies": {
"@actions/core": "1.10.0", "@actions/core": "1.10.0",
"@actions/exec": "1.1.1", "@actions/exec": "1.1.1",
"@actions/http-client": "^2.1.0", "@actions/http-client": "2.1.0",
"semver": "7.3.8" "semver": "7.3.8"
}, },
"devDependencies": { "devDependencies": {
+3 -3
View File
@@ -4,12 +4,12 @@
"private": true, "private": true,
"scripts": { "scripts": {
"build": "ncc build src/setup-beam.js --no-cache", "build": "ncc build src/setup-beam.js --no-cache",
"format": "prettier src/**/*.js --write && prettier __tests__/**/*.js --write", "format": "prettier src/**/*.js --write && prettier test/**/*.js --write",
"jslint": "eslint src/**/*.js && eslint __tests__/**/*.js", "jslint": "eslint src/**/*.js && eslint test/**/*.js",
"licenses": "yarn licenses generate-disclaimer > 3RD_PARTY_LICENSES", "licenses": "yarn licenses generate-disclaimer > 3RD_PARTY_LICENSES",
"markdownlint": "markdownlint *.md", "markdownlint": "markdownlint *.md",
"shellcheck": "shellcheck src/install-*.sh .github/workflows/*.sh", "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", "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" "build-dist": "npm install && npm run build && npm run format && npm run markdownlint && npm run shellcheck && npm run yamllint && npm run jslint"
}, },
+44 -31
View File
@@ -58,13 +58,11 @@ async function main() {
async function installOTP(otpSpec, osVersion, hexMirrors) { async function installOTP(otpSpec, osVersion, hexMirrors) {
const otpVersion = await getOTPVersion(otpSpec, osVersion, hexMirrors) const otpVersion = await getOTPVersion(otpSpec, osVersion, hexMirrors)
console.log( core.startGroup(`Installing Erlang/OTP ${otpVersion} - built on ${osVersion}`)
`##[group]Installing Erlang/OTP ${otpVersion} - built on ${osVersion}`,
)
await installer.installOTP(osVersion, otpVersion, hexMirrors) await installer.installOTP(osVersion, otpVersion, hexMirrors)
core.setOutput('otp-version', otpVersion) core.setOutput('otp-version', otpVersion)
core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/otp/bin`) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/otp/bin`)
console.log('##[endgroup]') core.endGroup()
return otpVersion return otpVersion
} }
@@ -78,19 +76,22 @@ async function maybeInstallElixir(elixirSpec, otpSpec, hexMirrors) {
otpSpec, otpSpec,
hexMirrors, hexMirrors,
) )
console.log(`##[group]Installing Elixir ${elixirVersion}`) core.startGroup(`Installing Elixir ${elixirVersion}`)
await installer.installElixir(elixirVersion, hexMirrors) await installer.installElixir(elixirVersion, hexMirrors)
core.setOutput('elixir-version', elixirVersion) core.setOutput('elixir-version', elixirVersion)
const disableProblemMatchers = getInput('disable_problem_matchers', false) const disableProblemMatchers = getInput('disable_problem_matchers', false)
if (disableProblemMatchers === 'false') { if (disableProblemMatchers === 'false') {
const matchersPath = path.join(__dirname, '..', '.github') const elixirMatchers = path.join(
console.log( __dirname,
`##[add-matcher]${path.join(matchersPath, 'elixir-matchers.json')}`, '..',
'matchers',
'elixir-matchers.json',
) )
core.info(`##[add-matcher]${elixirMatchers}`)
} }
core.addPath(`${os.homedir()}/.mix/escripts`) core.addPath(`${os.homedir()}/.mix/escripts`)
core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/elixir/bin`) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/elixir/bin`)
console.log('##[endgroup]') core.endGroup()
installed = true installed = true
} }
@@ -118,9 +119,9 @@ async function mix(shouldMix, what, hexMirrors) {
if (shouldMix === 'true') { if (shouldMix === 'true') {
const cmd = 'mix' const cmd = 'mix'
const args = [`local.${what}`, '--force'] const args = [`local.${what}`, '--force']
console.log(`##[group]Running ${cmd} ${args}`) core.startGroup(`Running ${cmd} ${args}`)
await mixWithMirrors(cmd, args, hexMirrors) await mixWithMirrors(cmd, args, hexMirrors)
console.log('##[endgroup]') core.endGroup()
} }
} }
@@ -129,11 +130,11 @@ async function maybeInstallGleam(gleamSpec) {
if (gleamSpec) { if (gleamSpec) {
const gleamVersion = await getGleamVersion(gleamSpec) const gleamVersion = await getGleamVersion(gleamSpec)
console.log(`##[group]Installing Gleam ${gleamVersion}`) core.startGroup(`Installing Gleam ${gleamVersion}`)
await installer.installGleam(gleamVersion) await installer.installGleam(gleamVersion)
core.setOutput('gleam-version', gleamVersion) core.setOutput('gleam-version', gleamVersion)
core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/gleam/bin`) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/gleam/bin`)
console.log('##[endgroup]') core.endGroup()
installed = true installed = true
} }
@@ -151,11 +152,11 @@ async function maybeInstallRebar3(rebar3Spec) {
} else { } else {
rebar3Version = await getRebar3Version(rebar3Spec) rebar3Version = await getRebar3Version(rebar3Spec)
} }
console.log(`##[group]Installing rebar3 ${rebar3Version}`) core.startGroup(`Installing rebar3 ${rebar3Version}`)
await installer.installRebar3(rebar3Version) await installer.installRebar3(rebar3Version)
core.setOutput('rebar3-version', rebar3Version) core.setOutput('rebar3-version', rebar3Version)
core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/rebar3/bin`) core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/rebar3/bin`)
console.log('##[endgroup]') core.endGroup()
installed = true installed = true
} }
@@ -248,16 +249,16 @@ async function getRebar3Version(r3Spec) {
async function getOTPVersions(osVersion, hexMirrors) { async function getOTPVersions(osVersion, hexMirrors) {
let otpVersionsListings let otpVersionsListings
let originListing
if (process.platform === 'linux') { if (process.platform === 'linux') {
otpVersionsListings = await getWithMirrors( originListing = `/builds/otp/${osVersion}/builds.txt`
`/builds/otp/${osVersion}/builds.txt`, otpVersionsListings = await getWithMirrors(originListing, hexMirrors)
hexMirrors,
)
} else if (process.platform === 'win32') { } else if (process.platform === 'win32') {
const originListing = originListing =
'https://api.github.com/repos/erlang/otp/releases?per_page=100' 'https://api.github.com/repos/erlang/otp/releases?per_page=100'
otpVersionsListings = await get(originListing, [1, 2, 3]) otpVersionsListings = await get(originListing, [1, 2, 3])
} }
debugLog(`OTP versions listings from ${originListing}`, otpVersionsListings)
const otpVersions = new Map() const otpVersions = new Map()
@@ -274,7 +275,7 @@ async function getOTPVersions(osVersion, hexMirrors) {
}) })
} else if (process.platform === 'win32') { } else if (process.platform === 'win32') {
otpVersionsListings.forEach((otpVersionsListing) => { otpVersionsListings.forEach((otpVersionsListing) => {
jsonParse(otpVersionsListing) jsonParseAsList(otpVersionsListing)
.map((x) => x.assets) .map((x) => x.assets)
.flat() .flat()
.filter((x) => x.name.match(/^otp_win64_.*.exe$/)) .filter((x) => x.name.match(/^otp_win64_.*.exe$/))
@@ -321,7 +322,7 @@ async function getGleamVersions() {
) )
const gleamVersionsListing = [] const gleamVersionsListing = []
resultJSONs.forEach((resultJSON) => { resultJSONs.forEach((resultJSON) => {
jsonParse(resultJSON) jsonParseAsList(resultJSON)
.map((x) => x.tag_name) .map((x) => x.tag_name)
.sort() .sort()
.forEach((v) => gleamVersionsListing.push(v)) .forEach((v) => gleamVersionsListing.push(v))
@@ -336,7 +337,7 @@ async function getRebar3Versions() {
) )
const rebar3VersionsListing = [] const rebar3VersionsListing = []
resultJSONs.forEach((resultJSON) => { resultJSONs.forEach((resultJSON) => {
jsonParse(resultJSON) jsonParseAsList(resultJSON)
.map((x) => x.tag_name) .map((x) => x.tag_name)
.sort() .sort()
.forEach((v) => rebar3VersionsListing.push(v)) .forEach((v) => rebar3VersionsListing.push(v))
@@ -527,7 +528,7 @@ function parseVersionFile(versionFilePath0) {
`The specified version file, ${versionFilePath0}, does not exist`, `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 appVersions = new Map()
const versions = fs.readFileSync(versionFilePath, 'utf8') const versions = fs.readFileSync(versionFilePath, 'utf8')
// For the time being we parse .tool-versions // For the time being we parse .tool-versions
@@ -539,31 +540,43 @@ function parseVersionFile(versionFilePath0) {
const app = appVersion[1] const app = appVersion[1]
if (['erlang', 'elixir', 'gleam', 'rebar'].includes(app)) { if (['erlang', 'elixir', 'gleam', 'rebar'].includes(app)) {
const [, , version] = appVersion const [, , version] = appVersion
console.log(`Consuming ${app} at version ${version}`) core.info(`Consuming ${app} at version ${version}`)
appVersions.set(app, version) appVersions.set(app, version)
} }
} }
}) })
if (!appVersions.size) { if (!appVersions.size) {
console.log('There was apparently nothing to consume') core.info('There was apparently nothing to consume')
} else { } else {
console.log('... done!') core.info('... done!')
} }
console.log('##[endgroup]') core.endGroup()
return appVersions return appVersions
} }
function jsonParse(maybeJson) { function jsonParseAsList(maybeJson) {
try { try {
return JSON.parse(maybeJson) const obj = JSON.parse(maybeJson)
if (!Array.isArray(obj)) {
throw new Error('expected a list!')
}
return obj
} catch (exc) { } catch (exc) {
throw new Error( 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 = { module.exports = {
getOTPVersion, getOTPVersion,
getElixirVersion, getElixirVersion,
@@ -1,5 +1,6 @@
const assert = require('assert') 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() { async function all() {
await testElixirMixCompileError() await testElixirMixCompileError()
@@ -76,6 +77,6 @@ async function testElixirCredoOutputDefault() {
all() all()
.then(() => process.exit(0)) .then(() => process.exit(0))
.catch((err) => { .catch((err) => {
console.error(err) core.error(err)
process.exit(1) process.exit(1)
}) })
@@ -4,9 +4,11 @@ simulateInput('rebar3-version', '3.20')
simulateInput('install-rebar', 'true') simulateInput('install-rebar', 'true')
simulateInput('install-hex', 'true') simulateInput('install-hex', 'true')
simulateInput('github-token', process.env.GITHUB_TOKEN) simulateInput('github-token', process.env.GITHUB_TOKEN)
simulateInput('hexpm-mirrors', ['https://builds.hex.pm'])
const assert = require('assert') const assert = require('assert')
const fs = require('fs') const fs = require('fs')
const core = require('@actions/core')
const setupBeam = require('../src/setup-beam') const setupBeam = require('../src/setup-beam')
const installer = require('../src/installer') const installer = require('../src/installer')
@@ -174,6 +176,7 @@ async function testElixirVersions() {
let expected let expected
let spec let spec
let otpVersion let otpVersion
let before
const hexMirrors = ['https://repo.hex.pm'] const hexMirrors = ['https://repo.hex.pm']
spec = '1.1.x' spec = '1.1.x'
@@ -194,37 +197,37 @@ async function testElixirVersions() {
got = await setupBeam.getElixirVersion(spec, otpVersion, hexMirrors) got = await setupBeam.getElixirVersion(spec, otpVersion, hexMirrors)
assert.deepStrictEqual(got, expected) assert.deepStrictEqual(got, expected)
simulateInput('version-type', 'strict') before = simulateInput('version-type', 'strict')
spec = '1.14.0' spec = '1.14.0'
otpVersion = 'master' otpVersion = 'master'
expected = 'v1.14.0' expected = 'v1.14.0'
got = await setupBeam.getElixirVersion(spec, otpVersion, hexMirrors) got = await setupBeam.getElixirVersion(spec, otpVersion, hexMirrors)
assert.deepStrictEqual(got, expected) 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' spec = 'v1.11.0-rc.0'
otpVersion = 'OTP-23' otpVersion = 'OTP-23'
expected = 'v1.11.0-rc.0-otp-23' expected = 'v1.11.0-rc.0-otp-23'
got = await setupBeam.getElixirVersion(spec, otpVersion, hexMirrors) got = await setupBeam.getElixirVersion(spec, otpVersion, hexMirrors)
assert.deepStrictEqual(got, expected) 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' spec = 'v1.11.0'
otpVersion = '22.3.4.2' otpVersion = '22.3.4.2'
expected = 'v1.11.0-otp-22' expected = 'v1.11.0-otp-22'
got = await setupBeam.getElixirVersion(spec, otpVersion, hexMirrors) got = await setupBeam.getElixirVersion(spec, otpVersion, hexMirrors)
assert.deepStrictEqual(got, expected) assert.deepStrictEqual(got, expected)
simulateInput('version-type', 'loose') simulateInput('version-type', before)
simulateInput('version-type', 'strict') before = simulateInput('version-type', 'strict')
spec = 'main' spec = 'main'
otpVersion = '23.1' otpVersion = '23.1'
expected = 'main-otp-23' expected = 'main-otp-23'
got = await setupBeam.getElixirVersion(spec, otpVersion, hexMirrors) got = await setupBeam.getElixirVersion(spec, otpVersion, hexMirrors)
assert.deepStrictEqual(got, expected) assert.deepStrictEqual(got, expected)
simulateInput('version-type', 'loose') simulateInput('version-type', before)
} }
async function testGleamVersions() { async function testGleamVersions() {
@@ -245,13 +248,13 @@ async function testGleamVersions() {
got = await setupBeam.getGleamVersion(spec, otpVersion) got = await setupBeam.getGleamVersion(spec, otpVersion)
assert.deepStrictEqual(got, expected) assert.deepStrictEqual(got, expected)
simulateInput('version-type', 'strict') const before = simulateInput('version-type', 'strict')
spec = 'v0.14.0-rc2' spec = 'v0.14.0-rc2'
otpVersion = 'OTP-22' otpVersion = 'OTP-22'
expected = 'v0.14.0-rc2' expected = 'v0.14.0-rc2'
got = await setupBeam.getGleamVersion(spec, otpVersion) got = await setupBeam.getGleamVersion(spec, otpVersion)
assert.deepStrictEqual(got, expected) assert.deepStrictEqual(got, expected)
simulateInput('version-type', 'loose') simulateInput('version-type', before)
} }
async function testRebar3Versions() { async function testRebar3Versions() {
@@ -279,6 +282,7 @@ async function testGetVersionFromSpec() {
let got let got
let expected let expected
let spec let spec
let before
const versions = [ const versions = [
'3.2.30.5', '3.2.30.5',
'3.2.3.5', '3.2.3.5',
@@ -320,19 +324,19 @@ async function testGetVersionFromSpec() {
got = setupBeam.getVersionFromSpec(spec, versions) got = setupBeam.getVersionFromSpec(spec, versions)
assert.deepStrictEqual(got, expected) assert.deepStrictEqual(got, expected)
simulateInput('version-type', 'strict') before = simulateInput('version-type', 'strict')
spec = '1' spec = '1'
expected = '1' expected = '1'
got = setupBeam.getVersionFromSpec(spec, versions) got = setupBeam.getVersionFromSpec(spec, versions)
assert.deepStrictEqual(got, expected) assert.deepStrictEqual(got, expected)
simulateInput('version-type', 'loose') simulateInput('version-type', before)
simulateInput('version-type', 'strict') before = simulateInput('version-type', 'strict')
spec = '1.0' spec = '1.0'
expected = '1.0' expected = '1.0'
got = setupBeam.getVersionFromSpec(spec, versions) got = setupBeam.getVersionFromSpec(spec, versions)
assert.deepStrictEqual(got, expected) assert.deepStrictEqual(got, expected)
simulateInput('version-type', 'loose') simulateInput('version-type', before)
spec = '2' spec = '2'
expected = '2.10' expected = '2.10'
@@ -359,12 +363,12 @@ async function testGetVersionFromSpec() {
got = setupBeam.getVersionFromSpec(spec, versions) got = setupBeam.getVersionFromSpec(spec, versions)
assert.deepStrictEqual(got, expected) assert.deepStrictEqual(got, expected)
simulateInput('version-type', 'strict') before = simulateInput('version-type', 'strict')
spec = '24.0-rc3' spec = '24.0-rc3'
expected = '24.0-rc3' expected = '24.0-rc3'
got = setupBeam.getVersionFromSpec(spec, versions) got = setupBeam.getVersionFromSpec(spec, versions)
assert.deepStrictEqual(got, expected) assert.deepStrictEqual(got, expected)
simulateInput('version-type', 'loose') simulateInput('version-type', before)
spec = '24.0-rc2' spec = '24.0-rc2'
expected = '24.0-rc2' expected = '24.0-rc2'
@@ -391,24 +395,24 @@ async function testGetVersionFromSpec() {
got = setupBeam.getVersionFromSpec(spec, versions) got = setupBeam.getVersionFromSpec(spec, versions)
assert.deepStrictEqual(got, expected) assert.deepStrictEqual(got, expected)
simulateInput('version-type', 'strict') before = simulateInput('version-type', 'strict')
spec = 'master' spec = 'master'
expected = 'master' expected = 'master'
got = setupBeam.getVersionFromSpec(spec, versions) got = setupBeam.getVersionFromSpec(spec, versions)
assert.deepStrictEqual(got, expected) assert.deepStrictEqual(got, expected)
simulateInput('version-type', 'loose') simulateInput('version-type', before)
spec = 'master' spec = 'master'
expected = 'master' expected = 'master'
got = setupBeam.getVersionFromSpec(spec, versions) got = setupBeam.getVersionFromSpec(spec, versions)
assert.deepStrictEqual(got, expected) assert.deepStrictEqual(got, expected)
simulateInput('version-type', 'strict') before = simulateInput('version-type', 'strict')
spec = '22.3.4.2' spec = '22.3.4.2'
expected = '22.3.4.2' expected = '22.3.4.2'
got = setupBeam.getVersionFromSpec(spec, versions) got = setupBeam.getVersionFromSpec(spec, versions)
assert.deepStrictEqual(got, expected) assert.deepStrictEqual(got, expected)
simulateInput('version-type', 'loose') simulateInput('version-type', before)
} }
async function testParseVersionFile() { async function testParseVersionFile() {
@@ -427,7 +431,7 @@ elixir ${elixir} # comment, with space
not-gleam 0.23 # not picked up not-gleam 0.23 # not picked up
gleam ${gleam} gleam ${gleam}
rebar ${rebar3}` rebar ${rebar3}`
const filename = '__tests__/.tool-versions' const filename = 'test/.tool-versions'
fs.writeFileSync(filename, toolVersions) fs.writeFileSync(filename, toolVersions)
process.env.GITHUB_WORKSPACE = '' process.env.GITHUB_WORKSPACE = ''
const appVersions = setupBeam.parseVersionFile(filename) const appVersions = setupBeam.parseVersionFile(filename)
@@ -454,13 +458,13 @@ rebar ${rebar3}`
} }
function unsimulateInput(key) { function unsimulateInput(key) {
const before = process.env[input(key)] return simulateInput(key, '')
simulateInput(key, '')
return before
} }
function simulateInput(key, value) { function simulateInput(key, value) {
const before = process.env[input(key)]
process.env[input(key)] = value process.env[input(key)] = value
return before
} }
function input(key) { function input(key) {
@@ -470,6 +474,6 @@ function input(key) {
all() all()
.then(() => process.exit(0)) .then(() => process.exit(0))
.catch((err) => { .catch((err) => {
console.error(err) core.error(err)
process.exit(1) process.exit(1)
}) })