diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 09d76c0..b99f21b 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -471,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'; @@ -527,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'; diff --git a/dist/setup/index.js b/dist/setup/index.js index 6782368..9a1f0b4 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -42006,8 +42006,12 @@ async function getGo(versionSpec, checkLatest, auth, arch = external_os_default( const toolCacheName = customBaseUrl ? customToolCacheName(customBaseUrl) : 'go'; + // Convert prerelease specs (1.21rc2) to semver (1.21.0-rc.2). + const cacheSpec = /^\d+\.\d+(\.\d+)?(beta|rc)\d+$/.test(versionSpec) + ? makeSemver(versionSpec) + : versionSpec; // check cache - const toolPath = find(toolCacheName, versionSpec, arch); + const toolPath = find(toolCacheName, cacheSpec, arch); // If not found in cache, download if (toolPath) { core_info(`Found in cache @ ${toolPath}`); diff --git a/src/installer.ts b/src/installer.ts index f9c11f9..92a2223 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -123,8 +123,13 @@ export async function getGo( ? customToolCacheName(customBaseUrl) : 'go'; + // Convert prerelease specs (1.21rc2) to semver (1.21.0-rc.2). + const cacheSpec = /^\d+\.\d+(\.\d+)?(beta|rc)\d+$/.test(versionSpec) + ? makeSemver(versionSpec) + : versionSpec; + // check cache - const toolPath = tc.find(toolCacheName, versionSpec, arch); + const toolPath = tc.find(toolCacheName, cacheSpec, arch); // If not found in cache, download if (toolPath) { core.info(`Found in cache @ ${toolPath}`);