Skip to content

Commit 2a34c33

Browse files
committed
Export GOROOT for versions < 1.9
1 parent 83124a1 commit 2a34c33

File tree

3 files changed

+56
-20
lines changed

3 files changed

+56
-20
lines changed

__tests__/setup-go.test.ts

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ describe('setup-go', () => {
2020

2121
let inSpy: jest.SpyInstance;
2222
let getBooleanInputSpy: jest.SpyInstance;
23+
let exportVarSpy: jest.SpyInstance;
2324
let findSpy: jest.SpyInstance;
2425
let cnSpy: jest.SpyInstance;
2526
let logSpy: jest.SpyInstance;
2627
let getSpy: jest.SpyInstance;
2728
let platSpy: jest.SpyInstance;
2829
let archSpy: jest.SpyInstance;
2930
let dlSpy: jest.SpyInstance;
30-
let exSpy: jest.SpyInstance;
31+
let extractTarSpy: jest.SpyInstance;
3132
let cacheSpy: jest.SpyInstance;
3233
let dbgSpy: jest.SpyInstance;
3334
let whichSpy: jest.SpyInstance;
@@ -49,7 +50,8 @@ describe('setup-go', () => {
4950
inSpy.mockImplementation(name => inputs[name]);
5051
getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput');
5152
getBooleanInputSpy.mockImplementation(name => inputs[name]);
52-
exSpy = jest.spyOn(core, 'exportVariable');
53+
exportVarSpy = jest.spyOn(core, 'exportVariable');
54+
extractTarSpy = jest.spyOn(core, 'exportVariable');
5355

5456
// node
5557
os = {};
@@ -62,7 +64,7 @@ describe('setup-go', () => {
6264
// @actions/tool-cache
6365
findSpy = jest.spyOn(tc, 'find');
6466
dlSpy = jest.spyOn(tc, 'downloadTool');
65-
exSpy = jest.spyOn(tc, 'extractTar');
67+
extractTarSpy = jest.spyOn(tc, 'extractTar');
6668
cacheSpy = jest.spyOn(tc, 'cacheDir');
6769
getSpy = jest.spyOn(im, 'getVersionsDist');
6870
getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
@@ -231,22 +233,41 @@ describe('setup-go', () => {
231233
expect(logSpy).toHaveBeenCalledWith(`Setup go version spec 1.13.0`);
232234
});
233235

234-
it('does not export any varibles', async () => {
236+
it('does not export any variables for Go versions >=1.9', async () => {
235237
inputs['go-version'] = '1.13.0';
236238
inSpy.mockImplementation(name => inputs[name]);
237239

238240
let toolPath = path.normalize('/cache/go/1.13.0/x64');
239241
findSpy.mockImplementation(() => toolPath);
240242

241-
let vars = {} as any;
242-
exSpy.mockImplementation(async (name, val) => {
243+
let vars: { [key: string]: string; } = {};
244+
exportVarSpy.mockImplementation((name: string, val: string) => {
243245
vars[name] = val;
244246
});
245247

246248
await main.run();
247249
expect(vars).toStrictEqual({});
248250
});
249251

252+
it('exports GOROOT for Go versions <1.9', async () => {
253+
inputs['go-version'] = '1.8';
254+
inSpy.mockImplementation(name => inputs[name]);
255+
256+
let toolPath = path.normalize('/cache/go/1.8.0/x64');
257+
findSpy.mockImplementation(() => toolPath);
258+
259+
let vars: { [key: string]: string; } = {};
260+
exportVarSpy.mockImplementation((name: string, val: string) => {
261+
vars[name] = val;
262+
});
263+
264+
await main.run();
265+
expect(vars).toStrictEqual({
266+
"GOROOT": toolPath
267+
});
268+
});
269+
270+
250271
it('finds a version of go already in the cache', async () => {
251272
inputs['go-version'] = '1.13.0';
252273

@@ -288,14 +309,14 @@ describe('setup-go', () => {
288309
findSpy.mockImplementation(() => '');
289310
dlSpy.mockImplementation(() => '/some/temp/path');
290311
let toolPath = path.normalize('/cache/go/1.13.0/x64');
291-
exSpy.mockImplementation(() => '/some/other/temp/path');
312+
extractTarSpy.mockImplementation(() => '/some/other/temp/path');
292313
cacheSpy.mockImplementation(() => toolPath);
293314
await main.run();
294315

295316
let expPath = path.join(toolPath, 'bin');
296317

297318
expect(dlSpy).toHaveBeenCalled();
298-
expect(exSpy).toHaveBeenCalled();
319+
expect(extractTarSpy).toHaveBeenCalled();
299320
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
300321
});
301322

@@ -330,15 +351,15 @@ describe('setup-go', () => {
330351

331352
dlSpy.mockImplementation(async () => '/some/temp/path');
332353
let toolPath = path.normalize('/cache/go/1.12.16/x64');
333-
exSpy.mockImplementation(async () => '/some/other/temp/path');
354+
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
334355
cacheSpy.mockImplementation(async () => toolPath);
335356

336357
await main.run();
337358

338359
let expPath = path.join(toolPath, 'bin');
339360

340361
expect(dlSpy).toHaveBeenCalled();
341-
expect(exSpy).toHaveBeenCalled();
362+
expect(extractTarSpy).toHaveBeenCalled();
342363
expect(logSpy).not.toHaveBeenCalledWith(
343364
'Not found in manifest. Falling back to download directly from Go'
344365
);
@@ -367,15 +388,15 @@ describe('setup-go', () => {
367388

368389
dlSpy.mockImplementation(async () => '/some/temp/path');
369390
let toolPath = path.normalize('/cache/go/1.12.17/x64');
370-
exSpy.mockImplementation(async () => '/some/other/temp/path');
391+
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
371392
cacheSpy.mockImplementation(async () => toolPath);
372393

373394
await main.run();
374395

375396
let expPath = path.join(toolPath, 'bin');
376397

377398
expect(dlSpy).toHaveBeenCalled();
378-
expect(exSpy).toHaveBeenCalled();
399+
expect(extractTarSpy).toHaveBeenCalled();
379400
expect(logSpy).not.toHaveBeenCalledWith(
380401
'Not found in manifest. Falling back to download directly from Go'
381402
);
@@ -404,7 +425,7 @@ describe('setup-go', () => {
404425

405426
dlSpy.mockImplementation(async () => '/some/temp/path');
406427
let toolPath = path.normalize('/cache/go/1.12.14/x64');
407-
exSpy.mockImplementation(async () => '/some/other/temp/path');
428+
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
408429
cacheSpy.mockImplementation(async () => toolPath);
409430

410431
await main.run();
@@ -415,7 +436,7 @@ describe('setup-go', () => {
415436
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.12.14...');
416437
expect(dlSpy).toHaveBeenCalled();
417438
expect(logSpy).toHaveBeenCalledWith('matching 1.12.14...');
418-
expect(exSpy).toHaveBeenCalled();
439+
expect(extractTarSpy).toHaveBeenCalled();
419440
expect(logSpy).toHaveBeenCalledWith(
420441
'Not found in manifest. Falling back to download directly from Go'
421442
);
@@ -617,7 +638,7 @@ describe('setup-go', () => {
617638
const toolPath = path.normalize('/cache/go/1.16.1/x64');
618639
findSpy.mockReturnValue(toolPath);
619640
dlSpy.mockImplementation(async () => '/some/temp/path');
620-
exSpy.mockImplementation(async () => '/some/other/temp/path');
641+
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
621642
cacheSpy.mockImplementation(async () => toolPath);
622643

623644
await main.run();
@@ -639,7 +660,7 @@ describe('setup-go', () => {
639660
findSpy.mockImplementation(() => '');
640661
dlSpy.mockImplementation(async () => '/some/temp/path');
641662
const toolPath = path.normalize('/cache/go/1.17.5/x64');
642-
exSpy.mockImplementation(async () => '/some/other/temp/path');
663+
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
643664
cacheSpy.mockImplementation(async () => toolPath);
644665
const expectedUrl =
645666
'https://github.com/actions/go-versions/releases/download/1.17.6-1668090892/go-1.17.6-darwin-x64.tar.gz';
@@ -680,15 +701,15 @@ describe('setup-go', () => {
680701

681702
dlSpy.mockImplementation(async () => '/some/temp/path');
682703
let toolPath = path.normalize('/cache/go/1.13.7/x64');
683-
exSpy.mockImplementation(async () => '/some/other/temp/path');
704+
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
684705
cacheSpy.mockImplementation(async () => toolPath);
685706

686707
await main.run();
687708

688709
let expPath = path.join(toolPath, 'bin');
689710

690711
expect(dlSpy).toHaveBeenCalled();
691-
expect(exSpy).toHaveBeenCalled();
712+
expect(extractTarSpy).toHaveBeenCalled();
692713
expect(logSpy).toHaveBeenCalledWith(
693714
'Attempting to resolve the latest version from the manifest...'
694715
);
@@ -722,7 +743,7 @@ describe('setup-go', () => {
722743

723744
dlSpy.mockImplementation(async () => '/some/temp/path');
724745
let toolPath = path.normalize('/cache/go/1.13.7/x64');
725-
exSpy.mockImplementation(async () => '/some/other/temp/path');
746+
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
726747
cacheSpy.mockImplementation(async () => toolPath);
727748

728749
await main.run();
@@ -733,7 +754,7 @@ describe('setup-go', () => {
733754
`Failed to resolve version ${versionSpec} from manifest`
734755
);
735756
expect(dlSpy).toHaveBeenCalled();
736-
expect(exSpy).toHaveBeenCalled();
757+
expect(extractTarSpy).toHaveBeenCalled();
737758
expect(logSpy).toHaveBeenCalledWith(
738759
'Attempting to resolve the latest version from the manifest...'
739760
);

dist/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,7 @@ exports.addBinToPath = exports.run = void 0;
20622062
const core = __importStar(__webpack_require__(470));
20632063
const io = __importStar(__webpack_require__(1));
20642064
const installer = __importStar(__webpack_require__(749));
2065+
const semver = __importStar(__webpack_require__(280));
20652066
const path_1 = __importDefault(__webpack_require__(622));
20662067
const child_process_1 = __importDefault(__webpack_require__(129));
20672068
const fs_1 = __importDefault(__webpack_require__(747));
@@ -2082,6 +2083,12 @@ function run() {
20822083
const installDir = yield installer.getGo(versionSpec, checkLatest, auth);
20832084
core.addPath(path_1.default.join(installDir, 'bin'));
20842085
core.info('Added go to the path');
2086+
const version = installer.makeSemver(versionSpec);
2087+
// Go versions less than 1.9 require GOROOT to be set
2088+
if (semver.lt(version, '1.9.0')) {
2089+
core.info("Setting GOROOT for Go version < 1.9");
2090+
core.exportVariable('GOROOT', installDir);
2091+
}
20852092
let added = yield addBinToPath();
20862093
core.debug(`add bin ${added}`);
20872094
core.info(`Successfully setup go version ${versionSpec}`);

src/main.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as core from '@actions/core';
22
import * as io from '@actions/io';
33
import * as installer from './installer';
4+
import * as semver from 'semver';
45
import path from 'path';
56
import cp from 'child_process';
67
import fs from 'fs';
@@ -26,6 +27,13 @@ export async function run() {
2627
core.addPath(path.join(installDir, 'bin'));
2728
core.info('Added go to the path');
2829

30+
const version = installer.makeSemver(versionSpec);
31+
// Go versions less than 1.9 require GOROOT to be set
32+
if (semver.lt(version, '1.9.0')) {
33+
core.info("Setting GOROOT for Go version < 1.9");
34+
core.exportVariable('GOROOT', installDir);
35+
}
36+
2937
let added = await addBinToPath();
3038
core.debug(`add bin ${added}`);
3139
core.info(`Successfully setup go version ${versionSpec}`);

0 commit comments

Comments
 (0)