Merge branch 'main' into reusable-workflow

This commit is contained in:
IvanZosimov 2023-03-08 10:17:58 +01:00
commit 7a77a6aab6
26 changed files with 2315 additions and 204 deletions

6
.eslintignore Normal file
View File

@ -0,0 +1,6 @@
# Ignore list
/*
# Do not ignore these folders:
!__tests__/
!src/

49
.eslintrc.js Normal file
View File

@ -0,0 +1,49 @@
module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:eslint-plugin-jest/recommended',
'eslint-config-prettier'
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'eslint-plugin-jest'],
rules: {
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-ignore': 'allow-with-description'
}
],
'no-console': 'error',
'yoda': 'error',
'prefer-const': [
'error',
{
destructuring: 'all'
}
],
'no-control-regex': 'off',
'no-constant-condition': ['error', {checkLoops: false}]
},
overrides: [
{
files: ['**/*{test,spec}.ts'],
rules: {
'@typescript-eslint/no-unused-vars': 'off',
'jest/no-standalone-expect': 'off',
'jest/no-conditional-expect': 'off',
'no-console': 'off',
}
}
],
env: {
node: true,
es6: true,
'jest/globals': true
}
};

2
.gitattributes vendored
View File

@ -1,2 +1,2 @@
* text=auto * text=auto eol=lf
.licenses/** -diff linguist-generated=true .licenses/** -diff linguist-generated=true

View File

@ -2,9 +2,9 @@ name: CodeQL analysis
on: on:
push: push:
branches: [ main ] branches: [main]
pull_request: pull_request:
branches: [ main ] branches: [main]
schedule: schedule:
- cron: '0 3 * * 0' - cron: '0 3 * * 0'

7
.prettierignore Normal file
View File

@ -0,0 +1,7 @@
# Ignore list
/*
# Do not ignore these folders:
!__tests__/
!.github/
!src/

10
.prettierrc.js Normal file
View File

@ -0,0 +1,10 @@
module.exports = {
printWidth: 80,
tabWidth: 2,
useTabs: false,
semi: true,
singleQuote: true,
trailingComma: 'none',
bracketSpacing: false,
arrowParens: 'avoid'
};

View File

@ -1,11 +0,0 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}

View File

@ -8,14 +8,14 @@ import {PackageManagerInfo} from '../src/package-managers';
describe('restoreCache', () => { describe('restoreCache', () => {
//Arrange //Arrange
let hashFilesSpy = jest.spyOn(glob, 'hashFiles'); const hashFilesSpy = jest.spyOn(glob, 'hashFiles');
let getCacheDirectoryPathSpy = jest.spyOn( const getCacheDirectoryPathSpy = jest.spyOn(
cacheUtils, cacheUtils,
'getCacheDirectoryPath' 'getCacheDirectoryPath'
); );
let restoreCacheSpy = jest.spyOn(cache, 'restoreCache'); const restoreCacheSpy = jest.spyOn(cache, 'restoreCache');
let infoSpy = jest.spyOn(core, 'info'); const infoSpy = jest.spyOn(core, 'info');
let setOutputSpy = jest.spyOn(core, 'setOutput'); const setOutputSpy = jest.spyOn(core, 'setOutput');
const versionSpec = '1.13.1'; const versionSpec = '1.13.1';
const packageManager = 'default'; const packageManager = 'default';
@ -40,13 +40,13 @@ describe('restoreCache', () => {
}); });
//Act + Assert //Act + Assert
expect(async () => { await expect(async () => {
await cacheRestore.restoreCache( await cacheRestore.restoreCache(
versionSpec, versionSpec,
packageManager, packageManager,
cacheDependencyPath cacheDependencyPath
); );
}).rejects.toThrowError( }).rejects.toThrow(
'Some specified paths were not resolved, unable to cache dependencies.' 'Some specified paths were not resolved, unable to cache dependencies.'
); );
}); });
@ -71,7 +71,7 @@ describe('restoreCache', () => {
packageManager, packageManager,
cacheDependencyPath cacheDependencyPath
); );
expect(infoSpy).toBeCalledWith(`Cache is not found`); expect(infoSpy).toHaveBeenCalledWith(`Cache is not found`);
}); });
it('should set output if cache hit is occured', async () => { it('should set output if cache hit is occured', async () => {
@ -94,6 +94,6 @@ describe('restoreCache', () => {
packageManager, packageManager,
cacheDependencyPath cacheDependencyPath
); );
expect(setOutputSpy).toBeCalledWith('cache-hit', true); expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true);
}); });
}); });

View File

@ -6,7 +6,7 @@ import {PackageManagerInfo} from '../src/package-managers';
describe('getCommandOutput', () => { describe('getCommandOutput', () => {
//Arrange //Arrange
let getExecOutputSpy = jest.spyOn(exec, 'getExecOutput'); const getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
it('should return trimmed stdout in case of successful exit code', async () => { it('should return trimmed stdout in case of successful exit code', async () => {
//Arrange //Arrange
@ -36,7 +36,7 @@ describe('getCommandOutput', () => {
}); });
//Act + Assert //Act + Assert
expect(async () => { await expect(async () => {
await cacheUtils.getCommandOutput('command'); await cacheUtils.getCommandOutput('command');
}).rejects.toThrow(); }).rejects.toThrow();
}); });
@ -62,7 +62,7 @@ describe('getPackageManagerInfo', () => {
const packageManagerName = 'invalidName'; const packageManagerName = 'invalidName';
//Act + Assert //Act + Assert
expect(async () => { await expect(async () => {
await cacheUtils.getPackageManagerInfo(packageManagerName); await cacheUtils.getPackageManagerInfo(packageManagerName);
}).rejects.toThrow(); }).rejects.toThrow();
}); });
@ -70,7 +70,7 @@ describe('getPackageManagerInfo', () => {
describe('getCacheDirectoryPath', () => { describe('getCacheDirectoryPath', () => {
//Arrange //Arrange
let getExecOutputSpy = jest.spyOn(exec, 'getExecOutput'); const getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
const validPackageManager: PackageManagerInfo = { const validPackageManager: PackageManagerInfo = {
dependencyFilePattern: 'go.sum', dependencyFilePattern: 'go.sum',
@ -123,7 +123,7 @@ describe('getCacheDirectoryPath', () => {
}); });
//Act + Assert //Act + Assert
expect(async () => { await expect(async () => {
await cacheUtils.getCacheDirectoryPath(validPackageManager); await cacheUtils.getCacheDirectoryPath(validPackageManager);
}).rejects.toThrow(); }).rejects.toThrow();
}); });
@ -136,7 +136,7 @@ describe('getCacheDirectoryPath', () => {
}); });
//Act + Assert //Act + Assert
expect(async () => { await expect(async () => {
await cacheUtils.getCacheDirectoryPath(validPackageManager); await cacheUtils.getCacheDirectoryPath(validPackageManager);
}).rejects.toThrow(); }).rejects.toThrow();
}); });
@ -144,8 +144,8 @@ describe('getCacheDirectoryPath', () => {
describe('isCacheFeatureAvailable', () => { describe('isCacheFeatureAvailable', () => {
//Arrange //Arrange
let isFeatureAvailableSpy = jest.spyOn(cache, 'isFeatureAvailable'); const isFeatureAvailableSpy = jest.spyOn(cache, 'isFeatureAvailable');
let warningSpy = jest.spyOn(core, 'warning'); const warningSpy = jest.spyOn(core, 'warning');
it('should return true when cache feature is available', () => { it('should return true when cache feature is available', () => {
//Arrange //Arrange
@ -153,16 +153,14 @@ describe('isCacheFeatureAvailable', () => {
return true; return true;
}); });
let functionResult;
//Act //Act
functionResult = cacheUtils.isCacheFeatureAvailable(); const functionResult = cacheUtils.isCacheFeatureAvailable();
//Assert //Assert
expect(functionResult).toBeTruthy(); expect(functionResult).toBeTruthy();
}); });
it('should warn when cache feature is unavailable and GHES is not used ', () => { it('should warn when cache feature is unavailable and GHES is not used', () => {
//Arrange //Arrange
isFeatureAvailableSpy.mockImplementation(() => { isFeatureAvailableSpy.mockImplementation(() => {
return false; return false;
@ -170,7 +168,7 @@ describe('isCacheFeatureAvailable', () => {
process.env['GITHUB_SERVER_URL'] = 'https://github.com'; process.env['GITHUB_SERVER_URL'] = 'https://github.com';
let warningMessage = const warningMessage =
'The runner was not able to contact the cache service. Caching will be skipped'; 'The runner was not able to contact the cache service. Caching will be skipped';
//Act //Act
@ -188,10 +186,8 @@ describe('isCacheFeatureAvailable', () => {
process.env['GITHUB_SERVER_URL'] = 'https://github.com'; process.env['GITHUB_SERVER_URL'] = 'https://github.com';
let functionResult;
//Act //Act
functionResult = cacheUtils.isCacheFeatureAvailable(); const functionResult = cacheUtils.isCacheFeatureAvailable();
//Assert //Assert
expect(functionResult).toBeFalsy(); expect(functionResult).toBeFalsy();
@ -205,7 +201,7 @@ describe('isCacheFeatureAvailable', () => {
process.env['GITHUB_SERVER_URL'] = 'https://nongithub.com'; process.env['GITHUB_SERVER_URL'] = 'https://nongithub.com';
let warningMessage = const warningMessage =
'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'; 'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.';
//Act + Assert //Act + Assert

View File

@ -8,13 +8,13 @@ import path from 'path';
import * as main from '../src/main'; import * as main from '../src/main';
import * as im from '../src/installer'; import * as im from '../src/installer';
let goJsonData = require('./data/golang-dl.json'); import goJsonData from './data/golang-dl.json';
let matchers = require('../matchers.json'); import matchers from '../matchers.json';
let goTestManifest = require('./data/versions-manifest.json'); import goTestManifest from './data/versions-manifest.json';
let matcherPattern = matchers.problemMatcher[0].pattern[0]; const matcherPattern = matchers.problemMatcher[0].pattern[0];
let matcherRegExp = new RegExp(matcherPattern.regexp); const matcherRegExp = new RegExp(matcherPattern.regexp);
let win32Join = path.win32.join; const win32Join = path.win32.join;
let posixJoin = path.posix.join; const posixJoin = path.posix.join;
describe('setup-go', () => { describe('setup-go', () => {
let inputs = {} as any; let inputs = {} as any;
@ -133,7 +133,7 @@ describe('setup-go', () => {
os.platform = 'darwin'; os.platform = 'darwin';
os.arch = 'x64'; os.arch = 'x64';
let match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken'); const match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken');
expect(match).toBeDefined(); expect(match).toBeDefined();
expect(match!.resolvedVersion).toBe('1.9.7'); expect(match!.resolvedVersion).toBe('1.9.7');
expect(match!.type).toBe('manifest'); expect(match!.type).toBe('manifest');
@ -146,7 +146,7 @@ describe('setup-go', () => {
os.platform = 'linux'; os.platform = 'linux';
os.arch = 'x64'; os.arch = 'x64';
let match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken'); const match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken');
expect(match).toBeDefined(); expect(match).toBeDefined();
expect(match!.resolvedVersion).toBe('1.9.7'); expect(match!.resolvedVersion).toBe('1.9.7');
expect(match!.type).toBe('manifest'); expect(match!.type).toBe('manifest');
@ -159,7 +159,7 @@ describe('setup-go', () => {
os.platform = 'win32'; os.platform = 'win32';
os.arch = 'x64'; os.arch = 'x64';
let match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken'); const match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken');
expect(match).toBeDefined(); expect(match).toBeDefined();
expect(match!.resolvedVersion).toBe('1.9.7'); expect(match!.resolvedVersion).toBe('1.9.7');
expect(match!.type).toBe('manifest'); expect(match!.type).toBe('manifest');
@ -173,11 +173,11 @@ describe('setup-go', () => {
os.arch = 'x64'; os.arch = 'x64';
// spec: 1.13.0 => 1.13 // spec: 1.13.0 => 1.13
let match: im.IGoVersion | undefined = await im.findMatch('1.13.0'); const match: im.IGoVersion | undefined = await im.findMatch('1.13.0');
expect(match).toBeDefined(); expect(match).toBeDefined();
let version: string = match ? match.version : ''; const version: string = match ? match.version : '';
expect(version).toBe('go1.13'); expect(version).toBe('go1.13');
let fileName = match ? match.files[0].filename : ''; const fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.13.darwin-amd64.tar.gz'); expect(fileName).toBe('go1.13.darwin-amd64.tar.gz');
}); });
@ -186,11 +186,11 @@ describe('setup-go', () => {
os.arch = 'x64'; os.arch = 'x64';
// spec: 1.13 => 1.13.7 (latest) // spec: 1.13 => 1.13.7 (latest)
let match: im.IGoVersion | undefined = await im.findMatch('1.13'); const match: im.IGoVersion | undefined = await im.findMatch('1.13');
expect(match).toBeDefined(); expect(match).toBeDefined();
let version: string = match ? match.version : ''; const version: string = match ? match.version : '';
expect(version).toBe('go1.13.7'); expect(version).toBe('go1.13.7');
let fileName = match ? match.files[0].filename : ''; const fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz'); expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz');
}); });
@ -199,11 +199,11 @@ describe('setup-go', () => {
os.arch = 'x64'; os.arch = 'x64';
// spec: ^1.13.6 => 1.13.7 // spec: ^1.13.6 => 1.13.7
let match: im.IGoVersion | undefined = await im.findMatch('^1.13.6'); const match: im.IGoVersion | undefined = await im.findMatch('^1.13.6');
expect(match).toBeDefined(); expect(match).toBeDefined();
let version: string = match ? match.version : ''; const version: string = match ? match.version : '';
expect(version).toBe('go1.13.7'); expect(version).toBe('go1.13.7');
let fileName = match ? match.files[0].filename : ''; const fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz'); expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz');
}); });
@ -212,11 +212,11 @@ describe('setup-go', () => {
os.arch = 'x32'; os.arch = 'x32';
// spec: 1 => 1.13.7 (latest) // spec: 1 => 1.13.7 (latest)
let match: im.IGoVersion | undefined = await im.findMatch('1'); const match: im.IGoVersion | undefined = await im.findMatch('1');
expect(match).toBeDefined(); expect(match).toBeDefined();
let version: string = match ? match.version : ''; const version: string = match ? match.version : '';
expect(version).toBe('go1.13.7'); expect(version).toBe('go1.13.7');
let fileName = match ? match.files[0].filename : ''; const fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.13.7.windows-386.zip'); expect(fileName).toBe('go1.13.7.windows-386.zip');
}); });
@ -225,11 +225,11 @@ describe('setup-go', () => {
os.arch = 'x64'; os.arch = 'x64';
// spec: 1.14, stable=false => go1.14rc1 // spec: 1.14, stable=false => go1.14rc1
let match: im.IGoVersion | undefined = await im.findMatch('1.14.0-rc.1'); const match: im.IGoVersion | undefined = await im.findMatch('1.14.0-rc.1');
expect(match).toBeDefined(); expect(match).toBeDefined();
let version: string = match ? match.version : ''; const version: string = match ? match.version : '';
expect(version).toBe('go1.14rc1'); expect(version).toBe('go1.14rc1');
let fileName = match ? match.files[0].filename : ''; const fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.14rc1.linux-amd64.tar.gz'); expect(fileName).toBe('go1.14rc1.linux-amd64.tar.gz');
}); });
@ -237,7 +237,7 @@ describe('setup-go', () => {
inputs['go-version'] = '1.13.0'; inputs['go-version'] = '1.13.0';
inputs.stable = 'true'; inputs.stable = 'true';
let toolPath = path.normalize('/cache/go/1.13.0/x64'); const toolPath = path.normalize('/cache/go/1.13.0/x64');
findSpy.mockImplementation(() => toolPath); findSpy.mockImplementation(() => toolPath);
await main.run(); await main.run();
@ -249,7 +249,7 @@ describe('setup-go', () => {
inSpy.mockImplementation(name => inputs[name]); inSpy.mockImplementation(name => inputs[name]);
let toolPath = path.normalize('/cache/go/1.13.0/x64'); const toolPath = path.normalize('/cache/go/1.13.0/x64');
findSpy.mockImplementation(() => toolPath); findSpy.mockImplementation(() => toolPath);
await main.run(); await main.run();
@ -260,10 +260,10 @@ describe('setup-go', () => {
inputs['go-version'] = '1.13.0'; inputs['go-version'] = '1.13.0';
inSpy.mockImplementation(name => inputs[name]); inSpy.mockImplementation(name => inputs[name]);
let toolPath = path.normalize('/cache/go/1.13.0/x64'); const toolPath = path.normalize('/cache/go/1.13.0/x64');
findSpy.mockImplementation(() => toolPath); findSpy.mockImplementation(() => toolPath);
let vars: {[key: string]: string} = {}; const vars: {[key: string]: string} = {};
exportVarSpy.mockImplementation((name: string, val: string) => { exportVarSpy.mockImplementation((name: string, val: string) => {
vars[name] = val; vars[name] = val;
}); });
@ -276,10 +276,10 @@ describe('setup-go', () => {
inputs['go-version'] = '1.8'; inputs['go-version'] = '1.8';
inSpy.mockImplementation(name => inputs[name]); inSpy.mockImplementation(name => inputs[name]);
let toolPath = path.normalize('/cache/go/1.8.0/x64'); const toolPath = path.normalize('/cache/go/1.8.0/x64');
findSpy.mockImplementation(() => toolPath); findSpy.mockImplementation(() => toolPath);
let vars: {[key: string]: string} = {}; const vars: {[key: string]: string} = {};
exportVarSpy.mockImplementation((name: string, val: string) => { exportVarSpy.mockImplementation((name: string, val: string) => {
vars[name] = val; vars[name] = val;
}); });
@ -293,7 +293,7 @@ describe('setup-go', () => {
it('finds a version of go already in the cache', async () => { it('finds a version of go already in the cache', async () => {
inputs['go-version'] = '1.13.0'; inputs['go-version'] = '1.13.0';
let toolPath = path.normalize('/cache/go/1.13.0/x64'); const toolPath = path.normalize('/cache/go/1.13.0/x64');
findSpy.mockImplementation(() => toolPath); findSpy.mockImplementation(() => toolPath);
await main.run(); await main.run();
@ -302,16 +302,16 @@ describe('setup-go', () => {
it('finds a version in the cache and adds it to the path', async () => { it('finds a version in the cache and adds it to the path', async () => {
inputs['go-version'] = '1.13.0'; inputs['go-version'] = '1.13.0';
let toolPath = path.normalize('/cache/go/1.13.0/x64'); const toolPath = path.normalize('/cache/go/1.13.0/x64');
findSpy.mockImplementation(() => toolPath); findSpy.mockImplementation(() => toolPath);
await main.run(); await main.run();
let expPath = path.join(toolPath, 'bin'); const expPath = path.join(toolPath, 'bin');
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
}); });
it('handles unhandled error and reports error', async () => { it('handles unhandled error and reports error', async () => {
let errMsg = 'unhandled error message'; const errMsg = 'unhandled error message';
inputs['go-version'] = '1.13.0'; inputs['go-version'] = '1.13.0';
findSpy.mockImplementation(() => { findSpy.mockImplementation(() => {
@ -329,12 +329,12 @@ describe('setup-go', () => {
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(() => '/some/temp/path'); dlSpy.mockImplementation(() => '/some/temp/path');
let toolPath = path.normalize('/cache/go/1.13.0/x64'); const toolPath = path.normalize('/cache/go/1.13.0/x64');
extractTarSpy.mockImplementation(() => '/some/other/temp/path'); extractTarSpy.mockImplementation(() => '/some/other/temp/path');
cacheSpy.mockImplementation(() => toolPath); cacheSpy.mockImplementation(() => toolPath);
await main.run(); await main.run();
let expPath = path.join(toolPath, 'bin'); const expPath = path.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalled(); expect(dlSpy).toHaveBeenCalled();
expect(extractTarSpy).toHaveBeenCalled(); expect(extractTarSpy).toHaveBeenCalled();
@ -352,12 +352,12 @@ describe('setup-go', () => {
dlSpy.mockImplementation(() => 'C:\\temp\\some\\path'); dlSpy.mockImplementation(() => 'C:\\temp\\some\\path');
extractZipSpy.mockImplementation(() => 'C:\\temp\\some\\other\\path'); extractZipSpy.mockImplementation(() => 'C:\\temp\\some\\other\\path');
let toolPath = path.normalize('C:\\cache\\go\\1.13.0\\x64'); const toolPath = path.normalize('C:\\cache\\go\\1.13.0\\x64');
cacheSpy.mockImplementation(() => toolPath); cacheSpy.mockImplementation(() => toolPath);
await main.run(); await main.run();
let expPath = path.win32.join(toolPath, 'bin'); const expPath = path.win32.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalledWith( expect(dlSpy).toHaveBeenCalledWith(
'https://storage.googleapis.com/golang/go1.13.1.windows-amd64.zip', 'https://storage.googleapis.com/golang/go1.13.1.windows-amd64.zip',
'C:\\temp\\go1.13.1.windows-amd64.zip', 'C:\\temp\\go1.13.1.windows-amd64.zip',
@ -384,25 +384,25 @@ describe('setup-go', () => {
os.platform = 'linux'; os.platform = 'linux';
os.arch = 'x64'; os.arch = 'x64';
let versionSpec = '1.12.16'; const versionSpec = '1.12.16';
inputs['go-version'] = versionSpec; inputs['go-version'] = versionSpec;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
let expectedUrl = const expectedUrl =
'https://github.com/actions/go-versions/releases/download/1.12.16-20200616.20/go-1.12.16-linux-x64.tar.gz'; 'https://github.com/actions/go-versions/releases/download/1.12.16-20200616.20/go-1.12.16-linux-x64.tar.gz';
// ... but not in the local cache // ... but not in the local cache
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path'); dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/go/1.12.16/x64'); const toolPath = path.normalize('/cache/go/1.12.16/x64');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath); cacheSpy.mockImplementation(async () => toolPath);
await main.run(); await main.run();
let expPath = path.join(toolPath, 'bin'); const expPath = path.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalled(); expect(dlSpy).toHaveBeenCalled();
expect(extractTarSpy).toHaveBeenCalled(); expect(extractTarSpy).toHaveBeenCalled();
@ -421,25 +421,25 @@ describe('setup-go', () => {
os.platform = 'linux'; os.platform = 'linux';
os.arch = 'x64'; os.arch = 'x64';
let versionSpec = '1.12'; const versionSpec = '1.12';
inputs['go-version'] = versionSpec; inputs['go-version'] = versionSpec;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
let expectedUrl = const expectedUrl =
'https://github.com/actions/go-versions/releases/download/1.12.17-20200616.21/go-1.12.17-linux-x64.tar.gz'; 'https://github.com/actions/go-versions/releases/download/1.12.17-20200616.21/go-1.12.17-linux-x64.tar.gz';
// ... but not in the local cache // ... but not in the local cache
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path'); dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/go/1.12.17/x64'); const toolPath = path.normalize('/cache/go/1.12.17/x64');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath); cacheSpy.mockImplementation(async () => toolPath);
await main.run(); await main.run();
let expPath = path.join(toolPath, 'bin'); const expPath = path.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalled(); expect(dlSpy).toHaveBeenCalled();
expect(extractTarSpy).toHaveBeenCalled(); expect(extractTarSpy).toHaveBeenCalled();
@ -458,7 +458,7 @@ describe('setup-go', () => {
os.platform = 'linux'; os.platform = 'linux';
os.arch = 'x64'; os.arch = 'x64';
let versionSpec = '1.12.14'; const versionSpec = '1.12.14';
inputs['go-version'] = versionSpec; inputs['go-version'] = versionSpec;
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
@ -467,13 +467,13 @@ describe('setup-go', () => {
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path'); dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/go/1.12.14/x64'); const toolPath = path.normalize('/cache/go/1.12.14/x64');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath); cacheSpy.mockImplementation(async () => toolPath);
await main.run(); await main.run();
let expPath = path.join(toolPath, 'bin'); const expPath = path.join(toolPath, 'bin');
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.12.14'); expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.12.14');
expect(findSpy).toHaveBeenCalled(); expect(findSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.12.14...'); expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.12.14...');
@ -489,7 +489,7 @@ describe('setup-go', () => {
}); });
it('reports a failed download', async () => { it('reports a failed download', async () => {
let errMsg = 'unhandled download message'; const errMsg = 'unhandled download message';
os.platform = 'linux'; os.platform = 'linux';
os.arch = 'x64'; os.arch = 'x64';
@ -510,7 +510,7 @@ describe('setup-go', () => {
whichSpy.mockImplementation(async () => { whichSpy.mockImplementation(async () => {
return ''; return '';
}); });
let added = await main.addBinToPath(); const added = await main.addBinToPath();
expect(added).toBeFalsy(); expect(added).toBeFalsy();
}); });
@ -528,8 +528,8 @@ describe('setup-go', () => {
return false; return false;
}); });
let added = await main.addBinToPath(); const added = await main.addBinToPath();
expect(added).toBeTruthy; expect(added).toBeTruthy();
}); });
interface Annotation { interface Annotation {
@ -543,9 +543,9 @@ describe('setup-go', () => {
// problem matcher regex pattern tests // problem matcher regex pattern tests
function testMatch(line: string): Annotation { function testMatch(line: string): Annotation {
let annotation = <Annotation>{}; const annotation = <Annotation>{};
let match = matcherRegExp.exec(line); const match = matcherRegExp.exec(line);
if (match) { if (match) {
annotation.line = parseInt(match[matcherPattern.line], 10); annotation.line = parseInt(match[matcherPattern.line], 10);
annotation.column = parseInt(match[matcherPattern.column], 10); annotation.column = parseInt(match[matcherPattern.column], 10);
@ -557,8 +557,8 @@ describe('setup-go', () => {
} }
it('matches on relative unix path', async () => { it('matches on relative unix path', async () => {
let line = './main.go:13:2: undefined: fmt.Printl'; const line = './main.go:13:2: undefined: fmt.Printl';
let annotation = testMatch(line); const annotation = testMatch(line);
expect(annotation).toBeDefined(); expect(annotation).toBeDefined();
expect(annotation.line).toBe(13); expect(annotation.line).toBe(13);
expect(annotation.column).toBe(2); expect(annotation.column).toBe(2);
@ -567,8 +567,8 @@ describe('setup-go', () => {
}); });
it('matches on unix path up the tree', async () => { it('matches on unix path up the tree', async () => {
let line = '../main.go:13:2: undefined: fmt.Printl'; const line = '../main.go:13:2: undefined: fmt.Printl';
let annotation = testMatch(line); const annotation = testMatch(line);
expect(annotation).toBeDefined(); expect(annotation).toBeDefined();
expect(annotation.line).toBe(13); expect(annotation.line).toBe(13);
expect(annotation.column).toBe(2); expect(annotation.column).toBe(2);
@ -577,8 +577,8 @@ describe('setup-go', () => {
}); });
it('matches on unix path down the tree', async () => { it('matches on unix path down the tree', async () => {
let line = 'foo/main.go:13:2: undefined: fmt.Printl'; const line = 'foo/main.go:13:2: undefined: fmt.Printl';
let annotation = testMatch(line); const annotation = testMatch(line);
expect(annotation).toBeDefined(); expect(annotation).toBeDefined();
expect(annotation.line).toBe(13); expect(annotation.line).toBe(13);
expect(annotation.column).toBe(2); expect(annotation.column).toBe(2);
@ -587,8 +587,8 @@ describe('setup-go', () => {
}); });
it('matches on rooted unix path', async () => { it('matches on rooted unix path', async () => {
let line = '/assert.go:4:1: missing return at end of function'; const line = '/assert.go:4:1: missing return at end of function';
let annotation = testMatch(line); const annotation = testMatch(line);
expect(annotation).toBeDefined(); expect(annotation).toBeDefined();
expect(annotation.line).toBe(4); expect(annotation.line).toBe(4);
expect(annotation.column).toBe(1); expect(annotation.column).toBe(1);
@ -597,8 +597,8 @@ describe('setup-go', () => {
}); });
it('matches on unix path with spaces', async () => { it('matches on unix path with spaces', async () => {
let line = ' ./assert.go:5:2: missing return at end of function '; const line = ' ./assert.go:5:2: missing return at end of function ';
let annotation = testMatch(line); const annotation = testMatch(line);
expect(annotation).toBeDefined(); expect(annotation).toBeDefined();
expect(annotation.line).toBe(5); expect(annotation.line).toBe(5);
expect(annotation.column).toBe(2); expect(annotation.column).toBe(2);
@ -607,8 +607,8 @@ describe('setup-go', () => {
}); });
it('matches on unix path with tabs', async () => { it('matches on unix path with tabs', async () => {
let line = '\t./assert.go:5:2: missing return at end of function '; const line = '\t./assert.go:5:2: missing return at end of function ';
let annotation = testMatch(line); const annotation = testMatch(line);
expect(annotation).toBeDefined(); expect(annotation).toBeDefined();
expect(annotation.line).toBe(5); expect(annotation.line).toBe(5);
expect(annotation.column).toBe(2); expect(annotation.column).toBe(2);
@ -617,8 +617,8 @@ describe('setup-go', () => {
}); });
it('matches on relative windows path', async () => { it('matches on relative windows path', async () => {
let line = '.\\main.go:13:2: undefined: fmt.Printl'; const line = '.\\main.go:13:2: undefined: fmt.Printl';
let annotation = testMatch(line); const annotation = testMatch(line);
expect(annotation).toBeDefined(); expect(annotation).toBeDefined();
expect(annotation.line).toBe(13); expect(annotation.line).toBe(13);
expect(annotation.column).toBe(2); expect(annotation.column).toBe(2);
@ -627,8 +627,8 @@ describe('setup-go', () => {
}); });
it('matches on windows path up the tree', async () => { it('matches on windows path up the tree', async () => {
let line = '..\\main.go:13:2: undefined: fmt.Printl'; const line = '..\\main.go:13:2: undefined: fmt.Printl';
let annotation = testMatch(line); const annotation = testMatch(line);
expect(annotation).toBeDefined(); expect(annotation).toBeDefined();
expect(annotation.line).toBe(13); expect(annotation.line).toBe(13);
expect(annotation.column).toBe(2); expect(annotation.column).toBe(2);
@ -730,7 +730,7 @@ describe('setup-go', () => {
os.platform = 'linux'; os.platform = 'linux';
os.arch = 'x64'; os.arch = 'x64';
let versionSpec = '1.13'; const versionSpec = '1.13';
inputs['go-version'] = versionSpec; inputs['go-version'] = versionSpec;
inputs['check-latest'] = true; inputs['check-latest'] = true;
@ -741,13 +741,13 @@ describe('setup-go', () => {
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path'); dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/go/1.13.7/x64'); const toolPath = path.normalize('/cache/go/1.13.7/x64');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath); cacheSpy.mockImplementation(async () => toolPath);
await main.run(); await main.run();
let expPath = path.join(toolPath, 'bin'); const expPath = path.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalled(); expect(dlSpy).toHaveBeenCalled();
expect(extractTarSpy).toHaveBeenCalled(); expect(extractTarSpy).toHaveBeenCalled();
@ -767,7 +767,7 @@ describe('setup-go', () => {
os.platform = 'linux'; os.platform = 'linux';
os.arch = 'x64'; os.arch = 'x64';
let versionSpec = '1.13'; const versionSpec = '1.13';
process.env['GITHUB_PATH'] = ''; process.env['GITHUB_PATH'] = '';
@ -784,13 +784,13 @@ describe('setup-go', () => {
getAllVersionsSpy.mockImplementationOnce(() => undefined); getAllVersionsSpy.mockImplementationOnce(() => undefined);
dlSpy.mockImplementation(async () => '/some/temp/path'); dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/go/1.13.7/x64'); const toolPath = path.normalize('/cache/go/1.13.7/x64');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath); cacheSpy.mockImplementation(async () => toolPath);
await main.run(); await main.run();
let expPath = path.join(toolPath, 'bin'); const expPath = path.join(toolPath, 'bin');
expect(logSpy).toHaveBeenCalledWith( expect(logSpy).toHaveBeenCalledWith(
`Failed to resolve version ${versionSpec} from manifest` `Failed to resolve version ${versionSpec} from manifest`
@ -910,7 +910,7 @@ use .
inputs['go-version'] = version; inputs['go-version'] = version;
inputs['architecture'] = arch; inputs['architecture'] = arch;
let expectedUrl = const expectedUrl =
platform === 'win32' platform === 'win32'
? `https://github.com/actions/go-versions/releases/download/${version}/go-${version}-${platform}-${arch}.${fileExtension}` ? `https://github.com/actions/go-versions/releases/download/${version}/go-${version}-${platform}-${arch}.${fileExtension}`
: `https://storage.googleapis.com/golang/go${version}.${osSpec}-${arch}.${fileExtension}`; : `https://storage.googleapis.com/golang/go${version}.${osSpec}-${arch}.${fileExtension}`;
@ -919,7 +919,7 @@ use .
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path'); dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize(`/cache/go/${version}/${arch}`); const toolPath = path.normalize(`/cache/go/${version}/${arch}`);
cacheSpy.mockImplementation(async () => toolPath); cacheSpy.mockImplementation(async () => toolPath);
await main.run(); await main.run();
@ -944,7 +944,7 @@ use .
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path'); dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize(`/cache/go/${alias}/${arch}`); const toolPath = path.normalize(`/cache/go/${alias}/${arch}`);
cacheSpy.mockImplementation(async () => toolPath); cacheSpy.mockImplementation(async () => toolPath);
await main.run(); await main.run();

View File

@ -60457,7 +60457,7 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
}); });
exports.getPackageManagerInfo = getPackageManagerInfo; exports.getPackageManagerInfo = getPackageManagerInfo;
const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () { const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
const pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command))); const pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map((command) => __awaiter(void 0, void 0, void 0, function* () { return exports.getCommandOutput(command); })));
const cachePaths = pathList.filter(item => item); const cachePaths = pathList.filter(item => item);
if (!cachePaths.length) { if (!cachePaths.length) {
throw new Error(`Could not get cache folder paths.`); throw new Error(`Could not get cache folder paths.`);

55
dist/setup/index.js vendored
View File

@ -63058,7 +63058,7 @@ const restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __awa
}); });
exports.restoreCache = restoreCache; exports.restoreCache = restoreCache;
const findDependencyFile = (packageManager) => { const findDependencyFile = (packageManager) => {
let dependencyFile = packageManager.dependencyFilePattern; const dependencyFile = packageManager.dependencyFilePattern;
const workspace = process.env.GITHUB_WORKSPACE; const workspace = process.env.GITHUB_WORKSPACE;
const rootContent = fs_1.default.readdirSync(workspace); const rootContent = fs_1.default.readdirSync(workspace);
const goSumFileExists = rootContent.includes(dependencyFile); const goSumFileExists = rootContent.includes(dependencyFile);
@ -63130,7 +63130,7 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
}); });
exports.getPackageManagerInfo = getPackageManagerInfo; exports.getPackageManagerInfo = getPackageManagerInfo;
const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () { const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
const pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command))); const pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map((command) => __awaiter(void 0, void 0, void 0, function* () { return exports.getCommandOutput(command); })));
const cachePaths = pathList.filter(item => item); const cachePaths = pathList.filter(item => item);
if (!cachePaths.length) { if (!cachePaths.length) {
throw new Error(`Could not get cache folder paths.`); throw new Error(`Could not get cache folder paths.`);
@ -63229,7 +63229,7 @@ const utils_1 = __nccwpck_require__(1314);
function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch()) { function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch()) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let manifest; let manifest;
let osPlat = os_1.default.platform(); const osPlat = os_1.default.platform();
if (versionSpec === utils_1.StableReleaseAlias.Stable || if (versionSpec === utils_1.StableReleaseAlias.Stable ||
versionSpec === utils_1.StableReleaseAlias.OldStable) { versionSpec === utils_1.StableReleaseAlias.OldStable) {
manifest = yield getManifest(auth); manifest = yield getManifest(auth);
@ -63255,8 +63255,7 @@ function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch()) {
} }
} }
// check cache // check cache
let toolPath; const toolPath = tc.find('go', versionSpec, arch);
toolPath = tc.find('go', versionSpec, arch);
// If not found in cache, download // If not found in cache, download
if (toolPath) { if (toolPath) {
core.info(`Found in cache @ ${toolPath}`); core.info(`Found in cache @ ${toolPath}`);
@ -63382,12 +63381,11 @@ function getInfoFromManifest(versionSpec, stable, auth, arch = os_1.default.arch
exports.getInfoFromManifest = getInfoFromManifest; exports.getInfoFromManifest = getInfoFromManifest;
function getInfoFromDist(versionSpec, arch) { function getInfoFromDist(versionSpec, arch) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let version; const version = yield findMatch(versionSpec, arch);
version = yield findMatch(versionSpec, arch);
if (!version) { if (!version) {
return null; return null;
} }
let downloadUrl = `https://storage.googleapis.com/golang/${version.files[0].filename}`; const downloadUrl = `https://storage.googleapis.com/golang/${version.files[0].filename}`;
return { return {
type: 'dist', type: 'dist',
downloadUrl: downloadUrl, downloadUrl: downloadUrl,
@ -63409,8 +63407,8 @@ function findMatch(versionSpec, arch = os_1.default.arch()) {
} }
let goFile; let goFile;
for (let i = 0; i < candidates.length; i++) { for (let i = 0; i < candidates.length; i++) {
let candidate = candidates[i]; const candidate = candidates[i];
let version = makeSemver(candidate.version); const version = makeSemver(candidate.version);
core.debug(`check ${version} satisfies ${versionSpec}`); core.debug(`check ${version} satisfies ${versionSpec}`);
if (semver.satisfies(version, versionSpec)) { if (semver.satisfies(version, versionSpec)) {
goFile = candidate.files.find(file => { goFile = candidate.files.find(file => {
@ -63454,8 +63452,8 @@ function makeSemver(version) {
var _a; var _a;
version = version.replace('go', ''); version = version.replace('go', '');
version = version.replace('beta', '-beta.').replace('rc', '-rc.'); version = version.replace('beta', '-beta.').replace('rc', '-rc.');
let parts = version.split('-'); const parts = version.split('-');
let semVersion = (_a = semver.coerce(parts[0])) === null || _a === void 0 ? void 0 : _a.version; const semVersion = (_a = semver.coerce(parts[0])) === null || _a === void 0 ? void 0 : _a.version;
if (!semVersion) { if (!semVersion) {
throw new Error(`The version: ${version} can't be changed to SemVer notation`); throw new Error(`The version: ${version} can't be changed to SemVer notation`);
} }
@ -63481,8 +63479,8 @@ function parseGoVersionFile(versionFilePath) {
exports.parseGoVersionFile = parseGoVersionFile; exports.parseGoVersionFile = parseGoVersionFile;
function resolveStableVersionDist(versionSpec, arch) { function resolveStableVersionDist(versionSpec, arch) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let archFilter = sys.getArch(arch); const archFilter = sys.getArch(arch);
let platFilter = sys.getPlatform(); const platFilter = sys.getPlatform();
const dlUrl = 'https://golang.org/dl/?mode=json&include=all'; const dlUrl = 'https://golang.org/dl/?mode=json&include=all';
const candidates = yield module.exports.getVersionsDist(dlUrl); const candidates = yield module.exports.getVersionsDist(dlUrl);
if (!candidates) { if (!candidates) {
@ -63585,8 +63583,8 @@ function run() {
arch = os_1.default.arch(); arch = os_1.default.arch();
} }
if (versionSpec) { if (versionSpec) {
let token = core.getInput('token'); const token = core.getInput('token');
let auth = !token ? undefined : `token ${token}`; const auth = !token ? undefined : `token ${token}`;
const checkLatest = core.getBooleanInput('check-latest'); const checkLatest = core.getBooleanInput('check-latest');
const installDir = yield installer.getGo(versionSpec, checkLatest, auth, arch); const installDir = yield installer.getGo(versionSpec, checkLatest, auth, arch);
const installDirVersion = path_1.default.basename(path_1.default.dirname(installDir)); const installDirVersion = path_1.default.basename(path_1.default.dirname(installDir));
@ -63598,12 +63596,12 @@ function run() {
core.info('Setting GOROOT for Go version < 1.9'); core.info('Setting GOROOT for Go version < 1.9');
core.exportVariable('GOROOT', installDir); core.exportVariable('GOROOT', installDir);
} }
let added = yield addBinToPath(); const added = yield addBinToPath();
core.debug(`add bin ${added}`); core.debug(`add bin ${added}`);
core.info(`Successfully set up Go version ${versionSpec}`); core.info(`Successfully set up Go version ${versionSpec}`);
} }
let goPath = yield io.which('go'); const goPath = yield io.which('go');
let goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString(); const goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString();
if (cache && cache_utils_1.isCacheFeatureAvailable()) { if (cache && cache_utils_1.isCacheFeatureAvailable()) {
const packageManager = 'default'; const packageManager = 'default';
const cacheDependencyPath = core.getInput('cache-dependency-path'); const cacheDependencyPath = core.getInput('cache-dependency-path');
@ -63616,7 +63614,7 @@ function run() {
core.info(goVersion); core.info(goVersion);
core.setOutput('go-version', parseGoVersion(goVersion)); core.setOutput('go-version', parseGoVersion(goVersion));
core.startGroup('go env'); core.startGroup('go env');
let goEnv = (child_process_1.default.execSync(`${goPath} env`) || '').toString(); const goEnv = (child_process_1.default.execSync(`${goPath} env`) || '').toString();
core.info(goEnv); core.info(goEnv);
core.endGroup(); core.endGroup();
} }
@ -63629,22 +63627,22 @@ exports.run = run;
function addBinToPath() { function addBinToPath() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let added = false; let added = false;
let g = yield io.which('go'); const g = yield io.which('go');
core.debug(`which go :${g}:`); core.debug(`which go :${g}:`);
if (!g) { if (!g) {
core.debug('go not in the path'); core.debug('go not in the path');
return added; return added;
} }
let buf = child_process_1.default.execSync('go env GOPATH'); const buf = child_process_1.default.execSync('go env GOPATH');
if (buf.length > 1) { if (buf.length > 1) {
let gp = buf.toString().trim(); const gp = buf.toString().trim();
core.debug(`go env GOPATH :${gp}:`); core.debug(`go env GOPATH :${gp}:`);
if (!fs_1.default.existsSync(gp)) { if (!fs_1.default.existsSync(gp)) {
// some of the hosted images have go install but not profile dir // some of the hosted images have go install but not profile dir
core.debug(`creating ${gp}`); core.debug(`creating ${gp}`);
yield io.mkdirP(gp); yield io.mkdirP(gp);
} }
let bp = path_1.default.join(gp, 'bin'); const bp = path_1.default.join(gp, 'bin');
if (!fs_1.default.existsSync(bp)) { if (!fs_1.default.existsSync(bp)) {
core.debug(`creating ${bp}`); core.debug(`creating ${bp}`);
yield io.mkdirP(bp); yield io.mkdirP(bp);
@ -63703,18 +63701,21 @@ exports.supportedPackageManagers = {
/***/ }), /***/ }),
/***/ 4300: /***/ 4300:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict"; "use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getArch = exports.getPlatform = void 0; exports.getArch = exports.getPlatform = void 0;
const os = __nccwpck_require__(2037); const os_1 = __importDefault(__nccwpck_require__(2037));
function getPlatform() { function getPlatform() {
// darwin and linux match already // darwin and linux match already
// freebsd not supported yet but future proofed. // freebsd not supported yet but future proofed.
// 'aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', and 'win32' // 'aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', and 'win32'
let plat = os.platform(); let plat = os_1.default.platform();
// wants 'darwin', 'freebsd', 'linux', 'windows' // wants 'darwin', 'freebsd', 'linux', 'windows'
if (plat === 'win32') { if (plat === 'win32') {
plat = 'windows'; plat = 'windows';

View File

@ -52,7 +52,7 @@ Pull requests are the easiest way to contribute changes to git repos at GitHub.
- Please check that no one else has already created a pull request with these changes - Please check that no one else has already created a pull request with these changes
- Use a "feature branch" for your changes. That separates the changes in the pull request from your other changes and makes it easy to edit/amend commits in the pull request - Use a "feature branch" for your changes. That separates the changes in the pull request from your other changes and makes it easy to edit/amend commits in the pull request
- **Run `pre-checkin` script to format, build and test changes** - **Run `pre-checkin` script to format, lint, build and test changes**
- Make sure your changes are well formatted and that all tests are passing - Make sure your changes are well formatted and that all tests are passing
- If your pull request is connected to an open issue, please, leave a link to this issue in the `Related issue:` section - If your pull request is connected to an open issue, please, leave a link to this issue in the `Related issue:` section
- If you later need to add new commits to the pull request, you can simply commit the changes to the local branch and then push them. The pull request gets automatically updated - If you later need to add new commits to the pull request, you can simply commit the changes to the local branch and then push them. The pull request gets automatically updated
@ -61,6 +61,7 @@ Pull requests are the easiest way to contribute changes to git repos at GitHub.
- To implement new features or fix bugs, you need to make changes to the `.ts` files, which are located in the `src` folder - To implement new features or fix bugs, you need to make changes to the `.ts` files, which are located in the `src` folder
- To comply with the code style, **you need to run the `format` script** - To comply with the code style, **you need to run the `format` script**
- To lint the code, **you need to run the `lint:fix` script**
- To transpile source code to `javascript` we use [NCC](https://github.com/vercel/ncc). **It is very important to run the `build` script after making changes**, otherwise your changes will not get into the final `javascript` build - To transpile source code to `javascript` we use [NCC](https://github.com/vercel/ncc). **It is very important to run the `build` script after making changes**, otherwise your changes will not get into the final `javascript` build
- You can also start formatting, building code, and testing with a single `pre-checkin` command - You can also start formatting, building code, and testing with a single `pre-checkin` command

2075
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,11 +6,12 @@
"main": "lib/setup-go.js", "main": "lib/setup-go.js",
"scripts": { "scripts": {
"build": "tsc && ncc build -o dist/setup src/setup-go.ts && ncc build -o dist/cache-save src/cache-save.ts", "build": "tsc && ncc build -o dist/setup src/setup-go.ts && ncc build -o dist/cache-save src/cache-save.ts",
"format": "prettier --write **/*.ts", "format": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --write **/*.{ts,yml,yaml}",
"format-check": "prettier --check **/*.ts", "format-check": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --check **/*.{ts,yml,yaml}",
"lint": "echo \"Fake command that does nothing. It is used in reusable workflows\"", "lint": "eslint --config ./.eslintrc.js **/*.ts",
"lint:fix": "eslint --config ./.eslintrc.js **/*.ts --fix",
"test": "jest --coverage", "test": "jest --coverage",
"pre-checkin": "npm run format && npm run build && npm test" "pre-checkin": "npm run format && npm run lint:fix && npm run build && npm test"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -37,11 +38,16 @@
"@types/jest": "^27.0.2", "@types/jest": "^27.0.2",
"@types/node": "^16.11.25", "@types/node": "^16.11.25",
"@types/semver": "^6.0.0", "@types/semver": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
"@vercel/ncc": "^0.33.4", "@vercel/ncc": "^0.33.4",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-jest": "^27.2.1",
"jest": "^27.2.5", "jest": "^27.2.5",
"jest-circus": "^27.2.5", "jest-circus": "^27.2.5",
"nock": "^10.0.6", "nock": "^10.0.6",
"prettier": "^1.17.1", "prettier": "^2.8.4",
"ts-jest": "^27.0.5", "ts-jest": "^27.0.5",
"typescript": "^4.3.3" "typescript": "^4.3.3"
} }

View File

@ -48,7 +48,7 @@ export const restoreCache = async (
}; };
const findDependencyFile = (packageManager: PackageManagerInfo) => { const findDependencyFile = (packageManager: PackageManagerInfo) => {
let dependencyFile = packageManager.dependencyFilePattern; const dependencyFile = packageManager.dependencyFilePattern;
const workspace = process.env.GITHUB_WORKSPACE!; const workspace = process.env.GITHUB_WORKSPACE!;
const rootContent = fs.readdirSync(workspace); const rootContent = fs.readdirSync(workspace);

View File

@ -35,7 +35,7 @@ export const getCacheDirectoryPath = async (
packageManagerInfo: PackageManagerInfo packageManagerInfo: PackageManagerInfo
) => { ) => {
const pathList = await Promise.all( const pathList = await Promise.all(
packageManagerInfo.cacheFolderCommandList.map(command => packageManagerInfo.cacheFolderCommandList.map(async command =>
getCommandOutput(command) getCommandOutput(command)
) )
); );

View File

@ -37,7 +37,7 @@ export async function getGo(
arch = os.arch() arch = os.arch()
) { ) {
let manifest: tc.IToolRelease[] | undefined; let manifest: tc.IToolRelease[] | undefined;
let osPlat: string = os.platform(); const osPlat: string = os.platform();
if ( if (
versionSpec === StableReleaseAlias.Stable || versionSpec === StableReleaseAlias.Stable ||
@ -83,8 +83,7 @@ export async function getGo(
} }
// check cache // check cache
let toolPath: string; const toolPath = tc.find('go', versionSpec, arch);
toolPath = tc.find('go', versionSpec, arch);
// If not found in cache, download // If not found in cache, download
if (toolPath) { if (toolPath) {
core.info(`Found in cache @ ${toolPath}`); core.info(`Found in cache @ ${toolPath}`);
@ -246,13 +245,12 @@ async function getInfoFromDist(
versionSpec: string, versionSpec: string,
arch: string arch: string
): Promise<IGoVersionInfo | null> { ): Promise<IGoVersionInfo | null> {
let version: IGoVersion | undefined; const version: IGoVersion | undefined = await findMatch(versionSpec, arch);
version = await findMatch(versionSpec, arch);
if (!version) { if (!version) {
return null; return null;
} }
let downloadUrl: string = `https://storage.googleapis.com/golang/${version.files[0].filename}`; const downloadUrl = `https://storage.googleapis.com/golang/${version.files[0].filename}`;
return <IGoVersionInfo>{ return <IGoVersionInfo>{
type: 'dist', type: 'dist',
@ -282,8 +280,8 @@ export async function findMatch(
let goFile: IGoVersionFile | undefined; let goFile: IGoVersionFile | undefined;
for (let i = 0; i < candidates.length; i++) { for (let i = 0; i < candidates.length; i++) {
let candidate: IGoVersion = candidates[i]; const candidate: IGoVersion = candidates[i];
let version = makeSemver(candidate.version); const version = makeSemver(candidate.version);
core.debug(`check ${version} satisfies ${versionSpec}`); core.debug(`check ${version} satisfies ${versionSpec}`);
if (semver.satisfies(version, versionSpec)) { if (semver.satisfies(version, versionSpec)) {
@ -331,9 +329,9 @@ export async function getVersionsDist(
export function makeSemver(version: string): string { export function makeSemver(version: string): string {
version = version.replace('go', ''); version = version.replace('go', '');
version = version.replace('beta', '-beta.').replace('rc', '-rc.'); version = version.replace('beta', '-beta.').replace('rc', '-rc.');
let parts = version.split('-'); const parts = version.split('-');
let semVersion = semver.coerce(parts[0])?.version; const semVersion = semver.coerce(parts[0])?.version;
if (!semVersion) { if (!semVersion) {
throw new Error( throw new Error(
`The version: ${version} can't be changed to SemVer notation` `The version: ${version} can't be changed to SemVer notation`
@ -369,9 +367,9 @@ export function parseGoVersionFile(versionFilePath: string): string {
} }
async function resolveStableVersionDist(versionSpec: string, arch: string) { async function resolveStableVersionDist(versionSpec: string, arch: string) {
let archFilter = sys.getArch(arch); const archFilter = sys.getArch(arch);
let platFilter = sys.getPlatform(); const platFilter = sys.getPlatform();
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all'; const dlUrl = 'https://golang.org/dl/?mode=json&include=all';
const candidates: IGoVersion[] | null = await module.exports.getVersionsDist( const candidates: IGoVersion[] | null = await module.exports.getVersionsDist(
dlUrl dlUrl
); );

View File

@ -27,8 +27,8 @@ export async function run() {
} }
if (versionSpec) { if (versionSpec) {
let token = core.getInput('token'); const token = core.getInput('token');
let auth = !token ? undefined : `token ${token}`; const auth = !token ? undefined : `token ${token}`;
const checkLatest = core.getBooleanInput('check-latest'); const checkLatest = core.getBooleanInput('check-latest');
@ -51,13 +51,13 @@ export async function run() {
core.exportVariable('GOROOT', installDir); core.exportVariable('GOROOT', installDir);
} }
let added = await addBinToPath(); const added = await addBinToPath();
core.debug(`add bin ${added}`); core.debug(`add bin ${added}`);
core.info(`Successfully set up Go version ${versionSpec}`); core.info(`Successfully set up Go version ${versionSpec}`);
} }
let goPath = await io.which('go'); const goPath = await io.which('go');
let goVersion = (cp.execSync(`${goPath} version`) || '').toString(); const goVersion = (cp.execSync(`${goPath} version`) || '').toString();
if (cache && isCacheFeatureAvailable()) { if (cache && isCacheFeatureAvailable()) {
const packageManager = 'default'; const packageManager = 'default';
@ -79,7 +79,7 @@ export async function run() {
core.setOutput('go-version', parseGoVersion(goVersion)); core.setOutput('go-version', parseGoVersion(goVersion));
core.startGroup('go env'); core.startGroup('go env');
let goEnv = (cp.execSync(`${goPath} env`) || '').toString(); const goEnv = (cp.execSync(`${goPath} env`) || '').toString();
core.info(goEnv); core.info(goEnv);
core.endGroup(); core.endGroup();
} catch (error) { } catch (error) {
@ -89,16 +89,16 @@ export async function run() {
export async function addBinToPath(): Promise<boolean> { export async function addBinToPath(): Promise<boolean> {
let added = false; let added = false;
let g = await io.which('go'); const g = await io.which('go');
core.debug(`which go :${g}:`); core.debug(`which go :${g}:`);
if (!g) { if (!g) {
core.debug('go not in the path'); core.debug('go not in the path');
return added; return added;
} }
let buf = cp.execSync('go env GOPATH'); const buf = cp.execSync('go env GOPATH');
if (buf.length > 1) { if (buf.length > 1) {
let gp = buf.toString().trim(); const gp = buf.toString().trim();
core.debug(`go env GOPATH :${gp}:`); core.debug(`go env GOPATH :${gp}:`);
if (!fs.existsSync(gp)) { if (!fs.existsSync(gp)) {
// some of the hosted images have go install but not profile dir // some of the hosted images have go install but not profile dir
@ -106,7 +106,7 @@ export async function addBinToPath(): Promise<boolean> {
await io.mkdirP(gp); await io.mkdirP(gp);
} }
let bp = path.join(gp, 'bin'); const bp = path.join(gp, 'bin');
if (!fs.existsSync(bp)) { if (!fs.existsSync(bp)) {
core.debug(`creating ${bp}`); core.debug(`creating ${bp}`);
await io.mkdirP(bp); await io.mkdirP(bp);

View File

@ -1,4 +1,4 @@
const os = require('os'); import os from 'os';
export function getPlatform(): string { export function getPlatform(): string {
// darwin and linux match already // darwin and linux match already

View File

@ -46,6 +46,7 @@
// "types": [], /* Type declaration files to be included in compilation. */ // "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"resolveJsonModule": true, /* Allows importing modules with a '.json' extension, which is a common practice in node projects. */
"sourceMap": true, "sourceMap": true,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */