Skip to content

Commit

Permalink
Add known branch exceptions to version matching
Browse files Browse the repository at this point in the history
Maybe doing it this way is better, since we don't "break"
existing consumption elements

Forcing `version-type: strict`, while explicit, would
probably force some installations to use a too-specific
Elixir version
  • Loading branch information
paulo-ferraz-oliveira committed Jan 17, 2024
1 parent 980f47e commit 70cd6c0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@ jobs:
SHA=$(git rev-parse --short HEAD)
sed -i'.bak' \
-e "s/const setupBeamVersion = '.*'/const setupBeamVersion = '${SHA}'/g" \
dist/index.js
# it always starts by being 'undefined'
NEWVER=$(grep -oE "const setupBeamVersion = '.*'" dist/index.js | cut -d\' -f2)
if [ "$NEWVER" == "undefined" ]; then
exit 1
else
echo "Continuing... new version is ${NEWVER}"
fi
src/setup-beam.js
npm run build-dist
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git add src/setup-beam.js
git add dist/index.js
git commit -m "Update setup-beam version output to ${SHA}"
git push origin main
Expand Down
8 changes: 6 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9870,7 +9870,7 @@ async function main() {
await maybeInstallRebar3(rebar3Spec)

// undefined is replaced by a function, post- main branch merge
const setupBeamVersion = '4678b57'
const setupBeamVersion = 'undefined'
core.setOutput('setup-beam-version', setupBeamVersion)
}

Expand Down Expand Up @@ -10220,7 +10220,7 @@ function getVersionFromSpec(spec0, versions0) {
const rangeMax = semver.maxSatisfying(versions, rangeForMax)
let version = null

if (isStrictVersion() || isRC(spec0)) {
if (isStrictVersion() || isRC(spec0) || isKnownBranch(spec0)) {
if (versions0[spec]) {
// If `version-type: strict` or version is RC, we obtain it directly
version = versions0[spec]
Expand Down Expand Up @@ -10292,6 +10292,10 @@ function isRC(ver) {
return ver.match(xyzAbcVersion('^', '(?:-rc\\.?\\d+)'))
}

function isKnownBranch(ver) {
return ['main', 'master', 'maint'].includes(ver)
}

function getRunnerOSVersion() {
const ImageOSToContainer = {
ubuntu18: 'ubuntu-18.04',
Expand Down
6 changes: 5 additions & 1 deletion src/setup-beam.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ function getVersionFromSpec(spec0, versions0) {
const rangeMax = semver.maxSatisfying(versions, rangeForMax)
let version = null

if (isStrictVersion() || isRC(spec0)) {
if (isStrictVersion() || isRC(spec0) || isKnownBranch(spec0)) {
if (versions0[spec]) {
// If `version-type: strict` or version is RC, we obtain it directly
version = versions0[spec]
Expand Down Expand Up @@ -476,6 +476,10 @@ function isRC(ver) {
return ver.match(xyzAbcVersion('^', '(?:-rc\\.?\\d+)'))
}

function isKnownBranch(ver) {
return ['main', 'master', 'maint'].includes(ver)
}

function getRunnerOSVersion() {
const ImageOSToContainer = {
ubuntu18: 'ubuntu-18.04',
Expand Down
12 changes: 12 additions & 0 deletions test/setup-beam.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ async function testOTPVersions() {
expected = 'OTP-20.0.5'
got = await setupBeam.getOTPVersion(spec, osVersion)
assert.deepStrictEqual(got, expected)

spec = 'maint'
osVersion = 'ubuntu-22.04'
expected = 'maint'
got = await setupBeam.getOTPVersion(spec, osVersion, hexMirrors)
assert.deepStrictEqual(got, expected)

spec = 'master'
osVersion = 'ubuntu-22.04'
expected = 'master'
got = await setupBeam.getOTPVersion(spec, osVersion, hexMirrors)
assert.deepStrictEqual(got, expected)
}

if (process.platform === 'win32') {
Expand Down

0 comments on commit 70cd6c0

Please sign in to comment.