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 2026-07-16 07:46:42 +02:00
commit 1adbf3753d
No known key found for this signature in database
4 changed files with 242 additions and 20 deletions

View file

@ -1,22 +1,22 @@
import {
jest,
describe,
it,
expect,
beforeAll,
beforeEach,
afterEach,
afterAll
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
jest
} from '@jest/globals';
import fs from 'fs';
import cp from 'child_process';
import fs from 'fs';
import goJsonData from './data/golang-dl.json' with {type: 'json'};
import matchers from '../matchers.json' with {type: 'json'};
import goTestManifest from './data/versions-manifest.json' with {type: 'json'};
import matchers from '../matchers.json' with { type: 'json' };
import goJsonData from './data/golang-dl.json' with { type: 'json' };
import goTestManifest from './data/versions-manifest.json' with { type: 'json' };
import type {IGoVersion} from '../src/installer.js';
import type {IToolRelease} from '@actions/tool-cache';
import type { IToolRelease } from '@actions/tool-cache';
import type { IGoVersion } from '../src/installer.js';
const httpClientGetJson = jest.fn();
@ -336,11 +336,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: IGoVersion | undefined = await im.findMatch('1.14.0-rc.1');
expect(match).toBeDefined();
const version: string = match ? match.version : '';
@ -349,6 +349,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';