From 6036aa2424258f4a42bd3bae3c818d6128a3151b Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Tue, 14 Jun 2022 10:57:37 +0200 Subject: [PATCH] Add cache error handling --- dist/cache-save/index.js | 398 ++++++------ dist/setup/index.js | 1272 +++++++++++++++++++------------------- src/cache-restore.ts | 26 +- 3 files changed, 859 insertions(+), 837 deletions(-) diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 384e76a..d921c2e 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -59135,106 +59135,106 @@ module.exports = v4; /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -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); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.logWarning = exports.run = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const cache = __importStar(__nccwpck_require__(7799)); -const fs_1 = __importDefault(__nccwpck_require__(7147)); -const constants_1 = __nccwpck_require__(9042); -const cache_utils_1 = __nccwpck_require__(1678); -// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in -// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to -// throw an uncaught exception. Instead of failing this action, just warn. -process.on('uncaughtException', e => { - const warningPrefix = '[warning]'; - core.info(`${warningPrefix}${e.message}`); -}); -function run() { - return __awaiter(this, void 0, void 0, function* () { - try { - yield cachePackages(); - } - catch (error) { - core.setFailed(error.message); - } - }); -} -exports.run = run; -const cachePackages = () => __awaiter(void 0, void 0, void 0, function* () { - const cacheInput = core.getBooleanInput('cache'); - if (!cacheInput) { - return; - } - const packageManager = 'default'; - const state = core.getState(constants_1.State.CacheMatchedKey); - const primaryKey = core.getState(constants_1.State.CachePrimaryKey); - const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager); - const cachePaths = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo); - const nonExistingPaths = cachePaths.filter(cachePath => !fs_1.default.existsSync(cachePath)); - if (nonExistingPaths.length === cachePaths.length) { - throw new Error(`There are no cache folders on the disk`); - } - if (nonExistingPaths.length) { - logWarning(`Cache folder path is retrieved but doesn't exist on disk: ${nonExistingPaths.join(', ')}`); - } - if (primaryKey === state) { - core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); - return; - } - try { - yield cache.saveCache(cachePaths, primaryKey); - core.info(`Cache saved with the key: ${primaryKey}`); - } - catch (error) { - if (error.name === cache.ValidationError.name) { - throw error; - } - else if (error.name === cache.ReserveCacheError.name) { - core.info(error.message); - } - else { - core.warning(`${error.message}`); - } - } -}); -function logWarning(message) { - const warningPrefix = '[warning]'; - core.info(`${warningPrefix}${message}`); -} -exports.logWarning = logWarning; -run(); + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +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); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.logWarning = exports.run = void 0; +const core = __importStar(__nccwpck_require__(2186)); +const cache = __importStar(__nccwpck_require__(7799)); +const fs_1 = __importDefault(__nccwpck_require__(7147)); +const constants_1 = __nccwpck_require__(9042); +const cache_utils_1 = __nccwpck_require__(1678); +// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in +// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to +// throw an uncaught exception. Instead of failing this action, just warn. +process.on('uncaughtException', e => { + const warningPrefix = '[warning]'; + core.info(`${warningPrefix}${e.message}`); +}); +function run() { + return __awaiter(this, void 0, void 0, function* () { + try { + yield cachePackages(); + } + catch (error) { + core.setFailed(error.message); + } + }); +} +exports.run = run; +const cachePackages = () => __awaiter(void 0, void 0, void 0, function* () { + const cacheInput = core.getBooleanInput('cache'); + if (!cacheInput) { + return; + } + const packageManager = 'default'; + const state = core.getState(constants_1.State.CacheMatchedKey); + const primaryKey = core.getState(constants_1.State.CachePrimaryKey); + const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager); + const cachePaths = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo); + const nonExistingPaths = cachePaths.filter(cachePath => !fs_1.default.existsSync(cachePath)); + if (nonExistingPaths.length === cachePaths.length) { + throw new Error(`There are no cache folders on the disk`); + } + if (nonExistingPaths.length) { + logWarning(`Cache folder path is retrieved but doesn't exist on disk: ${nonExistingPaths.join(', ')}`); + } + if (primaryKey === state) { + core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); + return; + } + try { + yield cache.saveCache(cachePaths, primaryKey); + core.info(`Cache saved with the key: ${primaryKey}`); + } + catch (error) { + if (error.name === cache.ValidationError.name) { + throw error; + } + else if (error.name === cache.ReserveCacheError.name) { + core.info(error.message); + } + else { + core.warning(`${error.message}`); + } + } +}); +function logWarning(message) { + const warningPrefix = '[warning]'; + core.info(`${warningPrefix}${message}`); +} +exports.logWarning = logWarning; +run(); /***/ }), @@ -59243,84 +59243,84 @@ run(); /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -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); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0; -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* () { - let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true }); - if (exitCode) { - stderr = !stderr.trim() - ? `The '${toolCommand}' command failed with exit code: ${exitCode}` - : stderr; - throw new Error(stderr); - } - return stdout.trim(); -}); -exports.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* () { - let pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command))); - const emptyPaths = pathList.filter(item => !item); - if (emptyPaths.length) { - throw new Error(`Could not get cache folder paths.`); - } - return pathList; -}); -function isGhes() { - const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); - return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; -} -exports.isGhes = isGhes; -function isCacheFeatureAvailable() { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); - } - else { - core.warning('The runner was not able to contact the cache service. Caching will be skipped'); - } - return false; - } - return true; -} -exports.isCacheFeatureAvailable = isCacheFeatureAvailable; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +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); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0; +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* () { + let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true }); + if (exitCode) { + stderr = !stderr.trim() + ? `The '${toolCommand}' command failed with exit code: ${exitCode}` + : stderr; + throw new Error(stderr); + } + return stdout.trim(); +}); +exports.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* () { + let pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command))); + const emptyPaths = pathList.filter(item => !item); + if (emptyPaths.length) { + throw new Error(`Could not get cache folder paths.`); + } + return pathList; +}); +function isGhes() { + const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); + return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; +} +exports.isGhes = isGhes; +function isCacheFeatureAvailable() { + if (!cache.isFeatureAvailable()) { + if (isGhes()) { + throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); + } + else { + core.warning('The runner was not able to contact the cache service. Caching will be skipped'); + } + return false; + } + return true; +} +exports.isCacheFeatureAvailable = isCacheFeatureAvailable; /***/ }), @@ -59329,18 +59329,18 @@ exports.isCacheFeatureAvailable = isCacheFeatureAvailable; /***/ ((__unused_webpack_module, exports) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.Outputs = exports.State = void 0; -var State; -(function (State) { - State["CachePrimaryKey"] = "CACHE_KEY"; - State["CacheMatchedKey"] = "CACHE_RESULT"; -})(State = exports.State || (exports.State = {})); -var Outputs; -(function (Outputs) { - Outputs["CacheHit"] = "cache-hit"; -})(Outputs = exports.Outputs || (exports.Outputs = {})); + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Outputs = exports.State = void 0; +var State; +(function (State) { + State["CachePrimaryKey"] = "CACHE_KEY"; + State["CacheMatchedKey"] = "CACHE_RESULT"; +})(State = exports.State || (exports.State = {})); +var Outputs; +(function (Outputs) { + Outputs["CacheHit"] = "cache-hit"; +})(Outputs = exports.Outputs || (exports.Outputs = {})); /***/ }), @@ -59349,15 +59349,15 @@ var Outputs; /***/ ((__unused_webpack_module, exports) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.supportedPackageManagers = void 0; -exports.supportedPackageManagers = { - default: { - dependencyFilePattern: 'go.sum', - cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE'] - } -}; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.supportedPackageManagers = void 0; +exports.supportedPackageManagers = { + default: { + dependencyFilePattern: 'go.sum', + cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE'] + } +}; /***/ }), diff --git a/dist/setup/index.js b/dist/setup/index.js index 168daa2..5520d15 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -61219,81 +61219,93 @@ module.exports = v4; /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -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); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.restoreCache = void 0; -const cache = __importStar(__nccwpck_require__(7799)); -const core = __importStar(__nccwpck_require__(2186)); -const glob = __importStar(__nccwpck_require__(8090)); -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 = (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 versionSpec = core.getInput('go-version'); - const cachePaths = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo); - const dependencyFilePath = cacheDependencyPath - ? cacheDependencyPath - : findDependencyFile(packageManagerInfo); - const fileHash = yield glob.hashFiles(dependencyFilePath); - if (!fileHash) { - throw new Error('Some specified paths were not resolved, unable to cache dependencies.'); - } - const primaryKey = `setup-go-${platform}-go-${versionSpec}-${fileHash}`; - core.debug(`primary key is ${primaryKey}`); - core.saveState(constants_1.State.CachePrimaryKey, primaryKey); - const cacheKey = yield cache.restoreCache(cachePaths, primaryKey); - core.setOutput(constants_1.Outputs.CacheHit, Boolean(cacheKey)); - if (!cacheKey) { - core.info(`Cache is not found`); - return; - } - core.saveState(constants_1.State.CacheMatchedKey, cacheKey); - core.info(`Cache restored from key: ${cacheKey}`); -}); -const findDependencyFile = (packageManager) => { - let dependencyFile = packageManager.dependencyFilePattern; - const workspace = process.env.GITHUB_WORKSPACE; - const rootContent = fs_1.default.readdirSync(workspace); - const goSumFileExists = rootContent.includes(dependencyFile); - if (!goSumFileExists) { - throw new Error(`Dependencies file is not found in ${workspace}. Supported file pattern: ${dependencyFile}`); - } - return path_1.default.join(workspace, dependencyFile); -}; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +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); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.restoreCache = void 0; +const cache = __importStar(__nccwpck_require__(7799)); +const core = __importStar(__nccwpck_require__(2186)); +const glob = __importStar(__nccwpck_require__(8090)); +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 = (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 versionSpec = core.getInput('go-version'); + const cachePaths = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo); + const dependencyFilePath = cacheDependencyPath + ? cacheDependencyPath + : findDependencyFile(packageManagerInfo); + const fileHash = yield glob.hashFiles(dependencyFilePath); + if (!fileHash) { + throw new Error('Some specified paths were not resolved, unable to cache dependencies.'); + } + const primaryKey = `setup-go-${platform}-go-${versionSpec}-${fileHash}`; + core.debug(`primary key is ${primaryKey}`); + core.saveState(constants_1.State.CachePrimaryKey, primaryKey); + try { + const cacheKey = yield cache.restoreCache(cachePaths, primaryKey); + core.setOutput(constants_1.Outputs.CacheHit, Boolean(cacheKey)); + if (!cacheKey) { + core.info(`Cache is not found`); + return; + } + core.saveState(constants_1.State.CacheMatchedKey, cacheKey); + core.info(`Cache restored from key: ${cacheKey}`); + } + catch (error) { + const typedError = error; + if (typedError.name === cache.ValidationError.name) { + throw error; + } + else { + core.warning(typedError.message); + core.setOutput(constants_1.Outputs.CacheHit, false); + } + } +}); +const findDependencyFile = (packageManager) => { + let dependencyFile = packageManager.dependencyFilePattern; + const workspace = process.env.GITHUB_WORKSPACE; + const rootContent = fs_1.default.readdirSync(workspace); + const goSumFileExists = rootContent.includes(dependencyFile); + if (!goSumFileExists) { + throw new Error(`Dependencies file is not found in ${workspace}. Supported file pattern: ${dependencyFile}`); + } + return path_1.default.join(workspace, dependencyFile); +}; /***/ }), @@ -61302,84 +61314,84 @@ const findDependencyFile = (packageManager) => { /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -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); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0; -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* () { - let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true }); - if (exitCode) { - stderr = !stderr.trim() - ? `The '${toolCommand}' command failed with exit code: ${exitCode}` - : stderr; - throw new Error(stderr); - } - return stdout.trim(); -}); -exports.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* () { - let pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command))); - const emptyPaths = pathList.filter(item => !item); - if (emptyPaths.length) { - throw new Error(`Could not get cache folder paths.`); - } - return pathList; -}); -function isGhes() { - const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); - return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; -} -exports.isGhes = isGhes; -function isCacheFeatureAvailable() { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); - } - else { - core.warning('The runner was not able to contact the cache service. Caching will be skipped'); - } - return false; - } - return true; -} -exports.isCacheFeatureAvailable = isCacheFeatureAvailable; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +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); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0; +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* () { + let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true }); + if (exitCode) { + stderr = !stderr.trim() + ? `The '${toolCommand}' command failed with exit code: ${exitCode}` + : stderr; + throw new Error(stderr); + } + return stdout.trim(); +}); +exports.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* () { + let pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command))); + const emptyPaths = pathList.filter(item => !item); + if (emptyPaths.length) { + throw new Error(`Could not get cache folder paths.`); + } + return pathList; +}); +function isGhes() { + const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); + return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; +} +exports.isGhes = isGhes; +function isCacheFeatureAvailable() { + if (!cache.isFeatureAvailable()) { + if (isGhes()) { + throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); + } + else { + core.warning('The runner was not able to contact the cache service. Caching will be skipped'); + } + return false; + } + return true; +} +exports.isCacheFeatureAvailable = isCacheFeatureAvailable; /***/ }), @@ -61388,18 +61400,18 @@ exports.isCacheFeatureAvailable = isCacheFeatureAvailable; /***/ ((__unused_webpack_module, exports) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.Outputs = exports.State = void 0; -var State; -(function (State) { - State["CachePrimaryKey"] = "CACHE_KEY"; - State["CacheMatchedKey"] = "CACHE_RESULT"; -})(State = exports.State || (exports.State = {})); -var Outputs; -(function (Outputs) { - Outputs["CacheHit"] = "cache-hit"; -})(Outputs = exports.Outputs || (exports.Outputs = {})); + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.Outputs = exports.State = void 0; +var State; +(function (State) { + State["CachePrimaryKey"] = "CACHE_KEY"; + State["CacheMatchedKey"] = "CACHE_RESULT"; +})(State = exports.State || (exports.State = {})); +var Outputs; +(function (Outputs) { + Outputs["CacheHit"] = "cache-hit"; +})(Outputs = exports.Outputs || (exports.Outputs = {})); /***/ }), @@ -61408,274 +61420,274 @@ var Outputs; /***/ (function(module, exports, __nccwpck_require__) { "use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -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); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.parseGoVersionFile = exports.makeSemver = exports.getVersionsDist = exports.findMatch = exports.getInfoFromManifest = exports.extractGoArchive = exports.getGo = void 0; -const tc = __importStar(__nccwpck_require__(7784)); -const core = __importStar(__nccwpck_require__(2186)); -const path = __importStar(__nccwpck_require__(1017)); -const semver = __importStar(__nccwpck_require__(5911)); -const httpm = __importStar(__nccwpck_require__(9925)); -const sys = __importStar(__nccwpck_require__(4300)); -const fs_1 = __importDefault(__nccwpck_require__(7147)); -const os_1 = __importDefault(__nccwpck_require__(2037)); -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, true, auth); - if (resolvedVersion) { - versionSpec = resolvedVersion; - core.info(`Resolved as '${versionSpec}'`); - } - else { - core.info(`Failed to resolve version ${versionSpec} from manifest`); - } - } - // check cache - let toolPath; - toolPath = tc.find('go', versionSpec); - // If not found in cache, download - if (toolPath) { - core.info(`Found in cache @ ${toolPath}`); - return toolPath; - } - core.info(`Attempting to download ${versionSpec}...`); - let downloadPath = ''; - let info = null; - // - // Try download from internal distribution (popular versions only) - // - try { - info = yield getInfoFromManifest(versionSpec, true, auth); - if (info) { - downloadPath = yield installGoVersion(info, auth); - } - else { - core.info('Not found in manifest. Falling back to download directly from Go'); - } - } - catch (err) { - if (err instanceof tc.HTTPError && - (err.httpStatusCode === 403 || err.httpStatusCode === 429)) { - core.info(`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`); - } - else { - core.info(err.message); - } - core.debug(err.stack); - core.info('Falling back to download directly from Go'); - } - // - // Download from storage.googleapis.com - // - if (!downloadPath) { - info = yield getInfoFromDist(versionSpec); - if (!info) { - throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`); - } - try { - core.info('Install from dist'); - downloadPath = yield installGoVersion(info, undefined); - } - catch (err) { - throw new Error(`Failed to download version ${versionSpec}: ${err}`); - } - } - return downloadPath; - }); -} -exports.getGo = getGo; -function resolveVersionFromManifest(versionSpec, stable, auth) { - return __awaiter(this, void 0, void 0, function* () { - try { - const info = yield getInfoFromManifest(versionSpec, stable, auth); - return info === null || info === void 0 ? void 0 : info.resolvedVersion; - } - catch (err) { - core.info('Unable to resolve a version from the manifest...'); - core.debug(err.message); - } - }); -} -function installGoVersion(info, auth) { - return __awaiter(this, void 0, void 0, function* () { - core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); - const downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, auth); - core.info('Extracting Go...'); - let extPath = yield extractGoArchive(downloadPath); - core.info(`Successfully extracted go to ${extPath}`); - if (info.type === 'dist') { - extPath = path.join(extPath, 'go'); - } - core.info('Adding to the cache ...'); - const cachedDir = yield tc.cacheDir(extPath, 'go', makeSemver(info.resolvedVersion)); - core.info(`Successfully cached go to ${cachedDir}`); - return cachedDir; - }); -} -function extractGoArchive(archivePath) { - return __awaiter(this, void 0, void 0, function* () { - const platform = os_1.default.platform(); - let extPath; - if (platform === 'win32') { - extPath = yield tc.extractZip(archivePath); - } - else { - extPath = yield tc.extractTar(archivePath); - } - return extPath; - }); -} -exports.extractGoArchive = extractGoArchive; -function getInfoFromManifest(versionSpec, stable, auth) { - return __awaiter(this, void 0, void 0, function* () { - let info = null; - const releases = yield tc.getManifestFromRepo('actions', 'go-versions', auth, 'main'); - core.info(`matching ${versionSpec}...`); - const rel = yield tc.findFromManifest(versionSpec, stable, releases); - if (rel && rel.files.length > 0) { - info = {}; - info.type = 'manifest'; - info.resolvedVersion = rel.version; - info.downloadUrl = rel.files[0].download_url; - info.fileName = rel.files[0].filename; - } - return info; - }); -} -exports.getInfoFromManifest = getInfoFromManifest; -function getInfoFromDist(versionSpec) { - return __awaiter(this, void 0, void 0, function* () { - let version; - version = yield findMatch(versionSpec); - if (!version) { - return null; - } - let downloadUrl = `https://storage.googleapis.com/golang/${version.files[0].filename}`; - return { - type: 'dist', - downloadUrl: downloadUrl, - resolvedVersion: version.version, - fileName: version.files[0].filename - }; - }); -} -function findMatch(versionSpec) { - return __awaiter(this, void 0, void 0, function* () { - let archFilter = sys.getArch(); - let platFilter = sys.getPlatform(); - let result; - let match; - const dlUrl = 'https://golang.org/dl/?mode=json&include=all'; - let candidates = yield module.exports.getVersionsDist(dlUrl); - if (!candidates) { - throw new Error(`golang download url did not return results`); - } - let goFile; - for (let i = 0; i < candidates.length; i++) { - let candidate = candidates[i]; - let version = makeSemver(candidate.version); - core.debug(`check ${version} satisfies ${versionSpec}`); - 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; - }); - if (goFile) { - core.debug(`matched ${candidate.version}`); - match = candidate; - break; - } - } - } - if (match && goFile) { - // clone since we're mutating the file list to be only the file that matches - result = Object.assign({}, match); - result.files = [goFile]; - } - return result; - }); -} -exports.findMatch = findMatch; -function getVersionsDist(dlUrl) { - return __awaiter(this, void 0, void 0, function* () { - // this returns versions descending so latest is first - let http = new httpm.HttpClient('setup-go', [], { - allowRedirects: true, - maxRedirects: 3 - }); - return (yield http.getJson(dlUrl)).result; - }); -} -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-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.'); - let parts = version.split('-'); - 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`); - } - 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; -function parseGoVersionFile(versionFilePath) { - const contents = fs_1.default.readFileSync(versionFilePath).toString(); - if (path.basename(versionFilePath) === 'go.mod') { - const match = contents.match(/^go (\d+(\.\d+)*)/m); - return match ? match[1] : ''; - } - return contents.trim(); -} -exports.parseGoVersionFile = parseGoVersionFile; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +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); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseGoVersionFile = exports.makeSemver = exports.getVersionsDist = exports.findMatch = exports.getInfoFromManifest = exports.extractGoArchive = exports.getGo = void 0; +const tc = __importStar(__nccwpck_require__(7784)); +const core = __importStar(__nccwpck_require__(2186)); +const path = __importStar(__nccwpck_require__(1017)); +const semver = __importStar(__nccwpck_require__(5911)); +const httpm = __importStar(__nccwpck_require__(9925)); +const sys = __importStar(__nccwpck_require__(4300)); +const fs_1 = __importDefault(__nccwpck_require__(7147)); +const os_1 = __importDefault(__nccwpck_require__(2037)); +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, true, auth); + if (resolvedVersion) { + versionSpec = resolvedVersion; + core.info(`Resolved as '${versionSpec}'`); + } + else { + core.info(`Failed to resolve version ${versionSpec} from manifest`); + } + } + // check cache + let toolPath; + toolPath = tc.find('go', versionSpec); + // If not found in cache, download + if (toolPath) { + core.info(`Found in cache @ ${toolPath}`); + return toolPath; + } + core.info(`Attempting to download ${versionSpec}...`); + let downloadPath = ''; + let info = null; + // + // Try download from internal distribution (popular versions only) + // + try { + info = yield getInfoFromManifest(versionSpec, true, auth); + if (info) { + downloadPath = yield installGoVersion(info, auth); + } + else { + core.info('Not found in manifest. Falling back to download directly from Go'); + } + } + catch (err) { + if (err instanceof tc.HTTPError && + (err.httpStatusCode === 403 || err.httpStatusCode === 429)) { + core.info(`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`); + } + else { + core.info(err.message); + } + core.debug(err.stack); + core.info('Falling back to download directly from Go'); + } + // + // Download from storage.googleapis.com + // + if (!downloadPath) { + info = yield getInfoFromDist(versionSpec); + if (!info) { + throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`); + } + try { + core.info('Install from dist'); + downloadPath = yield installGoVersion(info, undefined); + } + catch (err) { + throw new Error(`Failed to download version ${versionSpec}: ${err}`); + } + } + return downloadPath; + }); +} +exports.getGo = getGo; +function resolveVersionFromManifest(versionSpec, stable, auth) { + return __awaiter(this, void 0, void 0, function* () { + try { + const info = yield getInfoFromManifest(versionSpec, stable, auth); + return info === null || info === void 0 ? void 0 : info.resolvedVersion; + } + catch (err) { + core.info('Unable to resolve a version from the manifest...'); + core.debug(err.message); + } + }); +} +function installGoVersion(info, auth) { + return __awaiter(this, void 0, void 0, function* () { + core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); + const downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, auth); + core.info('Extracting Go...'); + let extPath = yield extractGoArchive(downloadPath); + core.info(`Successfully extracted go to ${extPath}`); + if (info.type === 'dist') { + extPath = path.join(extPath, 'go'); + } + core.info('Adding to the cache ...'); + const cachedDir = yield tc.cacheDir(extPath, 'go', makeSemver(info.resolvedVersion)); + core.info(`Successfully cached go to ${cachedDir}`); + return cachedDir; + }); +} +function extractGoArchive(archivePath) { + return __awaiter(this, void 0, void 0, function* () { + const platform = os_1.default.platform(); + let extPath; + if (platform === 'win32') { + extPath = yield tc.extractZip(archivePath); + } + else { + extPath = yield tc.extractTar(archivePath); + } + return extPath; + }); +} +exports.extractGoArchive = extractGoArchive; +function getInfoFromManifest(versionSpec, stable, auth) { + return __awaiter(this, void 0, void 0, function* () { + let info = null; + const releases = yield tc.getManifestFromRepo('actions', 'go-versions', auth, 'main'); + core.info(`matching ${versionSpec}...`); + const rel = yield tc.findFromManifest(versionSpec, stable, releases); + if (rel && rel.files.length > 0) { + info = {}; + info.type = 'manifest'; + info.resolvedVersion = rel.version; + info.downloadUrl = rel.files[0].download_url; + info.fileName = rel.files[0].filename; + } + return info; + }); +} +exports.getInfoFromManifest = getInfoFromManifest; +function getInfoFromDist(versionSpec) { + return __awaiter(this, void 0, void 0, function* () { + let version; + version = yield findMatch(versionSpec); + if (!version) { + return null; + } + let downloadUrl = `https://storage.googleapis.com/golang/${version.files[0].filename}`; + return { + type: 'dist', + downloadUrl: downloadUrl, + resolvedVersion: version.version, + fileName: version.files[0].filename + }; + }); +} +function findMatch(versionSpec) { + return __awaiter(this, void 0, void 0, function* () { + let archFilter = sys.getArch(); + let platFilter = sys.getPlatform(); + let result; + let match; + const dlUrl = 'https://golang.org/dl/?mode=json&include=all'; + let candidates = yield module.exports.getVersionsDist(dlUrl); + if (!candidates) { + throw new Error(`golang download url did not return results`); + } + let goFile; + for (let i = 0; i < candidates.length; i++) { + let candidate = candidates[i]; + let version = makeSemver(candidate.version); + core.debug(`check ${version} satisfies ${versionSpec}`); + 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; + }); + if (goFile) { + core.debug(`matched ${candidate.version}`); + match = candidate; + break; + } + } + } + if (match && goFile) { + // clone since we're mutating the file list to be only the file that matches + result = Object.assign({}, match); + result.files = [goFile]; + } + return result; + }); +} +exports.findMatch = findMatch; +function getVersionsDist(dlUrl) { + return __awaiter(this, void 0, void 0, function* () { + // this returns versions descending so latest is first + let http = new httpm.HttpClient('setup-go', [], { + allowRedirects: true, + maxRedirects: 3 + }); + return (yield http.getJson(dlUrl)).result; + }); +} +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-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.'); + let parts = version.split('-'); + 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`); + } + 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; +function parseGoVersionFile(versionFilePath) { + const contents = fs_1.default.readFileSync(versionFilePath).toString(); + if (path.basename(versionFilePath) === 'go.mod') { + const match = contents.match(/^go (\d+(\.\d+)*)/m); + return match ? match[1] : ''; + } + return contents.trim(); +} +exports.parseGoVersionFile = parseGoVersionFile; /***/ }), @@ -61684,155 +61696,155 @@ exports.parseGoVersionFile = parseGoVersionFile; /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -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); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.parseGoVersion = exports.addBinToPath = exports.run = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const io = __importStar(__nccwpck_require__(7436)); -const installer = __importStar(__nccwpck_require__(2574)); -const semver = __importStar(__nccwpck_require__(5911)); -const path_1 = __importDefault(__nccwpck_require__(1017)); -const cache_restore_1 = __nccwpck_require__(9517); -const cache_utils_1 = __nccwpck_require__(1678); -const child_process_1 = __importDefault(__nccwpck_require__(2081)); -const fs_1 = __importDefault(__nccwpck_require__(7147)); -function run() { - return __awaiter(this, void 0, void 0, function* () { - try { - // - // 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. - // - const versionSpec = resolveVersionInput(); - const cache = core.getBooleanInput('cache'); - core.info(`Setup go version spec ${versionSpec}`); - if (versionSpec) { - let token = core.getInput('token'); - let auth = !token || cache_utils_1.isGhes() ? undefined : `token ${token}`; - const checkLatest = core.getBooleanInput('check-latest'); - 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 set up Go version ${versionSpec}`); - } - if (cache && cache_utils_1.isCacheFeatureAvailable()) { - const packageManager = 'default'; - const cacheDependencyPath = core.getInput('cache-dependency-path'); - yield cache_restore_1.restoreCache(packageManager, cacheDependencyPath); - } - // add problem matchers - const matchersPath = path_1.default.join(__dirname, '../..', 'matchers.json'); - core.info(`##[add-matcher]${matchersPath}`); - // output the version actually being used - let goPath = yield io.which('go'); - let goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString(); - core.info(goVersion); - core.setOutput('go-version', parseGoVersion(goVersion)); - core.startGroup('go env'); - let goEnv = (child_process_1.default.execSync(`${goPath} env`) || '').toString(); - core.info(goEnv); - core.endGroup(); - } - catch (error) { - core.setFailed(error.message); - } - }); -} -exports.run = run; -function addBinToPath() { - return __awaiter(this, void 0, void 0, function* () { - let added = false; - let g = yield io.which('go'); - core.debug(`which go :${g}:`); - if (!g) { - core.debug('go not in the path'); - return added; - } - let buf = child_process_1.default.execSync('go env GOPATH'); - if (buf.length > 1) { - let gp = buf.toString().trim(); - core.debug(`go env GOPATH :${gp}:`); - if (!fs_1.default.existsSync(gp)) { - // some of the hosted images have go install but not profile dir - core.debug(`creating ${gp}`); - yield io.mkdirP(gp); - } - let bp = path_1.default.join(gp, 'bin'); - if (!fs_1.default.existsSync(bp)) { - core.debug(`creating ${bp}`); - yield io.mkdirP(bp); - } - core.addPath(bp); - added = true; - } - return added; - }); -} -exports.addBinToPath = addBinToPath; -function parseGoVersion(versionString) { - // get the installed version as an Action output - // based on go/src/cmd/go/internal/version/version.go: - // fmt.Printf("go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH) - // expecting go for runtime.Version() - return versionString.split(' ')[2].slice('go'.length); -} -exports.parseGoVersion = parseGoVersion; -function resolveVersionInput() { - let version = core.getInput('go-version'); - const versionFilePath = core.getInput('go-version-file'); - if (version && versionFilePath) { - core.warning('Both go-version and go-version-file inputs are specified, only go-version will be used'); - } - if (version) { - return version; - } - if (versionFilePath) { - if (!fs_1.default.existsSync(versionFilePath)) { - throw new Error(`The specified go version file at: ${versionFilePath} does not exist`); - } - version = installer.parseGoVersionFile(versionFilePath); - } - return version; -} + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +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); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.parseGoVersion = exports.addBinToPath = exports.run = void 0; +const core = __importStar(__nccwpck_require__(2186)); +const io = __importStar(__nccwpck_require__(7436)); +const installer = __importStar(__nccwpck_require__(2574)); +const semver = __importStar(__nccwpck_require__(5911)); +const path_1 = __importDefault(__nccwpck_require__(1017)); +const cache_restore_1 = __nccwpck_require__(9517); +const cache_utils_1 = __nccwpck_require__(1678); +const child_process_1 = __importDefault(__nccwpck_require__(2081)); +const fs_1 = __importDefault(__nccwpck_require__(7147)); +function run() { + return __awaiter(this, void 0, void 0, function* () { + try { + // + // 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. + // + const versionSpec = resolveVersionInput(); + const cache = core.getBooleanInput('cache'); + core.info(`Setup go version spec ${versionSpec}`); + if (versionSpec) { + let token = core.getInput('token'); + let auth = !token || cache_utils_1.isGhes() ? undefined : `token ${token}`; + const checkLatest = core.getBooleanInput('check-latest'); + 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 set up Go version ${versionSpec}`); + } + if (cache && cache_utils_1.isCacheFeatureAvailable()) { + const packageManager = 'default'; + const cacheDependencyPath = core.getInput('cache-dependency-path'); + yield cache_restore_1.restoreCache(packageManager, cacheDependencyPath); + } + // add problem matchers + const matchersPath = path_1.default.join(__dirname, '../..', 'matchers.json'); + core.info(`##[add-matcher]${matchersPath}`); + // output the version actually being used + let goPath = yield io.which('go'); + let goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString(); + core.info(goVersion); + core.setOutput('go-version', parseGoVersion(goVersion)); + core.startGroup('go env'); + let goEnv = (child_process_1.default.execSync(`${goPath} env`) || '').toString(); + core.info(goEnv); + core.endGroup(); + } + catch (error) { + core.setFailed(error.message); + } + }); +} +exports.run = run; +function addBinToPath() { + return __awaiter(this, void 0, void 0, function* () { + let added = false; + let g = yield io.which('go'); + core.debug(`which go :${g}:`); + if (!g) { + core.debug('go not in the path'); + return added; + } + let buf = child_process_1.default.execSync('go env GOPATH'); + if (buf.length > 1) { + let gp = buf.toString().trim(); + core.debug(`go env GOPATH :${gp}:`); + if (!fs_1.default.existsSync(gp)) { + // some of the hosted images have go install but not profile dir + core.debug(`creating ${gp}`); + yield io.mkdirP(gp); + } + let bp = path_1.default.join(gp, 'bin'); + if (!fs_1.default.existsSync(bp)) { + core.debug(`creating ${bp}`); + yield io.mkdirP(bp); + } + core.addPath(bp); + added = true; + } + return added; + }); +} +exports.addBinToPath = addBinToPath; +function parseGoVersion(versionString) { + // get the installed version as an Action output + // based on go/src/cmd/go/internal/version/version.go: + // fmt.Printf("go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH) + // expecting go for runtime.Version() + return versionString.split(' ')[2].slice('go'.length); +} +exports.parseGoVersion = parseGoVersion; +function resolveVersionInput() { + let version = core.getInput('go-version'); + const versionFilePath = core.getInput('go-version-file'); + if (version && versionFilePath) { + core.warning('Both go-version and go-version-file inputs are specified, only go-version will be used'); + } + if (version) { + return version; + } + if (versionFilePath) { + if (!fs_1.default.existsSync(versionFilePath)) { + throw new Error(`The specified go version file at: ${versionFilePath} does not exist`); + } + version = installer.parseGoVersionFile(versionFilePath); + } + return version; +} /***/ }), @@ -61841,15 +61853,15 @@ function resolveVersionInput() { /***/ ((__unused_webpack_module, exports) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.supportedPackageManagers = void 0; -exports.supportedPackageManagers = { - default: { - dependencyFilePattern: 'go.sum', - cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE'] - } -}; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.supportedPackageManagers = void 0; +exports.supportedPackageManagers = { + default: { + dependencyFilePattern: 'go.sum', + cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE'] + } +}; /***/ }), @@ -61858,41 +61870,41 @@ exports.supportedPackageManagers = { /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { "use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getArch = exports.getPlatform = void 0; -const os = __nccwpck_require__(2037); -function getPlatform() { - // darwin and linux match already - // freebsd not supported yet but future proofed. - // 'aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', and 'win32' - let plat = os.platform(); - // wants 'darwin', 'freebsd', 'linux', 'windows' - if (plat === 'win32') { - plat = 'windows'; - } - return plat; -} -exports.getPlatform = getPlatform; -function getArch() { - // 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', and 'x64'. - let arch = os.arch(); - // wants amd64, 386, arm64, armv61, ppc641e, s390x - // currently not supported by runner but future proofed mapping - switch (arch) { - case 'x64': - arch = 'amd64'; - break; - // case 'ppc': - // arch = 'ppc64'; - // break; - case 'x32': - arch = '386'; - break; - } - return arch; -} -exports.getArch = getArch; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.getArch = exports.getPlatform = void 0; +const os = __nccwpck_require__(2037); +function getPlatform() { + // darwin and linux match already + // freebsd not supported yet but future proofed. + // 'aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', and 'win32' + let plat = os.platform(); + // wants 'darwin', 'freebsd', 'linux', 'windows' + if (plat === 'win32') { + plat = 'windows'; + } + return plat; +} +exports.getPlatform = getPlatform; +function getArch() { + // 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', and 'x64'. + let arch = os.arch(); + // wants amd64, 386, arm64, armv61, ppc641e, s390x + // currently not supported by runner but future proofed mapping + switch (arch) { + case 'x64': + arch = 'amd64'; + break; + // case 'ppc': + // arch = 'ppc64'; + // break; + case 'x32': + arch = '386'; + break; + } + return arch; +} +exports.getArch = getArch; /***/ }), @@ -62124,10 +62136,10 @@ var __webpack_exports__ = {}; (() => { "use strict"; var exports = __webpack_exports__; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -const main_1 = __nccwpck_require__(399); -main_1.run(); + +Object.defineProperty(exports, "__esModule", ({ value: true })); +const main_1 = __nccwpck_require__(399); +main_1.run(); })(); diff --git a/src/cache-restore.ts b/src/cache-restore.ts index 30f9528..54da8fb 100644 --- a/src/cache-restore.ts +++ b/src/cache-restore.ts @@ -34,16 +34,26 @@ export const restoreCache = async ( core.saveState(State.CachePrimaryKey, primaryKey); - const cacheKey = await cache.restoreCache(cachePaths, primaryKey); - core.setOutput(Outputs.CacheHit, Boolean(cacheKey)); + try { + const cacheKey = await cache.restoreCache(cachePaths, primaryKey); + core.setOutput(Outputs.CacheHit, Boolean(cacheKey)); - if (!cacheKey) { - core.info(`Cache is not found`); - return; + if (!cacheKey) { + core.info(`Cache is not found`); + return; + } + + core.saveState(State.CacheMatchedKey, cacheKey); + core.info(`Cache restored from key: ${cacheKey}`); + } catch (error) { + const typedError = error as Error; + if (typedError.name === cache.ValidationError.name) { + throw error; + } else { + core.warning(typedError.message); + core.setOutput(Outputs.CacheHit, false); + } } - - core.saveState(State.CacheMatchedKey, cacheKey); - core.info(`Cache restored from key: ${cacheKey}`); }; const findDependencyFile = (packageManager: PackageManagerInfo) => {