Add support for rc and beta versions in go.mod file

The regex in `parseGoVersionFile()` didn't consider rc and beta
versions. The regex has been extended.

In `findMatch()` the match is checked using `semver.satisfies()`. But
`semver.satisfies()` doesn't no about Go's non-semver rc and beta
version formats (1.16c1 instead of 1.16.0-rc.1).

We cannot use `makeSemver()` on `versionSpec` and compare the result
using `semver.satisfies()` because `versionSpec` could be, well, a
spec. Instead we first check if there is a strict match between the
candidate version and the versionSpec.

Fixes #525.
This commit is contained in:
Arne Jørgensen 2025-12-18 10:28:45 +01:00
parent 7a3fe6cf4c
commit 90e09cb0fc
No known key found for this signature in database
4 changed files with 228 additions and 6 deletions

View file

@ -252,11 +252,11 @@ describe('setup-go', () => {
expect(fileName).toBe('go1.13.7.windows-386.zip');
});
it('finds unstable pre-release version', async () => {
it('finds unstable release candidate', async () => {
os.platform = 'linux';
os.arch = 'x64';
// spec: 1.14, stable=false => go1.14rc1
// spec: 1.14.0-rc.1, stable=false => go1.14rc1
const match: im.IGoVersion | undefined = await im.findMatch('1.14.0-rc.1');
expect(match).toBeDefined();
const version: string = match ? match.version : '';
@ -265,6 +265,47 @@ describe('setup-go', () => {
expect(fileName).toBe('go1.14rc1.linux-amd64.tar.gz');
});
it('finds unstable beta version', async () => {
os.platform = 'linux';
os.arch = 'x64';
// spec: 1.18.0-beta.2, stable=false => go1.18beta2
const match: im.IGoVersion | undefined = await im.findMatch(
'1.18.0-beta.2'
);
expect(match).toBeDefined();
const version: string = match ? match.version : '';
expect(version).toBe('go1.18beta2');
const fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.18beta2.linux-amd64.tar.gz');
});
it('finds unstable release candidate (go version format)', async () => {
os.platform = 'linux';
os.arch = 'x64';
// spec: 1.14rc1, stable=false => go1.14rc1
const match: im.IGoVersion | undefined = await im.findMatch('1.14rc1');
expect(match).toBeDefined();
const version: string = match ? match.version : '';
expect(version).toBe('go1.14rc1');
const fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.14rc1.linux-amd64.tar.gz');
});
it('finds unstable beta version (go version format)', async () => {
os.platform = 'linux';
os.arch = 'x64';
// spec: 1.18beta2, stable=false => go1.18beta2
const match: im.IGoVersion | undefined = await im.findMatch('1.18beta2');
expect(match).toBeDefined();
const version: string = match ? match.version : '';
expect(version).toBe('go1.18beta2');
const fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.18beta2.linux-amd64.tar.gz');
});
it('evaluates to stable with input as true', async () => {
inputs['go-version'] = '1.13.0';
inputs.stable = 'true';