Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ patch-level:
description: Include the patch levels on the versions (default is major.minor)
required: false
default: 'false'
latest-patches-only:
description: When patch-level is true, only include the latest patch version of each major.minor version in the matrix. Does nothing if patch-level is false. Cannot be used with unstable.
required: false
default: 'false'
strict-semver:
default: Use strict semver version in matrix. E.g. `1.16` -> `1.16.0` and `1.18beta2` -> `1.18.0-beta.2`.
required: false
default: 'false'
```

## Outputs
Expand Down
57 changes: 50 additions & 7 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ test('test latest version', () => {

test('test version matrix', () => {
const t = JSON.parse(fs.readFileSync('__tests__/testdata/dl.json', 'utf8'))
const m = matrix('1.16', false, false, false, t)
const m = matrix('1.16', false, false, false, false, t)
expect(m).toEqual(['1.16', '1.17', '1.18'])
})

test('test unstable version matrix', () => {
const t = JSON.parse(fs.readFileSync('__tests__/testdata/dl.json', 'utf8'))
const m = matrix('1.16', true, false, false, t)
const m = matrix('1.16', true, false, false, false, t)
expect(m).toEqual([
'1.16beta1',
'1.16rc1',
Expand All @@ -52,7 +52,7 @@ test('test unstable version matrix', () => {

test('test patch level version matrix', () => {
const t = JSON.parse(fs.readFileSync('__tests__/testdata/dl.json', 'utf8'))
const m = matrix('1.16', false, true, false, t)
const m = matrix('1.16', false, true, false, false, t)
expect(m).toEqual([
'1.16',
'1.16.1',
Expand Down Expand Up @@ -85,7 +85,7 @@ test('test patch level version matrix', () => {

test('test patch level, unstable version matrix', () => {
const t = JSON.parse(fs.readFileSync('__tests__/testdata/dl.json', 'utf8'))
const m = matrix('1.16', true, true, false, t)
const m = matrix('1.16', true, true, false, false, t)
expect(m).toEqual([
'1.16beta1',
'1.16rc1',
Expand Down Expand Up @@ -124,15 +124,58 @@ test('test patch level, unstable version matrix', () => {
])
})

test('test patch level, unstable, semver clean version matrix', () => {
const t = JSON.parse(fs.readFileSync('__tests__/testdata/dl.json', 'utf8'))
const m = matrix('1.16', true, true, false, true, t)
expect(m).toEqual([
'1.16.0-beta.1',
'1.16.0-rc.1',
'1.16.0',
'1.16.1',
'1.16.2',
'1.16.3',
'1.16.4',
'1.16.5',
'1.16.6',
'1.16.7',
'1.16.8',
'1.16.9',
'1.16.10',
'1.16.11',
'1.16.12',
'1.16.13',
'1.16.14',
'1.16.15',
'1.17.0-beta.1',
'1.17.0-rc.1',
'1.17.0-rc.2',
'1.17.0',
'1.17.1',
'1.17.2',
'1.17.3',
'1.17.4',
'1.17.5',
'1.17.6',
'1.17.7',
'1.17.8',
'1.18.0-beta.1',
'1.18.0-beta.2',
'1.18.0-rc.1',
'1.18.0'
])
})

test('test patch level with latest patches only', () => {
const t = JSON.parse(fs.readFileSync('__tests__/testdata/dl.json', 'utf8'))
const m = matrix('1.16', false, true, true, t)
const m = matrix('1.16', false, true, true, false, t)
expect(m).toEqual(['1.16.15', '1.17.8', '1.18'])
})

test('test patch level with latest patches only and unstable throws error', () => {
const t = JSON.parse(fs.readFileSync('__tests__/testdata/dl.json', 'utf8'))
expect(() => {
matrix('1.16', true, true, true, t)
}).toThrow('The options "unstable" and "latest-patches-only" cannot be used together')
matrix('1.16', true, true, true, false, t)
}).toThrow(
'The options "unstable" and "latest-patches-only" cannot be used together'
)
})
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ inputs:
description: When patch-level is true, only include the latest patch version of each major.minor version in the matrix. Does nothing if patch-level is false. Cannot be used with unstable.
required: false
default: 'false'
strict-semver:
description: Use strict semver version in matrix. E.g. `1.16` -> `1.16.0` and `1.18beta2` -> `1.18.0-beta.2`.
required: false
default: 'false'
outputs:
go-mod-version:
description: The Go version specified by go.mod
Expand All @@ -38,5 +42,5 @@ outputs:
module:
description: The Go module path (as specified by go.mod)
runs:
using: node20
using: node24
main: dist/index.js
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
],
"author": "Arne Jørgensen",
"license": "MIT",
"engines": {
"node": ">=24"
},
"dependencies": {
"@actions/core": "^1.11.1",
"node-fetch": "~2.7.0",
Expand Down
26 changes: 22 additions & 4 deletions src/go-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ const getVersions = async withUnsupported => {
return result
}

const matrix = (min, withUnstable, withPatchLevel, withLatestPatches, tags) => {
const matrix = (
min,
withUnstable,
withPatchLevel,
withLatestPatches,
withStrictSemver,
tags
) => {
const minClean = semverCoerce(min)
if (minClean === null) {
throw new Error(`Minimal version isn't quite right: ${min}`)
Expand All @@ -63,6 +70,17 @@ const matrix = (min, withUnstable, withPatchLevel, withLatestPatches, tags) => {
const v2 = semverCoerce(v)
return v2 !== null && semverGte(v2, minClean)
})
if (withStrictSemver) {
versions = versions.map(version => {
// Alpha and beta versions on https://go.dev/dl are named like
// `1.18beta2`. We rewrite into strict semver syntax:
// `1.18.0-beta.2`.
version = version.replace(/([^0-9\\.]+)/, '-$1.')
return semverCoerce(version, {
includePrerelease: true
}).version
})
}
if (!withPatchLevel) {
versions = versions.map(version => {
const parts = version.split('.')
Expand Down Expand Up @@ -117,11 +135,11 @@ const minimal = versions => {
}

export {
getGoModVersion,
getVersions,
gomod,
latest,
matrix,
minimal,
modulename,
getGoModVersion,
getVersions
modulename
}
6 changes: 4 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as core from '@actions/core'
import {
getGoModVersion,
getVersions,
gomod,
latest,
matrix,
minimal,
modulename,
getGoModVersion
modulename
} from './go-versions.js'

async function run() {
Expand All @@ -22,6 +22,7 @@ async function run() {
const withUnstable = core.getBooleanInput('unstable')
const withPatchLevel = core.getBooleanInput('patch-level')
const withLatestPatches = core.getBooleanInput('latest-patches-only')
const withStrictSemver = core.getBooleanInput('strict-semver')
const content = gomod(`${workingDirectory}/go.mod`)
const name = modulename(content)
const goModVersion = getGoModVersion(content)
Expand All @@ -31,6 +32,7 @@ async function run() {
withUnstable,
withPatchLevel,
withLatestPatches,
withStrictSemver,
versions
)
const lat = latest(mat)
Expand Down