Skip to content

Commit f279813

Browse files
Merge pull request #250 from jromero/feature/windows-download-filename
Use explicit filename when downloading Windows go package
2 parents 1022489 + e0dce94 commit f279813

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

__tests__/setup-go.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ let matchers = require('../matchers.json');
1313
let goTestManifest = require('./data/versions-manifest.json');
1414
let matcherPattern = matchers.problemMatcher[0].pattern[0];
1515
let matcherRegExp = new RegExp(matcherPattern.regexp);
16+
let win32Join = path.win32.join;
17+
let posixJoin = path.posix.join;
1618

1719
describe('setup-go', () => {
1820
let inputs = {} as any;
@@ -27,8 +29,10 @@ describe('setup-go', () => {
2729
let getSpy: jest.SpyInstance;
2830
let platSpy: jest.SpyInstance;
2931
let archSpy: jest.SpyInstance;
32+
let joinSpy: jest.SpyInstance;
3033
let dlSpy: jest.SpyInstance;
3134
let extractTarSpy: jest.SpyInstance;
35+
let extractZipSpy: jest.SpyInstance;
3236
let cacheSpy: jest.SpyInstance;
3337
let dbgSpy: jest.SpyInstance;
3438
let whichSpy: jest.SpyInstance;
@@ -61,10 +65,21 @@ describe('setup-go', () => {
6165
archSpy.mockImplementation(() => os['arch']);
6266
execSpy = jest.spyOn(cp, 'execSync');
6367

68+
// switch path join behaviour based on set os.platform
69+
joinSpy = jest.spyOn(path, 'join');
70+
joinSpy.mockImplementation((...paths: string[]): string => {
71+
if (os['platform'] == 'win32') {
72+
return win32Join(...paths);
73+
}
74+
75+
return posixJoin(...paths);
76+
});
77+
6478
// @actions/tool-cache
6579
findSpy = jest.spyOn(tc, 'find');
6680
dlSpy = jest.spyOn(tc, 'downloadTool');
6781
extractTarSpy = jest.spyOn(tc, 'extractTar');
82+
extractZipSpy = jest.spyOn(tc, 'extractZip');
6883
cacheSpy = jest.spyOn(tc, 'cacheDir');
6984
getSpy = jest.spyOn(im, 'getVersionsDist');
7085
getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
@@ -325,6 +340,31 @@ describe('setup-go', () => {
325340
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
326341
});
327342

343+
it('downloads a version not in the cache (windows)', async () => {
344+
os.platform = 'win32';
345+
os.arch = 'x64';
346+
347+
inputs['go-version'] = '1.13.1';
348+
process.env['RUNNER_TEMP'] = 'C:\\temp\\';
349+
350+
findSpy.mockImplementation(() => '');
351+
dlSpy.mockImplementation(() => 'C:\\temp\\some\\path');
352+
extractZipSpy.mockImplementation(() => 'C:\\temp\\some\\other\\path');
353+
354+
let toolPath = path.normalize('C:\\cache\\go\\1.13.0\\x64');
355+
cacheSpy.mockImplementation(() => toolPath);
356+
357+
await main.run();
358+
359+
let expPath = path.win32.join(toolPath, 'bin');
360+
expect(dlSpy).toHaveBeenCalledWith(
361+
'https://storage.googleapis.com/golang/go1.13.1.windows-amd64.zip',
362+
'C:\\temp\\go1.13.1.windows-amd64.zip',
363+
undefined
364+
);
365+
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
366+
});
367+
328368
it('does not find a version that does not exist', async () => {
329369
os.platform = 'linux';
330370
os.arch = 'x64';

dist/setup/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62942,7 +62942,11 @@ function resolveVersionFromManifest(versionSpec, stable, auth) {
6294262942
function installGoVersion(info, auth) {
6294362943
return __awaiter(this, void 0, void 0, function* () {
6294462944
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
62945-
const downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, auth);
62945+
// Windows requires that we keep the extension (.zip) for extraction
62946+
const isWindows = os_1.default.platform() === 'win32';
62947+
const tempDir = process.env.RUNNER_TEMP || '.';
62948+
const fileName = isWindows ? path.join(tempDir, info.fileName) : undefined;
62949+
const downloadPath = yield tc.downloadTool(info.downloadUrl, fileName, auth);
6294662950
core.info('Extracting Go...');
6294762951
let extPath = yield extractGoArchive(downloadPath);
6294862952
core.info(`Successfully extracted go to ${extPath}`);

src/installer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,13 @@ async function installGoVersion(
132132
auth: string | undefined
133133
): Promise<string> {
134134
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
135-
const downloadPath = await tc.downloadTool(info.downloadUrl, undefined, auth);
135+
136+
// Windows requires that we keep the extension (.zip) for extraction
137+
const isWindows = os.platform() === 'win32';
138+
const tempDir = process.env.RUNNER_TEMP || '.';
139+
const fileName = isWindows ? path.join(tempDir, info.fileName) : undefined;
140+
141+
const downloadPath = await tc.downloadTool(info.downloadUrl, fileName, auth);
136142

137143
core.info('Extracting Go...');
138144
let extPath = await extractGoArchive(downloadPath);

0 commit comments

Comments
 (0)