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

View file

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

View file

@ -52,8 +52,8 @@ jobs:
version: [stable, oldstable]
architecture: [x64, x32]
exclude:
- os: macos-latest
architecture: x32
- os: macos-latest
architecture: x32
steps:
- uses: actions/checkout@v3
- name: Setup Go ${{ matrix.version }} ${{ matrix.architecture }}

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', () => {
//Arrange
let hashFilesSpy = jest.spyOn(glob, 'hashFiles');
let getCacheDirectoryPathSpy = jest.spyOn(
const hashFilesSpy = jest.spyOn(glob, 'hashFiles');
const getCacheDirectoryPathSpy = jest.spyOn(
cacheUtils,
'getCacheDirectoryPath'
);
let restoreCacheSpy = jest.spyOn(cache, 'restoreCache');
let infoSpy = jest.spyOn(core, 'info');
let setOutputSpy = jest.spyOn(core, 'setOutput');
const restoreCacheSpy = jest.spyOn(cache, 'restoreCache');
const infoSpy = jest.spyOn(core, 'info');
const setOutputSpy = jest.spyOn(core, 'setOutput');
const versionSpec = '1.13.1';
const packageManager = 'default';
@ -40,13 +40,13 @@ describe('restoreCache', () => {
});
//Act + Assert
expect(async () => {
await expect(async () => {
await cacheRestore.restoreCache(
versionSpec,
packageManager,
cacheDependencyPath
);
}).rejects.toThrowError(
}).rejects.toThrow(
'Some specified paths were not resolved, unable to cache dependencies.'
);
});
@ -71,7 +71,7 @@ describe('restoreCache', () => {
packageManager,
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 () => {
@ -94,6 +94,6 @@ describe('restoreCache', () => {
packageManager,
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', () => {
//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 () => {
//Arrange
@ -36,7 +36,7 @@ describe('getCommandOutput', () => {
});
//Act + Assert
expect(async () => {
await expect(async () => {
await cacheUtils.getCommandOutput('command');
}).rejects.toThrow();
});
@ -62,7 +62,7 @@ describe('getPackageManagerInfo', () => {
const packageManagerName = 'invalidName';
//Act + Assert
expect(async () => {
await expect(async () => {
await cacheUtils.getPackageManagerInfo(packageManagerName);
}).rejects.toThrow();
});
@ -70,7 +70,7 @@ describe('getPackageManagerInfo', () => {
describe('getCacheDirectoryPath', () => {
//Arrange
let getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
const getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
const validPackageManager: PackageManagerInfo = {
dependencyFilePattern: 'go.sum',
@ -123,7 +123,7 @@ describe('getCacheDirectoryPath', () => {
});
//Act + Assert
expect(async () => {
await expect(async () => {
await cacheUtils.getCacheDirectoryPath(validPackageManager);
}).rejects.toThrow();
});
@ -136,7 +136,7 @@ describe('getCacheDirectoryPath', () => {
});
//Act + Assert
expect(async () => {
await expect(async () => {
await cacheUtils.getCacheDirectoryPath(validPackageManager);
}).rejects.toThrow();
});
@ -144,8 +144,8 @@ describe('getCacheDirectoryPath', () => {
describe('isCacheFeatureAvailable', () => {
//Arrange
let isFeatureAvailableSpy = jest.spyOn(cache, 'isFeatureAvailable');
let warningSpy = jest.spyOn(core, 'warning');
const isFeatureAvailableSpy = jest.spyOn(cache, 'isFeatureAvailable');
const warningSpy = jest.spyOn(core, 'warning');
it('should return true when cache feature is available', () => {
//Arrange
@ -153,16 +153,14 @@ describe('isCacheFeatureAvailable', () => {
return true;
});
let functionResult;
//Act
functionResult = cacheUtils.isCacheFeatureAvailable();
const functionResult = cacheUtils.isCacheFeatureAvailable();
//Assert
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
isFeatureAvailableSpy.mockImplementation(() => {
return false;
@ -170,7 +168,7 @@ describe('isCacheFeatureAvailable', () => {
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';
//Act
@ -188,10 +186,8 @@ describe('isCacheFeatureAvailable', () => {
process.env['GITHUB_SERVER_URL'] = 'https://github.com';
let functionResult;
//Act
functionResult = cacheUtils.isCacheFeatureAvailable();
const functionResult = cacheUtils.isCacheFeatureAvailable();
//Assert
expect(functionResult).toBeFalsy();
@ -205,7 +201,7 @@ describe('isCacheFeatureAvailable', () => {
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.';
//Act + Assert

View file

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

View file

@ -60457,7 +60457,7 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
});
exports.getPackageManagerInfo = getPackageManagerInfo;
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);
if (!cachePaths.length) {
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;
const findDependencyFile = (packageManager) => {
let dependencyFile = packageManager.dependencyFilePattern;
const dependencyFile = packageManager.dependencyFilePattern;
const workspace = process.env.GITHUB_WORKSPACE;
const rootContent = fs_1.default.readdirSync(workspace);
const goSumFileExists = rootContent.includes(dependencyFile);
@ -63130,7 +63130,7 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
});
exports.getPackageManagerInfo = getPackageManagerInfo;
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);
if (!cachePaths.length) {
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()) {
return __awaiter(this, void 0, void 0, function* () {
let manifest;
let osPlat = os_1.default.platform();
const osPlat = os_1.default.platform();
if (versionSpec === utils_1.StableReleaseAlias.Stable ||
versionSpec === utils_1.StableReleaseAlias.OldStable) {
manifest = yield getManifest(auth);
@ -63255,8 +63255,7 @@ function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch()) {
}
}
// check cache
let toolPath;
toolPath = tc.find('go', versionSpec, arch);
const toolPath = tc.find('go', versionSpec, arch);
// If not found in cache, download
if (toolPath) {
core.info(`Found in cache @ ${toolPath}`);
@ -63382,12 +63381,11 @@ function getInfoFromManifest(versionSpec, stable, auth, arch = os_1.default.arch
exports.getInfoFromManifest = getInfoFromManifest;
function getInfoFromDist(versionSpec, arch) {
return __awaiter(this, void 0, void 0, function* () {
let version;
version = yield findMatch(versionSpec, arch);
const version = yield findMatch(versionSpec, arch);
if (!version) {
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 {
type: 'dist',
downloadUrl: downloadUrl,
@ -63409,8 +63407,8 @@ function findMatch(versionSpec, arch = os_1.default.arch()) {
}
let goFile;
for (let i = 0; i < candidates.length; i++) {
let candidate = candidates[i];
let version = makeSemver(candidate.version);
const candidate = candidates[i];
const version = makeSemver(candidate.version);
core.debug(`check ${version} satisfies ${versionSpec}`);
if (semver.satisfies(version, versionSpec)) {
goFile = candidate.files.find(file => {
@ -63454,8 +63452,8 @@ function makeSemver(version) {
var _a;
version = version.replace('go', '');
version = version.replace('beta', '-beta.').replace('rc', '-rc.');
let parts = version.split('-');
let semVersion = (_a = semver.coerce(parts[0])) === null || _a === void 0 ? void 0 : _a.version;
const parts = version.split('-');
const semVersion = (_a = semver.coerce(parts[0])) === null || _a === void 0 ? void 0 : _a.version;
if (!semVersion) {
throw new Error(`The version: ${version} can't be changed to SemVer notation`);
}
@ -63481,8 +63479,8 @@ function parseGoVersionFile(versionFilePath) {
exports.parseGoVersionFile = parseGoVersionFile;
function resolveStableVersionDist(versionSpec, arch) {
return __awaiter(this, void 0, void 0, function* () {
let archFilter = sys.getArch(arch);
let platFilter = sys.getPlatform();
const archFilter = sys.getArch(arch);
const platFilter = sys.getPlatform();
const dlUrl = 'https://golang.org/dl/?mode=json&include=all';
const candidates = yield module.exports.getVersionsDist(dlUrl);
if (!candidates) {
@ -63585,8 +63583,8 @@ function run() {
arch = os_1.default.arch();
}
if (versionSpec) {
let token = core.getInput('token');
let auth = !token ? undefined : `token ${token}`;
const token = core.getInput('token');
const auth = !token ? undefined : `token ${token}`;
const checkLatest = core.getBooleanInput('check-latest');
const installDir = yield installer.getGo(versionSpec, checkLatest, auth, arch);
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.exportVariable('GOROOT', installDir);
}
let added = yield addBinToPath();
const added = yield addBinToPath();
core.debug(`add bin ${added}`);
core.info(`Successfully set up Go version ${versionSpec}`);
}
let goPath = yield io.which('go');
let goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString();
const goPath = yield io.which('go');
const goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString();
if (cache && cache_utils_1.isCacheFeatureAvailable()) {
const packageManager = 'default';
const cacheDependencyPath = core.getInput('cache-dependency-path');
@ -63616,7 +63614,7 @@ function run() {
core.info(goVersion);
core.setOutput('go-version', parseGoVersion(goVersion));
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.endGroup();
}
@ -63629,22 +63627,22 @@ exports.run = run;
function addBinToPath() {
return __awaiter(this, void 0, void 0, function* () {
let added = false;
let g = yield io.which('go');
const g = yield io.which('go');
core.debug(`which go :${g}:`);
if (!g) {
core.debug('go not in the path');
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) {
let gp = buf.toString().trim();
const gp = buf.toString().trim();
core.debug(`go env GOPATH :${gp}:`);
if (!fs_1.default.existsSync(gp)) {
// some of the hosted images have go install but not profile dir
core.debug(`creating ${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)) {
core.debug(`creating ${bp}`);
yield io.mkdirP(bp);
@ -63703,18 +63701,21 @@ exports.supportedPackageManagers = {
/***/ }),
/***/ 4300:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getArch = exports.getPlatform = void 0;
const os = __nccwpck_require__(2037);
const os_1 = __importDefault(__nccwpck_require__(2037));
function getPlatform() {
// darwin and linux match already
// freebsd not supported yet but future proofed.
// 'aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', and 'win32'
let plat = os.platform();
let plat = os_1.default.platform();
// wants 'darwin', 'freebsd', 'linux', 'windows'
if (plat === 'win32') {
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
- 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
- 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
@ -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 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
- 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",
"scripts": {
"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-check": "prettier --check **/*.ts",
"lint": "echo \"Fake command that does nothing. It is used in reusable workflows\"",
"format": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --write **/*.{ts,yml,yaml}",
"format-check": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --check **/*.{ts,yml,yaml}",
"lint": "eslint --config ./.eslintrc.js **/*.ts",
"lint:fix": "eslint --config ./.eslintrc.js **/*.ts --fix",
"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": {
"type": "git",
@ -37,11 +38,16 @@
"@types/jest": "^27.0.2",
"@types/node": "^16.11.25",
"@types/semver": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
"@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-circus": "^27.2.5",
"nock": "^10.0.6",
"prettier": "^1.17.1",
"prettier": "^2.8.4",
"ts-jest": "^27.0.5",
"typescript": "^4.3.3"
}

View file

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

View file

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

View file

@ -37,7 +37,7 @@ export async function getGo(
arch = os.arch()
) {
let manifest: tc.IToolRelease[] | undefined;
let osPlat: string = os.platform();
const osPlat: string = os.platform();
if (
versionSpec === StableReleaseAlias.Stable ||
@ -83,8 +83,7 @@ export async function getGo(
}
// check cache
let toolPath: string;
toolPath = tc.find('go', versionSpec, arch);
const toolPath = tc.find('go', versionSpec, arch);
// If not found in cache, download
if (toolPath) {
core.info(`Found in cache @ ${toolPath}`);
@ -246,13 +245,12 @@ async function getInfoFromDist(
versionSpec: string,
arch: string
): Promise<IGoVersionInfo | null> {
let version: IGoVersion | undefined;
version = await findMatch(versionSpec, arch);
const version: IGoVersion | undefined = await findMatch(versionSpec, arch);
if (!version) {
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>{
type: 'dist',
@ -282,8 +280,8 @@ export async function findMatch(
let goFile: IGoVersionFile | undefined;
for (let i = 0; i < candidates.length; i++) {
let candidate: IGoVersion = candidates[i];
let version = makeSemver(candidate.version);
const candidate: IGoVersion = candidates[i];
const version = makeSemver(candidate.version);
core.debug(`check ${version} satisfies ${versionSpec}`);
if (semver.satisfies(version, versionSpec)) {
@ -331,9 +329,9 @@ export async function getVersionsDist(
export function makeSemver(version: string): string {
version = version.replace('go', '');
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) {
throw new Error(
`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) {
let archFilter = sys.getArch(arch);
let platFilter = sys.getPlatform();
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all';
const archFilter = sys.getArch(arch);
const platFilter = sys.getPlatform();
const dlUrl = 'https://golang.org/dl/?mode=json&include=all';
const candidates: IGoVersion[] | null = await module.exports.getVersionsDist(
dlUrl
);

View file

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

View file

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

View file

@ -46,6 +46,7 @@
// "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. */
"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,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */