Add support for rc and beta versions in go.mod file (#701)
* 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. * Add support for beta versions in go.mod toolchain directive * Support prerelease versions in the toolchain cache
This commit is contained in:
1 parent
b2a9ab24f0
commit
7d2730e317
4 files changed
+306
-11
No files matched your search
+108
-3
@@ -343,11 +343,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 : '';
|
||||
@@ -356,6 +356,46 @@ 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';
|
||||
@@ -431,6 +471,26 @@ describe('setup-go', () => {
|
||||
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
||||
});
|
||||
|
||||
it('finds a rc version of go already in the cache', async () => {
|
||||
inputs['go-version'] = '1.14rc1';
|
||||
|
||||
const toolPath = path.normalize('/cache/go/1.14.0rc.1/x64');
|
||||
findSpy.mockImplementation(() => toolPath);
|
||||
await main.run();
|
||||
|
||||
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
||||
});
|
||||
|
||||
it('finds a rc version in the cache and adds it to the path', async () => {
|
||||
inputs['go-version'] = '1.14rc1';
|
||||
const toolPath = path.normalize('/cache/go/1.14.0.rc.1/x64');
|
||||
findSpy.mockImplementation(() => toolPath);
|
||||
await main.run();
|
||||
|
||||
const expPath = path.join(toolPath, 'bin');
|
||||
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
||||
});
|
||||
|
||||
it('handles unhandled error and reports error', async () => {
|
||||
const errMsg = 'unhandled error message';
|
||||
inputs['go-version'] = '1.13.0';
|
||||
@@ -487,6 +547,51 @@ describe('setup-go', () => {
|
||||
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
||||
});
|
||||
|
||||
it('downloads a rc version not in the cache', async () => {
|
||||
os.platform = 'linux';
|
||||
os.arch = 'x64';
|
||||
|
||||
inputs['go-version'] = '1.14rc1';
|
||||
|
||||
findSpy.mockImplementation(() => '');
|
||||
dlSpy.mockImplementation(() => '/some/temp/path');
|
||||
const toolPath = path.normalize('/cache/go/1.14.0-rc.1/x64');
|
||||
extractTarSpy.mockImplementation(() => '/some/other/temp/path');
|
||||
cacheSpy.mockImplementation(() => toolPath);
|
||||
await main.run();
|
||||
|
||||
const expPath = path.join(toolPath, 'bin');
|
||||
|
||||
expect(dlSpy).toHaveBeenCalled();
|
||||
expect(extractTarSpy).toHaveBeenCalled();
|
||||
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
||||
});
|
||||
|
||||
it('downloads a rc version not in the cache (windows)', async () => {
|
||||
os.platform = 'win32';
|
||||
os.arch = 'x64';
|
||||
|
||||
inputs['go-version'] = '1.14rc1';
|
||||
process.env['RUNNER_TEMP'] = 'C:\\temp\\';
|
||||
|
||||
findSpy.mockImplementation(() => '');
|
||||
dlSpy.mockImplementation(() => 'C:\\temp\\some\\path');
|
||||
extractZipSpy.mockImplementation(() => 'C:\\temp\\some\\other\\path');
|
||||
|
||||
const toolPath = path.normalize('C:\\cache\\go\\1.21.0-rc.2\\x64');
|
||||
cacheSpy.mockImplementation(() => toolPath);
|
||||
|
||||
await main.run();
|
||||
|
||||
const expPath = path.win32.join(toolPath, 'bin');
|
||||
expect(dlSpy).toHaveBeenCalledWith(
|
||||
'https://go.dev/dl/go1.14rc1.windows-amd64.zip',
|
||||
'C:\\temp\\go1.14rc1.windows-amd64.zip',
|
||||
undefined
|
||||
);
|
||||
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
||||
});
|
||||
|
||||
it('does not find a version that does not exist', async () => {
|
||||
os.platform = 'linux';
|
||||
os.arch = 'x64';
|
||||
@@ -1298,7 +1403,7 @@ use .
|
||||
});
|
||||
|
||||
describe('go-version-file-toolchain', () => {
|
||||
const goVersions = ['1.22.0', '1.21rc2', '1.18'];
|
||||
const goVersions = ['1.22.0', '1.21rc2', '1.18', '1.18beta2'];
|
||||
const placeholderVersion = '1.19';
|
||||
const buildGoMod = (
|
||||
goVersion: string,
|
||||
|
||||
Reference in new issue
Block a user