mirror of https://github.com/actions/setup-go.git
Apply PR suggestions
This commit is contained in:
parent
9d73e829e4
commit
a29996aa9d
|
@ -25,44 +25,10 @@ jobs:
|
||||||
with:
|
with:
|
||||||
go-version: stable
|
go-version: stable
|
||||||
architecture: x64
|
architecture: x64
|
||||||
check-latest: true
|
|
||||||
- name: Verify Go
|
- name: Verify Go
|
||||||
run: go version
|
run: go version
|
||||||
|
|
||||||
oldstable:
|
oldstable:
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Setup Go and check latest
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
go-version: oldstable
|
|
||||||
architecture: x64
|
|
||||||
check-latest: true
|
|
||||||
- name: Verify Go
|
|
||||||
run: go version
|
|
||||||
|
|
||||||
stable-no-check-latest:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Setup Go and check latest
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
go-version: stable
|
|
||||||
architecture: x64
|
|
||||||
- name: Verify Go
|
|
||||||
run: go version
|
|
||||||
|
|
||||||
oldstable-no-check-latest:
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
|
10
README.md
10
README.md
|
@ -16,7 +16,7 @@ The V3 edition of the action offers:
|
||||||
- Proxy support
|
- Proxy support
|
||||||
- Check latest version
|
- Check latest version
|
||||||
- Caching packages dependencies
|
- Caching packages dependencies
|
||||||
- stable and olstable aliases
|
- stable and oldstable aliases
|
||||||
- Bug Fixes (including issues around version matching and semver)
|
- 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).
|
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).
|
||||||
|
@ -99,7 +99,11 @@ steps:
|
||||||
|
|
||||||
## Using stable/oldstable aliases
|
## Using stable/oldstable aliases
|
||||||
|
|
||||||
Given the fact that Go doesn't use semver syntax ranges, and that many Go projects want to run tests based on `stable` and `oldstable` aliases, these aliases are introduced in the action as possible values of the input `go-version`. When alias `stable` is provided, and `check-latest` input is set to `true` action will get the latest stable version from the [`go-versions`](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository manifest. When `check-latest` is not provided, or set to false, the action will resolve `stable` as the most recent present version from the runners tool cache directory. In case of the `oldstable` alias, if current release is 1.19.x, action will resolve version as 1.18.x, where x is the latest patch release. The `check-latest` rules described above will apply for `oldstable` as well.
|
If `stable` is provided, action will get the latest stable version from the [`go-versions`](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository manifest.
|
||||||
|
|
||||||
|
If `oldstable` is provided, when current release is 1.19.x, action will resolve version as 1.18.x, where x is the latest patch release.
|
||||||
|
|
||||||
|
**Note:** using these aliases will result in same version as using corresponding minor release with `check-latest` input set to `true`
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
|
@ -107,7 +111,6 @@ steps:
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 'stable'
|
go-version: 'stable'
|
||||||
check-latest: true
|
|
||||||
- run: go run hello.go
|
- run: go run hello.go
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -117,7 +120,6 @@ steps:
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 'oldstable'
|
go-version: 'oldstable'
|
||||||
check-latest: true
|
|
||||||
- run: go run hello.go
|
- run: go run hello.go
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ describe('setup-go', () => {
|
||||||
cacheSpy = jest.spyOn(tc, 'cacheDir');
|
cacheSpy = jest.spyOn(tc, 'cacheDir');
|
||||||
getSpy = jest.spyOn(im, 'getVersionsDist');
|
getSpy = jest.spyOn(im, 'getVersionsDist');
|
||||||
getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
|
getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
|
||||||
getAllVersionsSpy = jest.spyOn(im, 'getAllManifestReleases');
|
getAllVersionsSpy = jest.spyOn(im, 'getManifest');
|
||||||
|
|
||||||
// io
|
// io
|
||||||
whichSpy = jest.spyOn(io, 'which');
|
whichSpy = jest.spyOn(io, 'which');
|
||||||
|
@ -929,5 +929,32 @@ use .
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
|
it.each(['stable', 'oldstable'])(
|
||||||
|
'acquires latest go version with %s go-version input',
|
||||||
|
async (alias: string) => {
|
||||||
|
const arch = 'x64';
|
||||||
|
os.platform = 'darwin';
|
||||||
|
os.arch = arch;
|
||||||
|
|
||||||
|
inputs['go-version'] = alias;
|
||||||
|
inputs['architecture'] = os.arch;
|
||||||
|
|
||||||
|
// ... but not in the local cache
|
||||||
|
findSpy.mockImplementation(() => '');
|
||||||
|
|
||||||
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
|
let toolPath = path.normalize(`/cache/go/${alias}/${arch}`);
|
||||||
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
|
|
||||||
|
await main.run();
|
||||||
|
|
||||||
|
const releaseIndex = alias === 'stable' ? 0 : 1;
|
||||||
|
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
`${alias} version resolved as ${goTestManifest[releaseIndex].version}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -63213,7 +63213,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.parseGoVersionFile = exports.makeSemver = exports.getVersionsDist = exports.findMatch = exports.getInfoFromManifest = exports.getAllToolCacheReleases = exports.getAllManifestReleases = exports.extractGoArchive = exports.resolveVersionFromManifest = exports.getGo = void 0;
|
exports.parseGoVersionFile = exports.makeSemver = exports.getVersionsDist = exports.findMatch = exports.getInfoFromManifest = exports.getManifest = exports.extractGoArchive = exports.resolveVersionFromManifest = exports.getGo = void 0;
|
||||||
const tc = __importStar(__nccwpck_require__(7784));
|
const tc = __importStar(__nccwpck_require__(7784));
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const path = __importStar(__nccwpck_require__(1017));
|
const path = __importStar(__nccwpck_require__(1017));
|
||||||
|
@ -63222,12 +63222,13 @@ const httpm = __importStar(__nccwpck_require__(6255));
|
||||||
const sys = __importStar(__nccwpck_require__(4300));
|
const sys = __importStar(__nccwpck_require__(4300));
|
||||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
const os_1 = __importDefault(__nccwpck_require__(2037));
|
const os_1 = __importDefault(__nccwpck_require__(2037));
|
||||||
function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch(), releases) {
|
const utils_1 = __nccwpck_require__(1314);
|
||||||
|
function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch(), manifest) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let osPlat = os_1.default.platform();
|
let osPlat = os_1.default.platform();
|
||||||
if (checkLatest) {
|
if (checkLatest) {
|
||||||
core.info('Attempting to resolve the latest version from the manifest...');
|
core.info('Attempting to resolve the latest version from the manifest...');
|
||||||
const resolvedVersion = yield resolveVersionFromManifest(versionSpec, true, auth, arch, releases);
|
const resolvedVersion = yield resolveVersionFromManifest(versionSpec, true, auth, arch, manifest);
|
||||||
if (resolvedVersion) {
|
if (resolvedVersion) {
|
||||||
versionSpec = resolvedVersion;
|
versionSpec = resolvedVersion;
|
||||||
core.info(`Resolved as '${versionSpec}'`);
|
core.info(`Resolved as '${versionSpec}'`);
|
||||||
|
@ -63236,6 +63237,10 @@ function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch(), relea
|
||||||
core.info(`Failed to resolve version ${versionSpec} from manifest`);
|
core.info(`Failed to resolve version ${versionSpec} from manifest`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (versionSpec === utils_1.StableReleaseAlias.Stable ||
|
||||||
|
versionSpec === utils_1.StableReleaseAlias.OldStable) {
|
||||||
|
versionSpec = yield resolveStableVersionInput(versionSpec, auth, arch, manifest);
|
||||||
|
}
|
||||||
// check cache
|
// check cache
|
||||||
let toolPath;
|
let toolPath;
|
||||||
toolPath = tc.find('go', versionSpec, arch);
|
toolPath = tc.find('go', versionSpec, arch);
|
||||||
|
@ -63290,10 +63295,10 @@ function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch(), relea
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.getGo = getGo;
|
exports.getGo = getGo;
|
||||||
function resolveVersionFromManifest(versionSpec, stable, auth, arch, releases) {
|
function resolveVersionFromManifest(versionSpec, stable, auth, arch, manifest) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
const info = yield getInfoFromManifest(versionSpec, stable, auth, arch, releases);
|
const info = yield getInfoFromManifest(versionSpec, stable, auth, arch, manifest);
|
||||||
return info === null || info === void 0 ? void 0 : info.resolvedVersion;
|
return info === null || info === void 0 ? void 0 : info.resolvedVersion;
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
|
@ -63337,24 +63342,21 @@ function extractGoArchive(archivePath) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.extractGoArchive = extractGoArchive;
|
exports.extractGoArchive = extractGoArchive;
|
||||||
function getAllManifestReleases(auth) {
|
function getManifest(auth) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
return tc.getManifestFromRepo('actions', 'go-versions', auth, 'main');
|
return tc.getManifestFromRepo('actions', 'go-versions', auth, 'main');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.getAllManifestReleases = getAllManifestReleases;
|
exports.getManifest = getManifest;
|
||||||
function getAllToolCacheReleases(arch = os_1.default.arch()) {
|
function getInfoFromManifest(versionSpec, stable, auth, arch = os_1.default.arch(), manifest) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
return tc.findAllVersions('go', arch);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.getAllToolCacheReleases = getAllToolCacheReleases;
|
|
||||||
function getInfoFromManifest(versionSpec, stable, auth, arch = os_1.default.arch(), releases) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let info = null;
|
let info = null;
|
||||||
releases = releases ? releases : yield getAllManifestReleases(auth);
|
if (!manifest) {
|
||||||
|
core.debug('No manifest cached');
|
||||||
|
manifest = yield getManifest(auth);
|
||||||
|
}
|
||||||
core.info(`matching ${versionSpec}...`);
|
core.info(`matching ${versionSpec}...`);
|
||||||
let rel = yield tc.findFromManifest(versionSpec, stable, releases, arch);
|
const rel = yield tc.findFromManifest(versionSpec, stable, manifest, arch);
|
||||||
if (rel && rel.files.length > 0) {
|
if (rel && rel.files.length > 0) {
|
||||||
info = {};
|
info = {};
|
||||||
info.type = 'manifest';
|
info.type = 'manifest';
|
||||||
|
@ -63465,6 +63467,29 @@ function parseGoVersionFile(versionFilePath) {
|
||||||
return contents.trim();
|
return contents.trim();
|
||||||
}
|
}
|
||||||
exports.parseGoVersionFile = parseGoVersionFile;
|
exports.parseGoVersionFile = parseGoVersionFile;
|
||||||
|
function resolveStableVersionInput(versionSpec, auth, arch = os_1.default.arch(), manifest) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (!manifest) {
|
||||||
|
core.debug('No manifest cached');
|
||||||
|
manifest = yield getManifest(auth);
|
||||||
|
}
|
||||||
|
const releases = manifest.map(release => release.version);
|
||||||
|
if (versionSpec === utils_1.StableReleaseAlias.Stable) {
|
||||||
|
core.info(`stable version resolved as ${releases[0]}`);
|
||||||
|
return releases[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const versions = releases.map(release => `${semver.major(release)}.${semver.minor(release)}`);
|
||||||
|
const uniqueVersions = Array.from(new Set(versions));
|
||||||
|
const oldstableVersion = yield getInfoFromManifest(uniqueVersions[1], true, auth, arch, manifest);
|
||||||
|
core.info(`oldstable version resolved as ${oldstableVersion === null || oldstableVersion === void 0 ? void 0 : oldstableVersion.resolvedVersion}`);
|
||||||
|
if (!oldstableVersion) {
|
||||||
|
return versionSpec;
|
||||||
|
}
|
||||||
|
return oldstableVersion.resolvedVersion;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -63517,7 +63542,6 @@ const cache_utils_1 = __nccwpck_require__(1678);
|
||||||
const child_process_1 = __importDefault(__nccwpck_require__(2081));
|
const child_process_1 = __importDefault(__nccwpck_require__(2081));
|
||||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
const os_1 = __importDefault(__nccwpck_require__(2037));
|
const os_1 = __importDefault(__nccwpck_require__(2037));
|
||||||
const utils_1 = __nccwpck_require__(1314);
|
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
|
@ -63525,7 +63549,7 @@ function run() {
|
||||||
// versionSpec is optional. If supplied, install / use from the tool cache
|
// versionSpec is optional. If supplied, install / use from the tool cache
|
||||||
// If not supplied then problem matchers will still be setup. Useful for self-hosted.
|
// If not supplied then problem matchers will still be setup. Useful for self-hosted.
|
||||||
//
|
//
|
||||||
let versionSpec = resolveVersionInput();
|
const versionSpec = resolveVersionInput();
|
||||||
const cache = core.getBooleanInput('cache');
|
const cache = core.getBooleanInput('cache');
|
||||||
core.info(`Setup go version spec ${versionSpec}`);
|
core.info(`Setup go version spec ${versionSpec}`);
|
||||||
let arch = core.getInput('architecture');
|
let arch = core.getInput('architecture');
|
||||||
|
@ -63535,13 +63559,9 @@ function run() {
|
||||||
if (versionSpec) {
|
if (versionSpec) {
|
||||||
let token = core.getInput('token');
|
let token = core.getInput('token');
|
||||||
let auth = !token ? undefined : `token ${token}`;
|
let auth = !token ? undefined : `token ${token}`;
|
||||||
const releases = yield installer.getAllManifestReleases(auth);
|
const manifest = yield installer.getManifest(auth);
|
||||||
const checkLatest = core.getBooleanInput('check-latest');
|
const checkLatest = core.getBooleanInput('check-latest');
|
||||||
if (versionSpec === utils_1.StableReleaseAlias.Stable ||
|
const installDir = yield installer.getGo(versionSpec, checkLatest, auth, arch, manifest);
|
||||||
versionSpec === utils_1.StableReleaseAlias.OldStable) {
|
|
||||||
versionSpec = yield resolveStableVersionInput(versionSpec, auth, arch, releases, checkLatest);
|
|
||||||
}
|
|
||||||
const installDir = yield installer.getGo(versionSpec, checkLatest, auth, arch, releases);
|
|
||||||
core.addPath(path_1.default.join(installDir, 'bin'));
|
core.addPath(path_1.default.join(installDir, 'bin'));
|
||||||
core.info('Added go to the path');
|
core.info('Added go to the path');
|
||||||
const version = installer.makeSemver(versionSpec);
|
const version = installer.makeSemver(versionSpec);
|
||||||
|
@ -63633,39 +63653,6 @@ function resolveVersionInput() {
|
||||||
}
|
}
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
function resolveStableVersionInput(versionSpec, auth, arch = os_1.default.arch(), manifestReleases, checkLatest = false) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
let releases;
|
|
||||||
if (checkLatest) {
|
|
||||||
releases = manifestReleases.map(release => release.version);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
releases = yield installer.getAllToolCacheReleases(arch);
|
|
||||||
releases.reverse();
|
|
||||||
}
|
|
||||||
if (versionSpec === utils_1.StableReleaseAlias.Stable) {
|
|
||||||
core.info(`Stable version resolved as ${releases[0]}`);
|
|
||||||
return releases[0];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const versions = releases.map(release => `${semver.major(release)}.${semver.minor(release)}`);
|
|
||||||
const uniqueVersions = Array.from(new Set(versions));
|
|
||||||
let oldstableVersion;
|
|
||||||
if (checkLatest) {
|
|
||||||
oldstableVersion = yield installer.getInfoFromManifest(uniqueVersions[1], true, auth, arch, manifestReleases);
|
|
||||||
oldstableVersion = oldstableVersion === null || oldstableVersion === void 0 ? void 0 : oldstableVersion.resolvedVersion;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
oldstableVersion = releases[1];
|
|
||||||
}
|
|
||||||
core.info(`Oldstable version resolved as ${oldstableVersion}`);
|
|
||||||
if (!oldstableVersion) {
|
|
||||||
return versionSpec;
|
|
||||||
}
|
|
||||||
return oldstableVersion;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
|
@ -6,6 +6,7 @@ import * as httpm from '@actions/http-client';
|
||||||
import * as sys from './system';
|
import * as sys from './system';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import os, {arch} from 'os';
|
import os, {arch} from 'os';
|
||||||
|
import {StableReleaseAlias} from './utils';
|
||||||
|
|
||||||
type InstallationType = 'dist' | 'manifest';
|
type InstallationType = 'dist' | 'manifest';
|
||||||
|
|
||||||
|
@ -34,7 +35,7 @@ export async function getGo(
|
||||||
checkLatest: boolean,
|
checkLatest: boolean,
|
||||||
auth: string | undefined,
|
auth: string | undefined,
|
||||||
arch = os.arch(),
|
arch = os.arch(),
|
||||||
releases: tc.IToolRelease[] | undefined
|
manifest: tc.IToolRelease[] | undefined
|
||||||
) {
|
) {
|
||||||
let osPlat: string = os.platform();
|
let osPlat: string = os.platform();
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ export async function getGo(
|
||||||
true,
|
true,
|
||||||
auth,
|
auth,
|
||||||
arch,
|
arch,
|
||||||
releases
|
manifest
|
||||||
);
|
);
|
||||||
if (resolvedVersion) {
|
if (resolvedVersion) {
|
||||||
versionSpec = resolvedVersion;
|
versionSpec = resolvedVersion;
|
||||||
|
@ -55,6 +56,18 @@ export async function getGo(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
versionSpec === StableReleaseAlias.Stable ||
|
||||||
|
versionSpec === StableReleaseAlias.OldStable
|
||||||
|
) {
|
||||||
|
versionSpec = await resolveStableVersionInput(
|
||||||
|
versionSpec,
|
||||||
|
auth,
|
||||||
|
arch,
|
||||||
|
manifest
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// check cache
|
// check cache
|
||||||
let toolPath: string;
|
let toolPath: string;
|
||||||
toolPath = tc.find('go', versionSpec, arch);
|
toolPath = tc.find('go', versionSpec, arch);
|
||||||
|
@ -121,7 +134,7 @@ export async function resolveVersionFromManifest(
|
||||||
stable: boolean,
|
stable: boolean,
|
||||||
auth: string | undefined,
|
auth: string | undefined,
|
||||||
arch: string,
|
arch: string,
|
||||||
releases: tc.IToolRelease[] | undefined
|
manifest: tc.IToolRelease[] | undefined
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
try {
|
try {
|
||||||
const info = await getInfoFromManifest(
|
const info = await getInfoFromManifest(
|
||||||
|
@ -129,7 +142,7 @@ export async function resolveVersionFromManifest(
|
||||||
stable,
|
stable,
|
||||||
auth,
|
auth,
|
||||||
arch,
|
arch,
|
||||||
releases
|
manifest
|
||||||
);
|
);
|
||||||
return info?.resolvedVersion;
|
return info?.resolvedVersion;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -183,27 +196,26 @@ export async function extractGoArchive(archivePath: string): Promise<string> {
|
||||||
return extPath;
|
return extPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllManifestReleases(auth: string | undefined) {
|
export async function getManifest(auth: string | undefined) {
|
||||||
return tc.getManifestFromRepo('actions', 'go-versions', auth, 'main');
|
return tc.getManifestFromRepo('actions', 'go-versions', auth, 'main');
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllToolCacheReleases(arch = os.arch()) {
|
|
||||||
return tc.findAllVersions('go', arch);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getInfoFromManifest(
|
export async function getInfoFromManifest(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
stable: boolean,
|
stable: boolean,
|
||||||
auth: string | undefined,
|
auth: string | undefined,
|
||||||
arch = os.arch(),
|
arch = os.arch(),
|
||||||
releases?: tc.IToolRelease[] | undefined
|
manifest?: tc.IToolRelease[] | undefined
|
||||||
): Promise<IGoVersionInfo | null> {
|
): Promise<IGoVersionInfo | null> {
|
||||||
let info: IGoVersionInfo | null = null;
|
let info: IGoVersionInfo | null = null;
|
||||||
releases = releases ? releases : await getAllManifestReleases(auth);
|
if (!manifest) {
|
||||||
|
core.debug('No manifest cached');
|
||||||
|
manifest = await getManifest(auth);
|
||||||
|
}
|
||||||
|
|
||||||
core.info(`matching ${versionSpec}...`);
|
core.info(`matching ${versionSpec}...`);
|
||||||
|
|
||||||
let rel = await tc.findFromManifest(versionSpec, stable, releases, arch);
|
const rel = await tc.findFromManifest(versionSpec, stable, manifest, arch);
|
||||||
|
|
||||||
if (rel && rel.files.length > 0) {
|
if (rel && rel.files.length > 0) {
|
||||||
info = <IGoVersionInfo>{};
|
info = <IGoVersionInfo>{};
|
||||||
|
@ -341,3 +353,46 @@ export function parseGoVersionFile(versionFilePath: string): string {
|
||||||
|
|
||||||
return contents.trim();
|
return contents.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function resolveStableVersionInput(
|
||||||
|
versionSpec: string,
|
||||||
|
auth: string | undefined,
|
||||||
|
arch = os.arch(),
|
||||||
|
manifest: tc.IToolRelease[] | undefined
|
||||||
|
): Promise<string> {
|
||||||
|
if (!manifest) {
|
||||||
|
core.debug('No manifest cached');
|
||||||
|
manifest = await getManifest(auth);
|
||||||
|
}
|
||||||
|
|
||||||
|
const releases = manifest.map(release => release.version);
|
||||||
|
|
||||||
|
if (versionSpec === StableReleaseAlias.Stable) {
|
||||||
|
core.info(`stable version resolved as ${releases[0]}`);
|
||||||
|
|
||||||
|
return releases[0];
|
||||||
|
} else {
|
||||||
|
const versions = releases.map(
|
||||||
|
release => `${semver.major(release)}.${semver.minor(release)}`
|
||||||
|
);
|
||||||
|
const uniqueVersions = Array.from(new Set(versions));
|
||||||
|
|
||||||
|
const oldstableVersion = await getInfoFromManifest(
|
||||||
|
uniqueVersions[1],
|
||||||
|
true,
|
||||||
|
auth,
|
||||||
|
arch,
|
||||||
|
manifest
|
||||||
|
);
|
||||||
|
|
||||||
|
core.info(
|
||||||
|
`oldstable version resolved as ${oldstableVersion?.resolvedVersion}`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!oldstableVersion) {
|
||||||
|
return versionSpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
return oldstableVersion.resolvedVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
69
src/main.ts
69
src/main.ts
|
@ -17,7 +17,7 @@ export async function run() {
|
||||||
// versionSpec is optional. If supplied, install / use from the tool cache
|
// versionSpec is optional. If supplied, install / use from the tool cache
|
||||||
// If not supplied then problem matchers will still be setup. Useful for self-hosted.
|
// If not supplied then problem matchers will still be setup. Useful for self-hosted.
|
||||||
//
|
//
|
||||||
let versionSpec = resolveVersionInput();
|
const versionSpec = resolveVersionInput();
|
||||||
|
|
||||||
const cache = core.getBooleanInput('cache');
|
const cache = core.getBooleanInput('cache');
|
||||||
core.info(`Setup go version spec ${versionSpec}`);
|
core.info(`Setup go version spec ${versionSpec}`);
|
||||||
|
@ -32,29 +32,16 @@ export async function run() {
|
||||||
let token = core.getInput('token');
|
let token = core.getInput('token');
|
||||||
let auth = !token ? undefined : `token ${token}`;
|
let auth = !token ? undefined : `token ${token}`;
|
||||||
|
|
||||||
const releases = await installer.getAllManifestReleases(auth);
|
const manifest = await installer.getManifest(auth);
|
||||||
|
|
||||||
const checkLatest = core.getBooleanInput('check-latest');
|
const checkLatest = core.getBooleanInput('check-latest');
|
||||||
|
|
||||||
if (
|
|
||||||
versionSpec === StableReleaseAlias.Stable ||
|
|
||||||
versionSpec === StableReleaseAlias.OldStable
|
|
||||||
) {
|
|
||||||
versionSpec = await resolveStableVersionInput(
|
|
||||||
versionSpec,
|
|
||||||
auth,
|
|
||||||
arch,
|
|
||||||
releases,
|
|
||||||
checkLatest
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const installDir = await installer.getGo(
|
const installDir = await installer.getGo(
|
||||||
versionSpec,
|
versionSpec,
|
||||||
checkLatest,
|
checkLatest,
|
||||||
auth,
|
auth,
|
||||||
arch,
|
arch,
|
||||||
releases
|
manifest
|
||||||
);
|
);
|
||||||
|
|
||||||
core.addPath(path.join(installDir, 'bin'));
|
core.addPath(path.join(installDir, 'bin'));
|
||||||
|
@ -162,53 +149,3 @@ function resolveVersionInput(): string {
|
||||||
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function resolveStableVersionInput(
|
|
||||||
versionSpec: string,
|
|
||||||
auth: string | undefined,
|
|
||||||
arch = os.arch(),
|
|
||||||
manifestReleases: IToolRelease[],
|
|
||||||
checkLatest = false
|
|
||||||
): Promise<string> {
|
|
||||||
let releases;
|
|
||||||
if (checkLatest) {
|
|
||||||
releases = manifestReleases.map(release => release.version);
|
|
||||||
} else {
|
|
||||||
releases = await installer.getAllToolCacheReleases(arch);
|
|
||||||
releases.reverse();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (versionSpec === StableReleaseAlias.Stable) {
|
|
||||||
core.info(`Stable version resolved as ${releases[0]}`);
|
|
||||||
|
|
||||||
return releases[0];
|
|
||||||
} else {
|
|
||||||
const versions = releases.map(
|
|
||||||
release => `${semver.major(release)}.${semver.minor(release)}`
|
|
||||||
);
|
|
||||||
const uniqueVersions = Array.from(new Set(versions));
|
|
||||||
|
|
||||||
let oldstableVersion;
|
|
||||||
|
|
||||||
if (checkLatest) {
|
|
||||||
oldstableVersion = await installer.getInfoFromManifest(
|
|
||||||
uniqueVersions[1],
|
|
||||||
true,
|
|
||||||
auth,
|
|
||||||
arch,
|
|
||||||
manifestReleases
|
|
||||||
);
|
|
||||||
oldstableVersion = oldstableVersion?.resolvedVersion;
|
|
||||||
} else {
|
|
||||||
oldstableVersion = releases[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
core.info(`Oldstable version resolved as ${oldstableVersion}`);
|
|
||||||
|
|
||||||
if (!oldstableVersion) {
|
|
||||||
return versionSpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
return oldstableVersion;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue