diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 10c4ddceb..e6e029d98 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -60313,7 +60313,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; @@ -60418,7 +60418,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; @@ -60437,7 +60437,7 @@ const cache = __importStar(__nccwpck_require__(7799)); const core = __importStar(__nccwpck_require__(2186)); const exec = __importStar(__nccwpck_require__(1514)); const package_managers_1 = __nccwpck_require__(6663); -exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () { +const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () { let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true }); if (exitCode) { stderr = !stderr.trim() @@ -60447,14 +60447,16 @@ exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, fu } return stdout.trim(); }); -exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () { +exports.getCommandOutput = getCommandOutput; +const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () { 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.`); } const obtainedPackageManager = package_managers_1.supportedPackageManagers[packageManager]; return obtainedPackageManager; }); -exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () { +exports.getPackageManagerInfo = getPackageManagerInfo; +const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () { let pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command))); const emptyPaths = pathList.filter(item => !item); if (emptyPaths.length) { @@ -60462,6 +60464,7 @@ exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0 } return pathList; }); +exports.getCacheDirectoryPath = getCacheDirectoryPath; function isGhes() { const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; diff --git a/dist/setup/index.js b/dist/setup/index.js index 06b72aa12..04c53eeeb 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -63007,7 +63007,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; @@ -63032,7 +63032,7 @@ const path_1 = __importDefault(__nccwpck_require__(1017)); const fs_1 = __importDefault(__nccwpck_require__(7147)); const constants_1 = __nccwpck_require__(9042); const cache_utils_1 = __nccwpck_require__(1678); -exports.restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () { +const restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () { const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager); const platform = process.env.RUNNER_OS; const cachePaths = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo); @@ -63056,6 +63056,7 @@ exports.restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __a core.saveState(constants_1.State.CacheMatchedKey, cacheKey); core.info(`Cache restored from key: ${cacheKey}`); }); +exports.restoreCache = restoreCache; const findDependencyFile = (packageManager) => { let dependencyFile = packageManager.dependencyFilePattern; const workspace = process.env.GITHUB_WORKSPACE; @@ -63090,7 +63091,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; @@ -63109,7 +63110,7 @@ const cache = __importStar(__nccwpck_require__(7799)); const core = __importStar(__nccwpck_require__(2186)); const exec = __importStar(__nccwpck_require__(1514)); const package_managers_1 = __nccwpck_require__(6663); -exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () { +const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () { let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true }); if (exitCode) { stderr = !stderr.trim() @@ -63119,14 +63120,16 @@ exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, fu } return stdout.trim(); }); -exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () { +exports.getCommandOutput = getCommandOutput; +const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () { 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.`); } const obtainedPackageManager = package_managers_1.supportedPackageManagers[packageManager]; return obtainedPackageManager; }); -exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () { +exports.getPackageManagerInfo = getPackageManagerInfo; +const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () { let pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command))); const emptyPaths = pathList.filter(item => !item); if (emptyPaths.length) { @@ -63134,6 +63137,7 @@ exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0 } return pathList; }); +exports.getCacheDirectoryPath = getCacheDirectoryPath; function isGhes() { const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; @@ -63196,7 +63200,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; @@ -63223,11 +63227,13 @@ const sys = __importStar(__nccwpck_require__(4300)); const fs_1 = __importDefault(__nccwpck_require__(7147)); const os_1 = __importDefault(__nccwpck_require__(2037)); const utils_1 = __nccwpck_require__(1314); -function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch(), manifest) { +function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch()) { return __awaiter(this, void 0, void 0, function* () { + let manifest; let osPlat = os_1.default.platform(); if (checkLatest) { core.info('Attempting to resolve the latest version from the manifest...'); + manifest = yield getManifest(auth); const resolvedVersion = yield resolveVersionFromManifest(versionSpec, true, auth, arch, manifest); if (resolvedVersion) { versionSpec = resolvedVersion; @@ -63239,6 +63245,7 @@ function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch(), manif } if (versionSpec === utils_1.StableReleaseAlias.Stable || versionSpec === utils_1.StableReleaseAlias.OldStable) { + manifest !== null && manifest !== void 0 ? manifest : (manifest = yield getManifest(auth)); versionSpec = yield resolveStableVersionInput(versionSpec, auth, arch, manifest); } // check cache @@ -63394,6 +63401,13 @@ function findMatch(versionSpec, arch = os_1.default.arch()) { if (!candidates) { throw new Error(`golang download url did not return results`); } + if (versionSpec === utils_1.StableReleaseAlias.Stable || + versionSpec === utils_1.StableReleaseAlias.OldStable) { + const fixedCandidates = candidates.map(item => { + return Object.assign(Object.assign({}, item), { version: makeSemver(item.version) }); + }); + versionSpec = yield resolveStableVersionInput(versionSpec, undefined, arch, fixedCandidates); + } let goFile; for (let i = 0; i < candidates.length; i++) { let candidate = candidates[i]; @@ -63472,7 +63486,15 @@ function resolveStableVersionInput(versionSpec, auth, arch = os_1.default.arch() core.debug('No manifest cached'); manifest = yield getManifest(auth); } - const releases = manifest.map(release => release.version); + const releases = manifest + .map(item => { + const index = item.files.findIndex(item => item.arch === arch); + if (index === -1) { + return ''; + } + return item.version; + }) + .filter(item => !!item); if (versionSpec === utils_1.StableReleaseAlias.Stable) { core.info(`stable version resolved as ${releases[0]}`); return releases[0]; @@ -63480,12 +63502,12 @@ function resolveStableVersionInput(versionSpec, auth, arch = os_1.default.arch() 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}`); + const oldstableVersion = releases.find(item => item.startsWith(uniqueVersions[1])); + core.info(`oldstable version resolved as ${oldstableVersion}`); if (!oldstableVersion) { return versionSpec; } - return oldstableVersion.resolvedVersion; + return oldstableVersion; } }); } @@ -63514,7 +63536,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; @@ -63559,9 +63581,8 @@ function run() { if (versionSpec) { let token = core.getInput('token'); let auth = !token ? undefined : `token ${token}`; - const manifest = yield installer.getManifest(auth); const checkLatest = core.getBooleanInput('check-latest'); - const installDir = yield installer.getGo(versionSpec, checkLatest, auth, arch, manifest); + const installDir = yield installer.getGo(versionSpec, checkLatest, auth, arch); const installDirVersion = path_1.default.basename(path_1.default.dirname(installDir)); core.addPath(path_1.default.join(installDir, 'bin')); core.info('Added go to the path'); diff --git a/package-lock.json b/package-lock.json index 73e443dee..5d4490ca3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,9 +26,9 @@ "jest": "^27.2.5", "jest-circus": "^27.2.5", "nock": "^10.0.6", - "prettier": "^1.17.1", + "prettier": "^2.8.0", "ts-jest": "^27.0.5", - "typescript": "^3.8.3" + "typescript": "^4.3.3" } }, "node_modules/@actions/cache": { @@ -4062,15 +4062,18 @@ } }, "node_modules/prettier": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", - "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.0.tgz", + "integrity": "sha512-9Lmg8hTFZKG0Asr/kW9Bp8tJjRVluO8EJQVfY2T7FMw9T5jy4I/Uvx0Rca/XWf50QQ1/SS48+6IJWnrb+2yemA==", "dev": true, "bin": { "prettier": "bin-prettier.js" }, "engines": { - "node": ">=4" + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" } }, "node_modules/pretty-format": { @@ -4694,9 +4697,9 @@ } }, "node_modules/typescript": { - "version": "3.9.10", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", - "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==", + "version": "4.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.3.tgz", + "integrity": "sha512-rUvLW0WtF7PF2b9yenwWUi9Da9euvDRhmH7BLyBG4DCFfOJ850LGNknmRpp8Z8kXNUPObdZQEfKOiHtXuQHHKA==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -8118,9 +8121,9 @@ "dev": true }, "prettier": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", - "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.0.tgz", + "integrity": "sha512-9Lmg8hTFZKG0Asr/kW9Bp8tJjRVluO8EJQVfY2T7FMw9T5jy4I/Uvx0Rca/XWf50QQ1/SS48+6IJWnrb+2yemA==", "dev": true }, "pretty-format": { @@ -8565,9 +8568,9 @@ } }, "typescript": { - "version": "3.9.10", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", - "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==", + "version": "4.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.3.tgz", + "integrity": "sha512-rUvLW0WtF7PF2b9yenwWUi9Da9euvDRhmH7BLyBG4DCFfOJ850LGNknmRpp8Z8kXNUPObdZQEfKOiHtXuQHHKA==", "dev": true }, "universalify": { diff --git a/package.json b/package.json index fbbedc0ff..9a1aa88e8 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,8 @@ "jest": "^27.2.5", "jest-circus": "^27.2.5", "nock": "^10.0.6", - "prettier": "^1.17.1", + "prettier": "^2.8.0", "ts-jest": "^27.0.5", - "typescript": "^3.8.3" + "typescript": "^4.3.3" } } diff --git a/src/installer.ts b/src/installer.ts index 0c2cdee38..84c9242f1 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -34,13 +34,14 @@ export async function getGo( versionSpec: string, checkLatest: boolean, auth: string | undefined, - arch = os.arch(), - manifest: tc.IToolRelease[] | undefined + arch = os.arch() ) { + let manifest: tc.IToolRelease[] | undefined; let osPlat: string = os.platform(); if (checkLatest) { core.info('Attempting to resolve the latest version from the manifest...'); + manifest = await getManifest(auth); const resolvedVersion = await resolveVersionFromManifest( versionSpec, true, @@ -60,6 +61,7 @@ export async function getGo( versionSpec === StableReleaseAlias.Stable || versionSpec === StableReleaseAlias.OldStable ) { + manifest ??= await getManifest(auth); versionSpec = await resolveStableVersionInput( versionSpec, auth, @@ -266,6 +268,21 @@ export async function findMatch( throw new Error(`golang download url did not return results`); } + if ( + versionSpec === StableReleaseAlias.Stable || + versionSpec === StableReleaseAlias.OldStable + ) { + const fixedCandidates = candidates.map(item => { + return {...item, version: makeSemver(item.version)}; + }); + versionSpec = await resolveStableVersionInput( + versionSpec, + undefined, + arch, + fixedCandidates + ); + } + let goFile: IGoVersionFile | undefined; for (let i = 0; i < candidates.length; i++) { let candidate: IGoVersion = candidates[i]; @@ -358,14 +375,22 @@ export async function resolveStableVersionInput( versionSpec: string, auth: string | undefined, arch = os.arch(), - manifest: tc.IToolRelease[] | undefined + manifest: tc.IToolRelease[] | IGoVersion[] | undefined ): Promise { if (!manifest) { core.debug('No manifest cached'); manifest = await getManifest(auth); } - const releases = manifest.map(release => release.version); + const releases = manifest + .map(item => { + const index = item.files.findIndex(item => item.arch === arch); + if (index === -1) { + return ''; + } + return item.version; + }) + .filter(item => !!item); if (versionSpec === StableReleaseAlias.Stable) { core.info(`stable version resolved as ${releases[0]}`); @@ -377,22 +402,16 @@ export async function resolveStableVersionInput( ); const uniqueVersions = Array.from(new Set(versions)); - const oldstableVersion = await getInfoFromManifest( - uniqueVersions[1], - true, - auth, - arch, - manifest + const oldstableVersion = releases.find(item => + item.startsWith(uniqueVersions[1]) ); - core.info( - `oldstable version resolved as ${oldstableVersion?.resolvedVersion}` - ); + core.info(`oldstable version resolved as ${oldstableVersion}`); if (!oldstableVersion) { return versionSpec; } - return oldstableVersion.resolvedVersion; + return oldstableVersion; } } diff --git a/src/main.ts b/src/main.ts index 613cb5460..5833f16de 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,16 +30,13 @@ export async function run() { let token = core.getInput('token'); let auth = !token ? undefined : `token ${token}`; - const manifest = await installer.getManifest(auth); - const checkLatest = core.getBooleanInput('check-latest'); const installDir = await installer.getGo( versionSpec, checkLatest, auth, - arch, - manifest + arch ); const installDirVersion = path.basename(path.dirname(installDir));