Merge branch 'modules-caching' into modules-caching-tests

This commit is contained in:
Ivan Zosimov 2022-03-30 11:00:12 +02:00
commit 1a1c412f7e
17 changed files with 212 additions and 453 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,12 +11,11 @@ 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
- Bug Fixes (including issues around version matching and semver)
@ -25,21 +24,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 +66,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,8 +84,8 @@ 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
@ -86,9 +102,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 +113,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

@ -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');
@ -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'
runs:
using: 'node12'
using: 'node16'
main: 'dist/setup/index.js'
post: 'dist/cache-save/index.js'
post-if: success()

View file

@ -3944,7 +3944,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);
@ -46368,10 +46369,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);

63
dist/setup/index.js vendored
View file

@ -3702,16 +3702,13 @@ 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);
const installDir = yield installer.getGo(versionSpec, checkLatest, auth);
core.exportVariable('GOROOT', installDir);
core.addPath(path_1.default.join(installDir, 'bin'));
core.info('Added go to the path');
@ -3723,7 +3720,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);
}
@ -4188,7 +4185,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);
@ -52460,7 +52458,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 +52630,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 +52660,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 +52683,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 +52758,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 +52774,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 +52789,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 +52826,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;

312
package-lock.json generated
View file

@ -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",
@ -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",
@ -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,21 +8411,6 @@
"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
}
}
},

View file

@ -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

@ -25,8 +25,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