Merge branch 'modules-caching' into v-dmshib/modules-caching

This commit is contained in:
Dmitry Shibanov 2022-04-01 14:34:20 +02:00
commit fce3a09c89
19 changed files with 480 additions and 482 deletions

View file

@ -23,10 +23,10 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set Node.js 12.x
- name: Set Node.js 16.x
uses: actions/setup-node@v2
with:
node-version: 12.x
node-version: 16.x
- name: Install dependencies
run: npm ci

View file

@ -14,11 +14,15 @@ jobs:
name: Check licenses
steps:
- uses: actions/checkout@v2
- name: Set Node.js 16.x
uses: actions/setup-node@v2
with:
node-version: 16.x
- run: npm ci
- name: Install licensed
run: |
cd $RUNNER_TEMP
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/3.3.1/licensed-3.3.1-linux-x64.tar.gz
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/3.4.4/licensed-3.4.4-linux-x64.tar.gz
sudo tar -xzf licensed.tar.gz
sudo mv licensed /usr/local/bin/licensed
- run: licensed status

View file

@ -78,7 +78,7 @@ jobs:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
go: [1.7, 1.8.6]
go: [1.9, 1.8.6]
steps:
- name: Checkout
uses: actions/checkout@v2

View file

@ -19,10 +19,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Setup node 12
- name: Setup node 16
uses: actions/setup-node@v2
with:
node-version: 12
node-version: 16
cache: npm
- name: npm ci

View file

@ -1 +1 @@
* @actions/spark
* @actions/actions-service

View file

@ -11,13 +11,13 @@ This action sets up a go environment for use in actions by:
- optionally downloading and caching a version of Go by version and adding to PATH
- registering problem matchers for error output
# V2
# V3
The V2 offers:
The V3 offers:
- Adds GOBIN to the PATH
- Proxy Support
- `stable` input
- Check latest version
- Caching packages dependencies
- Bug Fixes (including issues around version matching and semver)
The action will first check the local cache for a version match. If a version is not found locally, it will pull it from the `main` branch of the [go-versions](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository. On miss or failure, it will fall back to downloading directly from [go dist](https://storage.googleapis.com/golang). To change the default behavior, please use the [check-latest input](#check-latest-version).
@ -25,21 +25,38 @@ The action will first check the local cache for a version match. If a version is
Matching by [semver spec](https://github.com/npm/node-semver):
```yaml
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.13.1' # The Go version to download (if necessary) and use.
- run: go version
```
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '>=1.17.0'
- run: go version
```
Matching an unstable pre-release:
```yaml
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
stable: 'false'
go-version: '1.14.0-rc1' # The Go version to download (if necessary) and use.
go-version: '1.18.0-rc.1' # The Go version to download (if necessary) and use.
- run: go version
```
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.16.0-beta.1' # The Go version to download (if necessary) and use.
- run: go version
```
@ -50,8 +67,8 @@ See [action.yml](action.yml)
## Basic:
```yaml
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.16.1' # The Go version to download (if necessary) and use.
- run: go run hello.go
@ -68,14 +85,45 @@ If `check-latest` is set to `true`, the action first checks if the cached versio
```yaml
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.14'
check-latest: true
- run: go run hello.go
```
## Caching packages dependencies:
The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under the hood for caching dependencies but requires less configuration settings.The `cache` input is optional, and caching is turned off by default.
The action defaults to search for the dependency file - go.sum in the repository root, and uses its hash as a part of the cache key. Use `cache-dependency-path` input for cases when multiple dependency files are used, or they are located in different subdirectories.
**Caching packages dependencies without specifying dependency file path**
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.14'
check-latest: true
cache: true
- run: go run hello.go
```
**Caching packages dependencies in monorepos**
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.14'
check-latest: true
cache: true
cache-dependency-path: subdir/go.sum
- run: go run hello.go
```
## Matrix Testing:
```yaml
jobs:
@ -86,9 +134,9 @@ jobs:
go: [ '1.14', '1.13' ]
name: Go ${{ matrix.go }} sample
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- run: go run hello.go
@ -97,8 +145,8 @@ jobs:
### Supported version syntax
The `go-version` input supports the following syntax:
Specific versions: `1.15`, `1.16.1`, `1.17.0-rc2`, `1.16.0-beta1`
SemVer's version range syntax: `^1.13.1`
Specific versions: `1.15`, `1.16.1`, `1.17.0-rc.2`, `1.16.0-beta.1`
SemVer's version range syntax: `^1.13.1`, `>=1.18.0-rc.1`
For more information about semantic versioning please refer [semver](https://github.com/npm/node-semver) documentation
# License

View file

@ -0,0 +1,86 @@
import * as cache from '@actions/cache';
import * as core from '@actions/core';
import * as glob from '@actions/glob';
import * as cacheRestore from '../src/cache-restore';
import * as cacheUtils from '../src/cache-utils';
import {PackageManagerInfo} from '../src/package-managers';
describe('restoreCache', () => {
//Arrange
let hashFilesSpy = jest.spyOn(glob, 'hashFiles');
let getCacheDirectoryPathSpy = jest.spyOn(
cacheUtils,
'getCacheDirectoryPath'
);
let restoreCacheSpy = jest.spyOn(cache, 'restoreCache');
let infoSpy = jest.spyOn(core, 'info');
let setOutputSpy = jest.spyOn(core, 'setOutput');
const packageManager = 'default';
const cacheDependencyPath = 'path';
beforeEach(() => {
getCacheDirectoryPathSpy.mockImplementation(
(PackageManager: PackageManagerInfo) => {
return new Promise<string>(resolve => {
resolve('cache_directory_path');
});
}
);
});
it('should throw if dependency file path is not valid', async () => {
//Arrange
hashFilesSpy.mockImplementation((somePath: string) => {
return new Promise<string>(resolve => {
resolve('');
});
});
//Act + Assert
expect(async () => {
await cacheRestore.restoreCache(packageManager, cacheDependencyPath);
}).rejects.toThrowError(
'Some specified paths were not resolved, unable to cache dependencies.'
);
});
it('should inform if cache hit is not occured', async () => {
//Arrange
hashFilesSpy.mockImplementation((somePath: string) => {
return new Promise<string>(resolve => {
resolve('file_hash');
});
});
restoreCacheSpy.mockImplementation(() => {
return new Promise<string>(resolve => {
resolve('');
});
});
//Act + Assert
await cacheRestore.restoreCache(packageManager, cacheDependencyPath);
expect(infoSpy).toBeCalledWith(`Cache is not found`);
});
it('should set output if cache hit is occured', async () => {
//Arrange
hashFilesSpy.mockImplementation((somePath: string) => {
return new Promise<string>(resolve => {
resolve('file_hash');
});
});
restoreCacheSpy.mockImplementation(() => {
return new Promise<string>(resolve => {
resolve('cache_key');
});
});
//Act + Assert
await cacheRestore.restoreCache(packageManager, cacheDependencyPath);
expect(setOutputSpy).toBeCalledWith('cache-hit', true);
});
});

View file

@ -0,0 +1,106 @@
import * as exec from '@actions/exec';
import * as cacheUtils from '../src/cache-utils';
import {PackageManagerInfo} from '../src/package-managers';
describe('getCommandOutput', () => {
//Arrange
let getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
it('should return trimmed stdout in case of successful exit code', async () => {
//Arrange
const stdoutResult = ' stdout ';
const trimmedStdout = stdoutResult.trim();
getExecOutputSpy.mockImplementation((commandLine: string) => {
return new Promise<exec.ExecOutput>(resolve => {
resolve({exitCode: 0, stdout: stdoutResult, stderr: ''});
});
});
//Act + Assert
return cacheUtils
.getCommandOutput('command')
.then(data => expect(data).toBe(trimmedStdout));
});
it('should return error in case of unsuccessful exit code', async () => {
//Arrange
const stderrResult = 'error message';
getExecOutputSpy.mockImplementation((commandLine: string) => {
return new Promise<exec.ExecOutput>(resolve => {
resolve({exitCode: 10, stdout: '', stderr: stderrResult});
});
});
//Act + Assert
expect(async () => {
await cacheUtils.getCommandOutput('command');
}).rejects.toThrow();
});
});
describe('getPackageManagerInfo', () => {
it('should return package manager info in case of valid package manager name', async () => {
//Arrange
const packageManagerName = 'default';
const expectedResult = {
dependencyFilePattern: 'go.sum',
getCacheFolderCommand: 'go env GOMODCACHE'
};
//Act + Assert
return cacheUtils
.getPackageManagerInfo(packageManagerName)
.then(data => expect(data).toEqual(expectedResult));
});
it('should throw the error in case of invalid package manager name', async () => {
//Arrange
const packageManagerName = 'invalidName';
//Act + Assert
expect(async () => {
await cacheUtils.getPackageManagerInfo(packageManagerName);
}).rejects.toThrow();
});
});
describe('getCacheDirectoryPath', () => {
//Arrange
let getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
const validPackageManager: PackageManagerInfo = {
dependencyFilePattern: 'go.sum',
getCacheFolderCommand: 'go env GOMODCACHE'
};
it('should return path to the cache folder which specified package manager uses', async () => {
//Arrange
getExecOutputSpy.mockImplementation((commandLine: string) => {
return new Promise<exec.ExecOutput>(resolve => {
resolve({exitCode: 0, stdout: 'path/to/cache/folder', stderr: ''});
});
});
const expectedResult = 'path/to/cache/folder';
//Act + Assert
return cacheUtils
.getCacheDirectoryPath(validPackageManager)
.then(data => expect(data).toEqual(expectedResult));
});
it('should throw if the specified package name is invalid', async () => {
getExecOutputSpy.mockImplementation((commandLine: string) => {
return new Promise<exec.ExecOutput>(resolve => {
resolve({exitCode: 10, stdout: '', stderr: 'Error message'});
});
});
//Act + Assert
expect(async () => {
await cacheUtils.getCacheDirectoryPath(validPackageManager);
}).rejects.toThrow();
});
});

View file

@ -20,6 +20,7 @@ describe('setup-go', () => {
let inSpy: jest.SpyInstance;
let getBooleanInputSpy: jest.SpyInstance;
let exportVarSpy: jest.SpyInstance;
let findSpy: jest.SpyInstance;
let cnSpy: jest.SpyInstance;
let logSpy: jest.SpyInstance;
@ -27,7 +28,7 @@ describe('setup-go', () => {
let platSpy: jest.SpyInstance;
let archSpy: jest.SpyInstance;
let dlSpy: jest.SpyInstance;
let exSpy: jest.SpyInstance;
let extractTarSpy: jest.SpyInstance;
let cacheSpy: jest.SpyInstance;
let dbgSpy: jest.SpyInstance;
let whichSpy: jest.SpyInstance;
@ -49,6 +50,7 @@ describe('setup-go', () => {
inSpy.mockImplementation(name => inputs[name]);
getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput');
getBooleanInputSpy.mockImplementation(name => inputs[name]);
exportVarSpy = jest.spyOn(core, 'exportVariable');
// node
os = {};
@ -61,7 +63,7 @@ describe('setup-go', () => {
// @actions/tool-cache
findSpy = jest.spyOn(tc, 'find');
dlSpy = jest.spyOn(tc, 'downloadTool');
exSpy = jest.spyOn(tc, 'extractTar');
extractTarSpy = jest.spyOn(tc, 'extractTar');
cacheSpy = jest.spyOn(tc, 'cacheDir');
getSpy = jest.spyOn(im, 'getVersionsDist');
getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
@ -85,7 +87,7 @@ describe('setup-go', () => {
});
logSpy.mockImplementation(line => {
// uncomment to debug
// process.stderr.write('log:' + line + '\n');
//process.stderr.write('log:' + line + '\n');
});
dbgSpy.mockImplementation(msg => {
// uncomment to see debug output
@ -147,7 +149,7 @@ describe('setup-go', () => {
os.arch = 'x64';
// spec: 1.13.0 => 1.13
let match: im.IGoVersion | undefined = await im.findMatch('1.13.0', true);
let match: im.IGoVersion | undefined = await im.findMatch('1.13.0');
expect(match).toBeDefined();
let version: string = match ? match.version : '';
expect(version).toBe('go1.13');
@ -160,7 +162,7 @@ describe('setup-go', () => {
os.arch = 'x64';
// spec: 1.13 => 1.13.7 (latest)
let match: im.IGoVersion | undefined = await im.findMatch('1.13', true);
let match: im.IGoVersion | undefined = await im.findMatch('1.13');
expect(match).toBeDefined();
let version: string = match ? match.version : '';
expect(version).toBe('go1.13.7');
@ -173,7 +175,7 @@ describe('setup-go', () => {
os.arch = 'x64';
// spec: ^1.13.6 => 1.13.7
let match: im.IGoVersion | undefined = await im.findMatch('^1.13.6', true);
let match: im.IGoVersion | undefined = await im.findMatch('^1.13.6');
expect(match).toBeDefined();
let version: string = match ? match.version : '';
expect(version).toBe('go1.13.7');
@ -186,7 +188,7 @@ describe('setup-go', () => {
os.arch = 'x32';
// spec: 1 => 1.13.7 (latest)
let match: im.IGoVersion | undefined = await im.findMatch('1', true);
let match: im.IGoVersion | undefined = await im.findMatch('1');
expect(match).toBeDefined();
let version: string = match ? match.version : '';
expect(version).toBe('go1.13.7');
@ -199,10 +201,7 @@ describe('setup-go', () => {
os.arch = 'x64';
// spec: 1.14, stable=false => go1.14rc1
let match: im.IGoVersion | undefined = await im.findMatch(
'1.14.0-rc1',
false
);
let match: im.IGoVersion | undefined = await im.findMatch('1.14.0-rc.1');
expect(match).toBeDefined();
let version: string = match ? match.version : '';
expect(version).toBe('go1.14rc1');
@ -218,7 +217,7 @@ describe('setup-go', () => {
findSpy.mockImplementation(() => toolPath);
await main.run();
expect(logSpy).toHaveBeenCalledWith(`Setup go stable version spec 1.13.0`);
expect(logSpy).toHaveBeenCalledWith(`Setup go version spec 1.13.0`);
});
it('evaluates to stable with no input', async () => {
@ -230,7 +229,41 @@ describe('setup-go', () => {
findSpy.mockImplementation(() => toolPath);
await main.run();
expect(logSpy).toHaveBeenCalledWith(`Setup go stable version spec 1.13.0`);
expect(logSpy).toHaveBeenCalledWith(`Setup go version spec 1.13.0`);
});
it('does not export any variables for Go versions >=1.9', async () => {
inputs['go-version'] = '1.13.0';
inSpy.mockImplementation(name => inputs[name]);
let toolPath = path.normalize('/cache/go/1.13.0/x64');
findSpy.mockImplementation(() => toolPath);
let vars: {[key: string]: string} = {};
exportVarSpy.mockImplementation((name: string, val: string) => {
vars[name] = val;
});
await main.run();
expect(vars).toStrictEqual({});
});
it('exports GOROOT for Go versions <1.9', async () => {
inputs['go-version'] = '1.8';
inSpy.mockImplementation(name => inputs[name]);
let toolPath = path.normalize('/cache/go/1.8.0/x64');
findSpy.mockImplementation(() => toolPath);
let vars: {[key: string]: string} = {};
exportVarSpy.mockImplementation((name: string, val: string) => {
vars[name] = val;
});
await main.run();
expect(vars).toStrictEqual({
GOROOT: toolPath
});
});
it('finds a version of go already in the cache', async () => {
@ -274,14 +307,14 @@ describe('setup-go', () => {
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(() => '/some/temp/path');
let toolPath = path.normalize('/cache/go/1.13.0/x64');
exSpy.mockImplementation(() => '/some/other/temp/path');
extractTarSpy.mockImplementation(() => '/some/other/temp/path');
cacheSpy.mockImplementation(() => toolPath);
await main.run();
let expPath = path.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalled();
expect(exSpy).toHaveBeenCalled();
expect(extractTarSpy).toHaveBeenCalled();
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
@ -316,7 +349,7 @@ describe('setup-go', () => {
dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/go/1.12.16/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
@ -324,7 +357,7 @@ describe('setup-go', () => {
let expPath = path.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalled();
expect(exSpy).toHaveBeenCalled();
expect(extractTarSpy).toHaveBeenCalled();
expect(logSpy).not.toHaveBeenCalledWith(
'Not found in manifest. Falling back to download directly from Go'
);
@ -353,7 +386,7 @@ describe('setup-go', () => {
dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/go/1.12.17/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
@ -361,7 +394,7 @@ describe('setup-go', () => {
let expPath = path.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalled();
expect(exSpy).toHaveBeenCalled();
expect(extractTarSpy).toHaveBeenCalled();
expect(logSpy).not.toHaveBeenCalledWith(
'Not found in manifest. Falling back to download directly from Go'
);
@ -390,18 +423,18 @@ describe('setup-go', () => {
dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/go/1.12.14/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
let expPath = path.join(toolPath, 'bin');
expect(logSpy).toHaveBeenCalledWith('Setup go stable version spec 1.12.14');
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.12.14');
expect(findSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.12.14...');
expect(dlSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith('matching 1.12.14...');
expect(exSpy).toHaveBeenCalled();
expect(extractTarSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
'Not found in manifest. Falling back to download directly from Go'
);
@ -560,11 +593,11 @@ describe('setup-go', () => {
// 1.13.1 => 1.13.1
// 1.13 => 1.13.0
// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
// 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
// 1.10beta1 => 1.10.0-beta.1, 1.10rc1 => 1.10.0-rc.1
// 1.8.5beta1 => 1.8.5-beta.1, 1.8.5rc1 => 1.8.5-rc.1
it('converts prerelease versions', async () => {
expect(im.makeSemver('1.10beta1')).toBe('1.10.0-beta1');
expect(im.makeSemver('1.10rc1')).toBe('1.10.0-rc1');
expect(im.makeSemver('1.10beta1')).toBe('1.10.0-beta.1');
expect(im.makeSemver('1.10rc1')).toBe('1.10.0-rc.1');
});
it('converts dot zero versions', async () => {
@ -603,12 +636,12 @@ describe('setup-go', () => {
const toolPath = path.normalize('/cache/go/1.16.1/x64');
findSpy.mockReturnValue(toolPath);
dlSpy.mockImplementation(async () => '/some/temp/path');
exSpy.mockImplementation(async () => '/some/other/temp/path');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
expect(logSpy).toHaveBeenCalledWith('Setup go stable version spec 1.16');
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.16');
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
});
@ -625,7 +658,7 @@ describe('setup-go', () => {
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
const toolPath = path.normalize('/cache/go/1.17.5/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
const expectedUrl =
'https://github.com/actions/go-versions/releases/download/1.17.6-1668090892/go-1.17.6-darwin-x64.tar.gz';
@ -633,7 +666,7 @@ describe('setup-go', () => {
await main.run();
expect(logSpy).toHaveBeenCalledWith(
`Setup go stable version spec ${versionSpec}`
`Setup go version spec ${versionSpec}`
);
expect(logSpy).toHaveBeenCalledWith(
'Attempting to resolve the latest version from the manifest...'
@ -666,7 +699,7 @@ describe('setup-go', () => {
dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/go/1.13.7/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
@ -674,7 +707,7 @@ describe('setup-go', () => {
let expPath = path.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalled();
expect(exSpy).toHaveBeenCalled();
expect(extractTarSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
'Attempting to resolve the latest version from the manifest...'
);
@ -708,7 +741,7 @@ describe('setup-go', () => {
dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/go/1.13.7/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
@ -719,7 +752,7 @@ describe('setup-go', () => {
`Failed to resolve version ${versionSpec} from manifest`
);
expect(dlSpy).toHaveBeenCalled();
expect(exSpy).toHaveBeenCalled();
expect(extractTarSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
'Attempting to resolve the latest version from the manifest...'
);

View file

@ -7,22 +7,16 @@ inputs:
check-latest:
description: 'Set this option to true if you want the action to always check for the latest available version that satisfies the version spec'
default: false
stable:
description: 'Whether to download only stable versions'
default: 'true'
token:
description: Used to pull node distributions from go-versions. Since there's a default, this is typically not supplied by the user.
default: ${{ github.token }}
cache:
description: Used to specify whether go-modules caching is needed. Set to true, if you'd like to enable caching.
default: false
package-manager:
description: 'Used to specify non-default package manager'
default: 'default'
cache-dependency-path:
description: 'Used to specify the path to a dependency file: go.sum'
description: 'Used to specify the path to a dependency file - go.sum'
runs:
using: 'node12'
using: 'node16'
main: 'dist/setup/index.js'
post: 'dist/cache-save/index.js'
post-if: success()

View file

@ -3231,10 +3231,7 @@ const options_1 = __webpack_require__(538);
const requestUtils_1 = __webpack_require__(899);
const versionSalt = '1.0';
function getCacheApiUrl(resource) {
// Ideally we just use ACTIONS_CACHE_URL
const baseUrl = (process.env['ACTIONS_CACHE_URL'] ||
process.env['ACTIONS_RUNTIME_URL'] ||
'').replace('pipelines', 'artifactcache');
const baseUrl = process.env['ACTIONS_CACHE_URL'] || '';
if (!baseUrl) {
throw new Error('Cache Service Url not found, unable to restore cache.');
}
@ -3944,7 +3941,8 @@ exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, vo
if (!package_managers_1.supportedPackageManagers[packageManager]) {
throw new Error(`It's not possible to use ${packageManager}, please, check correctness of the package manager name spelling.`);
}
return package_managers_1.supportedPackageManagers[packageManager];
const obtainedPackageManager = package_managers_1.supportedPackageManagers[packageManager];
return obtainedPackageManager;
});
exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
const stdout = yield exports.getCommandOutput(packageManagerInfo.getCacheFolderCommand);
@ -5657,7 +5655,8 @@ function downloadCacheStorageSDK(archiveLocation, archivePath, options) {
//
// If the file exceeds the buffer maximum length (~1 GB on 32-bit systems and ~2 GB
// on 64-bit systems), split the download into multiple segments
const maxSegmentSize = buffer.constants.MAX_LENGTH;
// ~2 GB = 2147483647, beyond this, we start getting out of range error. So, capping it accordingly.
const maxSegmentSize = Math.min(2147483647, buffer.constants.MAX_LENGTH);
const downloadProgress = new DownloadProgress(contentLength);
const fd = fs.openSync(archivePath, 'w');
try {
@ -43507,6 +43506,15 @@ function checkKey(key) {
throw new ValidationError(`Key Validation Error: ${key} cannot contain commas.`);
}
}
/**
* isFeatureAvailable to check the presence of Actions cache service
*
* @returns boolean return true if Actions cache service feature is available, otherwise false
*/
function isFeatureAvailable() {
return !!process.env['ACTIONS_CACHE_URL'];
}
exports.isFeatureAvailable = isFeatureAvailable;
/**
* Restores cache from keys
*
@ -46368,10 +46376,11 @@ function run() {
}
exports.run = run;
const cachePackages = () => __awaiter(void 0, void 0, void 0, function* () {
const cachingFlag = core.getBooleanInput('cache');
if (!cachingFlag)
const cacheInput = core.getInput('cache');
if (!cacheInput) {
return;
const packageManager = core.getInput('package-manager');
}
const packageManager = cacheInput.toUpperCase() === 'TRUE' ? 'default' : cacheInput;
const state = core.getState(constants_1.State.CacheMatchedKey);
const primaryKey = core.getState(constants_1.State.CachePrimaryKey);
const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);

92
dist/setup/index.js vendored
View file

@ -3342,10 +3342,7 @@ const options_1 = __webpack_require__(538);
const requestUtils_1 = __webpack_require__(899);
const versionSalt = '1.0';
function getCacheApiUrl(resource) {
// Ideally we just use ACTIONS_CACHE_URL
const baseUrl = (process.env['ACTIONS_CACHE_URL'] ||
process.env['ACTIONS_RUNTIME_URL'] ||
'').replace('pipelines', 'artifactcache');
const baseUrl = process.env['ACTIONS_CACHE_URL'] || '';
if (!baseUrl) {
throw new Error('Cache Service Url not found, unable to restore cache.');
}
@ -3689,6 +3686,7 @@ exports.addBinToPath = exports.run = void 0;
const core = __importStar(__webpack_require__(470));
const io = __importStar(__webpack_require__(1));
const installer = __importStar(__webpack_require__(923));
const semver = __importStar(__webpack_require__(280));
const path_1 = __importDefault(__webpack_require__(622));
const cache_restore_1 = __webpack_require__(409);
const child_process_1 = __importDefault(__webpack_require__(129));
@ -3702,19 +3700,21 @@ function run() {
// If not supplied then problem matchers will still be setup. Useful for self-hosted.
//
let versionSpec = core.getInput('go-version');
// stable will be true unless false is the exact input
// since getting unstable versions should be explicit
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
const cache = core.getBooleanInput('cache');
core.info(`Setup go ${stable ? 'stable' : ''} version spec ${versionSpec}`);
const cache = core.getInput('cache');
core.info(`Setup go version spec ${versionSpec}`);
if (versionSpec) {
let token = core.getInput('token');
let auth = !token || isGhes() ? undefined : `token ${token}`;
const checkLatest = core.getBooleanInput('check-latest');
const installDir = yield installer.getGo(versionSpec, stable, checkLatest, auth);
core.exportVariable('GOROOT', installDir);
const installDir = yield installer.getGo(versionSpec, checkLatest, auth);
core.addPath(path_1.default.join(installDir, 'bin'));
core.info('Added go to the path');
const version = installer.makeSemver(versionSpec);
// Go versions less than 1.9 require GOROOT to be set
if (semver.lt(version, '1.9.0')) {
core.info('Setting GOROOT for Go version < 1.9');
core.exportVariable('GOROOT', installDir);
}
let added = yield addBinToPath();
core.debug(`add bin ${added}`);
core.info(`Successfully setup go version ${versionSpec}`);
@ -3723,7 +3723,7 @@ function run() {
if (isGhes()) {
throw new Error('Caching is not supported on GHES');
}
const packageManager = core.getInput('package-manager');
const packageManager = cache.toUpperCase() === 'TRUE' ? 'default' : cache;
const cacheDependencyPath = core.getInput('cache-dependency-path');
yield cache_restore_1.restoreCache(packageManager, cacheDependencyPath);
}
@ -3761,12 +3761,12 @@ function addBinToPath() {
if (!fs_1.default.existsSync(gp)) {
// some of the hosted images have go install but not profile dir
core.debug(`creating ${gp}`);
io.mkdirP(gp);
yield io.mkdirP(gp);
}
let bp = path_1.default.join(gp, 'bin');
if (!fs_1.default.existsSync(bp)) {
core.debug(`creating ${bp}`);
io.mkdirP(bp);
yield io.mkdirP(bp);
}
core.addPath(bp);
added = true;
@ -4188,7 +4188,8 @@ exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, vo
if (!package_managers_1.supportedPackageManagers[packageManager]) {
throw new Error(`It's not possible to use ${packageManager}, please, check correctness of the package manager name spelling.`);
}
return package_managers_1.supportedPackageManagers[packageManager];
const obtainedPackageManager = package_managers_1.supportedPackageManagers[packageManager];
return obtainedPackageManager;
});
exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
const stdout = yield exports.getCommandOutput(packageManagerInfo.getCacheFolderCommand);
@ -6081,7 +6082,8 @@ function downloadCacheStorageSDK(archiveLocation, archivePath, options) {
//
// If the file exceeds the buffer maximum length (~1 GB on 32-bit systems and ~2 GB
// on 64-bit systems), split the download into multiple segments
const maxSegmentSize = buffer.constants.MAX_LENGTH;
// ~2 GB = 2147483647, beyond this, we start getting out of range error. So, capping it accordingly.
const maxSegmentSize = Math.min(2147483647, buffer.constants.MAX_LENGTH);
const downloadProgress = new DownloadProgress(contentLength);
const fd = fs.openSync(archivePath, 'w');
try {
@ -45173,6 +45175,15 @@ function checkKey(key) {
throw new ValidationError(`Key Validation Error: ${key} cannot contain commas.`);
}
}
/**
* isFeatureAvailable to check the presence of Actions cache service
*
* @returns boolean return true if Actions cache service feature is available, otherwise false
*/
function isFeatureAvailable() {
return !!process.env['ACTIONS_CACHE_URL'];
}
exports.isFeatureAvailable = isFeatureAvailable;
/**
* Restores cache from keys
*
@ -52460,7 +52471,7 @@ __exportStar(__webpack_require__(764), exports);
Object.defineProperty(exports, "__esModule", { value: true });
exports.getArch = exports.getPlatform = void 0;
let os = __webpack_require__(87);
const os = __webpack_require__(87);
function getPlatform() {
// darwin and linux match already
// freebsd not supported yet but future proofed.
@ -52632,13 +52643,13 @@ const semver = __importStar(__webpack_require__(280));
const httpm = __importStar(__webpack_require__(539));
const sys = __importStar(__webpack_require__(913));
const os_1 = __importDefault(__webpack_require__(87));
function getGo(versionSpec, stable, checkLatest, auth) {
function getGo(versionSpec, checkLatest, auth) {
return __awaiter(this, void 0, void 0, function* () {
let osPlat = os_1.default.platform();
let osArch = os_1.default.arch();
if (checkLatest) {
core.info('Attempting to resolve the latest version from the manifest...');
const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth);
const resolvedVersion = yield resolveVersionFromManifest(versionSpec, true, auth);
if (resolvedVersion) {
versionSpec = resolvedVersion;
core.info(`Resolved as '${versionSpec}'`);
@ -52662,7 +52673,7 @@ function getGo(versionSpec, stable, checkLatest, auth) {
// Try download from internal distribution (popular versions only)
//
try {
info = yield getInfoFromManifest(versionSpec, stable, auth);
info = yield getInfoFromManifest(versionSpec, true, auth);
if (info) {
downloadPath = yield installGoVersion(info, auth);
}
@ -52685,7 +52696,7 @@ function getGo(versionSpec, stable, checkLatest, auth) {
// Download from storage.googleapis.com
//
if (!downloadPath) {
info = yield getInfoFromDist(versionSpec, stable);
info = yield getInfoFromDist(versionSpec);
if (!info) {
throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`);
}
@ -52760,10 +52771,10 @@ function getInfoFromManifest(versionSpec, stable, auth) {
});
}
exports.getInfoFromManifest = getInfoFromManifest;
function getInfoFromDist(versionSpec, stable) {
function getInfoFromDist(versionSpec) {
return __awaiter(this, void 0, void 0, function* () {
let version;
version = yield findMatch(versionSpec, stable);
version = yield findMatch(versionSpec);
if (!version) {
return null;
}
@ -52776,7 +52787,7 @@ function getInfoFromDist(versionSpec, stable) {
};
});
}
function findMatch(versionSpec, stable) {
function findMatch(versionSpec) {
return __awaiter(this, void 0, void 0, function* () {
let archFilter = sys.getArch();
let platFilter = sys.getPlatform();
@ -52791,15 +52802,8 @@ function findMatch(versionSpec, stable) {
for (let i = 0; i < candidates.length; i++) {
let candidate = candidates[i];
let version = makeSemver(candidate.version);
// 1.13.0 is advertised as 1.13 preventing being able to match exactly 1.13.0
// since a semver of 1.13 would match latest 1.13
let parts = version.split('.');
if (parts.length == 2) {
version = version + '.0';
}
core.debug(`check ${version} satisfies ${versionSpec}`);
if (semver.satisfies(version, versionSpec) &&
(!stable || candidate.stable === stable)) {
if (semver.satisfies(version, versionSpec)) {
goFile = candidate.files.find(file => {
core.debug(`${file.arch}===${archFilter} && ${file.os}===${platFilter}`);
return file.arch === archFilter && file.os === platFilter;
@ -52835,19 +52839,25 @@ exports.getVersionsDist = getVersionsDist;
// Convert the go version syntax into semver for semver matching
// 1.13.1 => 1.13.1
// 1.13 => 1.13.0
// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
// 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
// 1.10beta1 => 1.10.0-beta.1, 1.10rc1 => 1.10.0-rc.1
// 1.8.5beta1 => 1.8.5-beta.1, 1.8.5rc1 => 1.8.5-rc.1
function makeSemver(version) {
var _a;
version = version.replace('go', '');
version = version.replace('beta', '-beta').replace('rc', '-rc');
version = version.replace('beta', '-beta.').replace('rc', '-rc.');
let parts = version.split('-');
let verPart = parts[0];
let prereleasePart = parts.length > 1 ? `-${parts[1]}` : '';
let verParts = verPart.split('.');
if (verParts.length == 2) {
verPart += '.0';
let 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`);
}
return `${verPart}${prereleasePart}`;
if (!parts[1]) {
return semVersion;
}
const fullVersion = semver.valid(`${semVersion}-${parts[1]}`);
if (!fullVersion) {
throw new Error(`The version: ${version} can't be changed to SemVer notation`);
}
return fullVersion;
}
exports.makeSemver = makeSemver;

331
package-lock.json generated
View file

@ -9,7 +9,7 @@
"version": "1.0.0",
"license": "MIT",
"dependencies": {
"@actions/cache": "^1.0.8",
"@actions/cache": "^2.0.0",
"@actions/core": "^1.6.0",
"@actions/exec": "^1.1.0",
"@actions/glob": "^0.2.0",
@ -20,7 +20,7 @@
},
"devDependencies": {
"@types/jest": "^27.0.2",
"@types/node": "^12.0.4",
"@types/node": "^16.11.25",
"@types/semver": "^6.0.0",
"@zeit/ncc": "^0.21.0",
"jest": "^27.2.5",
@ -32,9 +32,9 @@
}
},
"node_modules/@actions/cache": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/@actions/cache/-/cache-1.0.9.tgz",
"integrity": "sha512-VzqeDyW3kIDdARNQphd1FrzZCiJRuv98aXwM3R+BLe2UvdZXdRqjC/rrytSm4Nv4OJuI8NA1pbhkXIf+a4LFtw==",
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@actions/cache/-/cache-2.0.0.tgz",
"integrity": "sha512-d7n8ul6HjWX6oDrNEPoqn8ZvqyyDhp9Uek6WOxALyxGVsXU+8+ND+viD3UfrXVWfs/GQiqI5Eq4cOozZj0yRFQ==",
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/exec": "^1.0.1",
@ -1303,9 +1303,9 @@
}
},
"node_modules/@types/node": {
"version": "12.12.47",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.47.tgz",
"integrity": "sha512-yzBInQFhdY8kaZmqoL2+3U5dSTMrKaYcb561VU+lDzAYvqt+2lojvBEy+hmpSNuXnPTx7m9+04CzWYOUqWME2A=="
"version": "16.11.25",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.25.tgz",
"integrity": "sha512-NrTwfD7L1RTc2qrHQD4RTTy4p0CO2LatKBEKEds3CaVuhoM/+DJzmWZl5f+ikR8cm8F5mfJxK+9rQq07gRiSjQ=="
},
"node_modules/@types/node-fetch": {
"version": "2.6.1",
@ -3647,9 +3647,9 @@
}
},
"node_modules/minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
"dev": true
},
"node_modules/mkdirp": {
@ -4554,145 +4554,6 @@
}
}
},
"node_modules/ts-jest/node_modules/@jest/types": {
"version": "27.1.0",
"resolved": "https://registry.npmjs.org/@jest/types/-/types-27.1.0.tgz",
"integrity": "sha512-pRP5cLIzN7I7Vp6mHKRSaZD7YpBTK7hawx5si8trMKqk4+WOdK8NEKOTO2G8PKWD1HbKMVckVB6/XHh/olhf2g==",
"dev": true,
"dependencies": {
"@types/istanbul-lib-coverage": "^2.0.0",
"@types/istanbul-reports": "^3.0.0",
"@types/node": "*",
"@types/yargs": "^16.0.0",
"chalk": "^4.0.0"
},
"engines": {
"node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0"
}
},
"node_modules/ts-jest/node_modules/@types/istanbul-reports": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.1.tgz",
"integrity": "sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==",
"dev": true,
"dependencies": {
"@types/istanbul-lib-report": "*"
}
},
"node_modules/ts-jest/node_modules/@types/yargs": {
"version": "16.0.4",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.4.tgz",
"integrity": "sha512-T8Yc9wt/5LbJyCaLiHPReJa0kApcIgJ7Bn735GjItUfh08Z1pJvu8QZqb9s+mMvKV6WUQRV7K2R46YbjMXTTJw==",
"dev": true,
"dependencies": {
"@types/yargs-parser": "*"
}
},
"node_modules/ts-jest/node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/ts-jest/node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/ts-jest/node_modules/ci-info": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.2.0.tgz",
"integrity": "sha512-dVqRX7fLUm8J6FgHJ418XuIgDLZDkYcDFTeL6TA2gt5WlIZUQrrH6EZrNClwT/H0FateUsZkGIOPRrLbP+PR9A==",
"dev": true
},
"node_modules/ts-jest/node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"dependencies": {
"color-name": "~1.1.4"
},
"engines": {
"node": ">=7.0.0"
}
},
"node_modules/ts-jest/node_modules/color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true
},
"node_modules/ts-jest/node_modules/has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true,
"engines": {
"node": ">=8"
}
},
"node_modules/ts-jest/node_modules/is-ci": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/is-ci/-/is-ci-3.0.0.tgz",
"integrity": "sha512-kDXyttuLeslKAHYL/K28F2YkM3x5jvFPEw3yXbRptXydjD9rpLEz+C5K5iutY9ZiUu6AP41JdvRQwF4Iqs4ZCQ==",
"dev": true,
"dependencies": {
"ci-info": "^3.1.1"
},
"bin": {
"is-ci": "bin.js"
}
},
"node_modules/ts-jest/node_modules/jest-util": {
"version": "27.1.0",
"resolved": "https://registry.npmjs.org/jest-util/-/jest-util-27.1.0.tgz",
"integrity": "sha512-edSLD2OneYDKC6gZM1yc+wY/877s/fuJNoM1k3sOEpzFyeptSmke3SLnk1dDHk9CgTA+58mnfx3ew3J11Kes/w==",
"dev": true,
"dependencies": {
"@jest/types": "^27.1.0",
"@types/node": "*",
"chalk": "^4.0.0",
"graceful-fs": "^4.2.4",
"is-ci": "^3.0.0",
"picomatch": "^2.2.3"
},
"engines": {
"node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0"
}
},
"node_modules/ts-jest/node_modules/picomatch": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.0.tgz",
"integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==",
"dev": true,
"engines": {
"node": ">=8.6"
},
"funding": {
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/ts-jest/node_modules/semver": {
"version": "7.3.5",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",
@ -4708,32 +4569,6 @@
"node": ">=10"
}
},
"node_modules/ts-jest/node_modules/supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"dependencies": {
"has-flag": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/ts-jest/node_modules/yargs-parser": {
"version": "20.2.9",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz",
"integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==",
"dev": true,
"engines": {
"node": ">=10"
}
},
"node_modules/tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
},
"node_modules/tunnel": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
@ -5062,9 +4897,9 @@
},
"dependencies": {
"@actions/cache": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/@actions/cache/-/cache-1.0.9.tgz",
"integrity": "sha512-VzqeDyW3kIDdARNQphd1FrzZCiJRuv98aXwM3R+BLe2UvdZXdRqjC/rrytSm4Nv4OJuI8NA1pbhkXIf+a4LFtw==",
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@actions/cache/-/cache-2.0.0.tgz",
"integrity": "sha512-d7n8ul6HjWX6oDrNEPoqn8ZvqyyDhp9Uek6WOxALyxGVsXU+8+ND+viD3UfrXVWfs/GQiqI5Eq4cOozZj0yRFQ==",
"requires": {
"@actions/core": "^1.2.6",
"@actions/exec": "^1.0.1",
@ -6111,9 +5946,9 @@
}
},
"@types/node": {
"version": "12.12.47",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.47.tgz",
"integrity": "sha512-yzBInQFhdY8kaZmqoL2+3U5dSTMrKaYcb561VU+lDzAYvqt+2lojvBEy+hmpSNuXnPTx7m9+04CzWYOUqWME2A=="
"version": "16.11.25",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.25.tgz",
"integrity": "sha512-NrTwfD7L1RTc2qrHQD4RTTy4p0CO2LatKBEKEds3CaVuhoM/+DJzmWZl5f+ikR8cm8F5mfJxK+9rQq07gRiSjQ=="
},
"@types/node-fetch": {
"version": "2.6.1",
@ -7895,9 +7730,9 @@
}
},
"minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
"dev": true
},
"mkdirp": {
@ -8568,112 +8403,6 @@
"yargs-parser": "20.x"
},
"dependencies": {
"@jest/types": {
"version": "27.1.0",
"resolved": "https://registry.npmjs.org/@jest/types/-/types-27.1.0.tgz",
"integrity": "sha512-pRP5cLIzN7I7Vp6mHKRSaZD7YpBTK7hawx5si8trMKqk4+WOdK8NEKOTO2G8PKWD1HbKMVckVB6/XHh/olhf2g==",
"dev": true,
"requires": {
"@types/istanbul-lib-coverage": "^2.0.0",
"@types/istanbul-reports": "^3.0.0",
"@types/node": "*",
"@types/yargs": "^16.0.0",
"chalk": "^4.0.0"
}
},
"@types/istanbul-reports": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.1.tgz",
"integrity": "sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==",
"dev": true,
"requires": {
"@types/istanbul-lib-report": "*"
}
},
"@types/yargs": {
"version": "16.0.4",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.4.tgz",
"integrity": "sha512-T8Yc9wt/5LbJyCaLiHPReJa0kApcIgJ7Bn735GjItUfh08Z1pJvu8QZqb9s+mMvKV6WUQRV7K2R46YbjMXTTJw==",
"dev": true,
"requires": {
"@types/yargs-parser": "*"
}
},
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"ci-info": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.2.0.tgz",
"integrity": "sha512-dVqRX7fLUm8J6FgHJ418XuIgDLZDkYcDFTeL6TA2gt5WlIZUQrrH6EZrNClwT/H0FateUsZkGIOPRrLbP+PR9A==",
"dev": true
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true
},
"is-ci": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/is-ci/-/is-ci-3.0.0.tgz",
"integrity": "sha512-kDXyttuLeslKAHYL/K28F2YkM3x5jvFPEw3yXbRptXydjD9rpLEz+C5K5iutY9ZiUu6AP41JdvRQwF4Iqs4ZCQ==",
"dev": true,
"requires": {
"ci-info": "^3.1.1"
}
},
"jest-util": {
"version": "27.1.0",
"resolved": "https://registry.npmjs.org/jest-util/-/jest-util-27.1.0.tgz",
"integrity": "sha512-edSLD2OneYDKC6gZM1yc+wY/877s/fuJNoM1k3sOEpzFyeptSmke3SLnk1dDHk9CgTA+58mnfx3ew3J11Kes/w==",
"dev": true,
"requires": {
"@jest/types": "^27.1.0",
"@types/node": "*",
"chalk": "^4.0.0",
"graceful-fs": "^4.2.4",
"is-ci": "^3.0.0",
"picomatch": "^2.2.3"
}
},
"picomatch": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.0.tgz",
"integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==",
"dev": true
},
"semver": {
"version": "7.3.5",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",
@ -8682,29 +8411,9 @@
"requires": {
"lru-cache": "^6.0.0"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"requires": {
"has-flag": "^4.0.0"
}
},
"yargs-parser": {
"version": "20.2.9",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz",
"integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==",
"dev": true
}
}
},
"tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
},
"tunnel": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",

View file

@ -5,7 +5,7 @@
"description": "setup go action",
"main": "lib/setup-go.js",
"scripts": {
"build": "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-check": "prettier --check **/*.ts",
"test": "jest --coverage",
@ -23,7 +23,7 @@
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@actions/cache": "^1.0.8",
"@actions/cache": "^2.0.0",
"@actions/core": "^1.6.0",
"@actions/exec": "^1.1.0",
"@actions/glob": "^0.2.0",
@ -34,7 +34,7 @@
},
"devDependencies": {
"@types/jest": "^27.0.2",
"@types/node": "^12.0.4",
"@types/node": "^16.11.25",
"@types/semver": "^6.0.0",
"@zeit/ncc": "^0.21.0",
"jest": "^27.2.5",

View file

@ -21,10 +21,13 @@ export async function run() {
}
const cachePackages = async () => {
const cachingFlag = core.getBooleanInput('cache');
if (!cachingFlag) return;
const cacheInput = core.getInput('cache');
if (!cacheInput) {
return;
}
const packageManager = core.getInput('package-manager');
const packageManager =
cacheInput.toUpperCase() === 'TRUE' ? 'default' : cacheInput;
const state = core.getState(State.CacheMatchedKey);
const primaryKey = core.getState(State.CachePrimaryKey);

View file

@ -24,8 +24,9 @@ export const getPackageManagerInfo = async (packageManager: string) => {
`It's not possible to use ${packageManager}, please, check correctness of the package manager name spelling.`
);
}
const obtainedPackageManager = supportedPackageManagers[packageManager];
return supportedPackageManagers[packageManager];
return obtainedPackageManager;
};
export const getCacheDirectoryPath = async (

View file

@ -30,7 +30,6 @@ export interface IGoVersionInfo {
export async function getGo(
versionSpec: string,
stable: boolean,
checkLatest: boolean,
auth: string | undefined
) {
@ -41,7 +40,7 @@ export async function getGo(
core.info('Attempting to resolve the latest version from the manifest...');
const resolvedVersion = await resolveVersionFromManifest(
versionSpec,
stable,
true,
auth
);
if (resolvedVersion) {
@ -68,7 +67,7 @@ export async function getGo(
// Try download from internal distribution (popular versions only)
//
try {
info = await getInfoFromManifest(versionSpec, stable, auth);
info = await getInfoFromManifest(versionSpec, true, auth);
if (info) {
downloadPath = await installGoVersion(info, auth);
} else {
@ -95,7 +94,7 @@ export async function getGo(
// Download from storage.googleapis.com
//
if (!downloadPath) {
info = await getInfoFromDist(versionSpec, stable);
info = await getInfoFromDist(versionSpec);
if (!info) {
throw new Error(
`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
@ -191,11 +190,10 @@ export async function getInfoFromManifest(
}
async function getInfoFromDist(
versionSpec: string,
stable: boolean
versionSpec: string
): Promise<IGoVersionInfo | null> {
let version: IGoVersion | undefined;
version = await findMatch(versionSpec, stable);
version = await findMatch(versionSpec);
if (!version) {
return null;
}
@ -211,8 +209,7 @@ async function getInfoFromDist(
}
export async function findMatch(
versionSpec: string,
stable: boolean
versionSpec: string
): Promise<IGoVersion | undefined> {
let archFilter = sys.getArch();
let platFilter = sys.getPlatform();
@ -233,18 +230,8 @@ export async function findMatch(
let candidate: IGoVersion = candidates[i];
let version = makeSemver(candidate.version);
// 1.13.0 is advertised as 1.13 preventing being able to match exactly 1.13.0
// since a semver of 1.13 would match latest 1.13
let parts: string[] = version.split('.');
if (parts.length == 2) {
version = version + '.0';
}
core.debug(`check ${version} satisfies ${versionSpec}`);
if (
semver.satisfies(version, versionSpec) &&
(!stable || candidate.stable === stable)
) {
if (semver.satisfies(version, versionSpec)) {
goFile = candidate.files.find(file => {
core.debug(
`${file.arch}===${archFilter} && ${file.os}===${platFilter}`
@ -284,20 +271,30 @@ export async function getVersionsDist(
// Convert the go version syntax into semver for semver matching
// 1.13.1 => 1.13.1
// 1.13 => 1.13.0
// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
// 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
// 1.10beta1 => 1.10.0-beta.1, 1.10rc1 => 1.10.0-rc.1
// 1.8.5beta1 => 1.8.5-beta.1, 1.8.5rc1 => 1.8.5-rc.1
export function makeSemver(version: string): string {
version = version.replace('go', '');
version = version.replace('beta', '-beta').replace('rc', '-rc');
version = version.replace('beta', '-beta.').replace('rc', '-rc.');
let parts = version.split('-');
let verPart: string = parts[0];
let prereleasePart = parts.length > 1 ? `-${parts[1]}` : '';
let verParts: string[] = verPart.split('.');
if (verParts.length == 2) {
verPart += '.0';
let semVersion = semver.coerce(parts[0])?.version;
if (!semVersion) {
throw new Error(
`The version: ${version} can't be changed to SemVer notation`
);
}
return `${verPart}${prereleasePart}`;
if (!parts[1]) {
return semVersion;
}
const fullVersion = semver.valid(`${semVersion}-${parts[1]}`);
if (!fullVersion) {
throw new Error(
`The version: ${version} can't be changed to SemVer notation`
);
}
return fullVersion;
}

View file

@ -1,6 +1,7 @@
import * as core from '@actions/core';
import * as io from '@actions/io';
import * as installer from './installer';
import * as semver from 'semver';
import path from 'path';
import {restoreCache} from './cache-restore';
import cp from 'child_process';
@ -15,29 +16,26 @@ export async function run() {
//
let versionSpec = core.getInput('go-version');
// stable will be true unless false is the exact input
// since getting unstable versions should be explicit
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
const cache = core.getBooleanInput('cache');
core.info(`Setup go ${stable ? 'stable' : ''} version spec ${versionSpec}`);
const cache = core.getInput('cache');
core.info(`Setup go version spec ${versionSpec}`);
if (versionSpec) {
let token = core.getInput('token');
let auth = !token || isGhes() ? undefined : `token ${token}`;
const checkLatest = core.getBooleanInput('check-latest');
const installDir = await installer.getGo(
versionSpec,
stable,
checkLatest,
auth
);
const installDir = await installer.getGo(versionSpec, checkLatest, auth);
core.exportVariable('GOROOT', installDir);
core.addPath(path.join(installDir, 'bin'));
core.info('Added go to the path');
const version = installer.makeSemver(versionSpec);
// Go versions less than 1.9 require GOROOT to be set
if (semver.lt(version, '1.9.0')) {
core.info('Setting GOROOT for Go version < 1.9');
core.exportVariable('GOROOT', installDir);
}
let added = await addBinToPath();
core.debug(`add bin ${added}`);
core.info(`Successfully setup go version ${versionSpec}`);
@ -47,7 +45,7 @@ export async function run() {
if (isGhes()) {
throw new Error('Caching is not supported on GHES');
}
const packageManager = core.getInput('package-manager');
const packageManager = cache.toUpperCase() === 'TRUE' ? 'default' : cache;
const cacheDependencyPath = core.getInput('cache-dependency-path');
await restoreCache(packageManager, cacheDependencyPath);
}
@ -86,13 +84,13 @@ export async function addBinToPath(): Promise<boolean> {
if (!fs.existsSync(gp)) {
// some of the hosted images have go install but not profile dir
core.debug(`creating ${gp}`);
io.mkdirP(gp);
await io.mkdirP(gp);
}
let bp = path.join(gp, 'bin');
if (!fs.existsSync(bp)) {
core.debug(`creating ${bp}`);
io.mkdirP(bp);
await io.mkdirP(bp);
}
core.addPath(bp);

View file

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