From be45b2722d88c64da8b5a12a7ee5870dac98919e Mon Sep 17 00:00:00 2001 From: Evgenii Korolevskii Date: Thu, 8 Sep 2022 12:29:13 +0200 Subject: [PATCH] build --- dist/cache-save/index.js | 381 +++++------ dist/setup/index.js | 1282 +++++++++++++++++++------------------- src/cache-save.ts | 3 + 3 files changed, 836 insertions(+), 830 deletions(-) diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index d5b8e75..f53d576 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -59932,96 +59932,99 @@ 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; - } - const cacheId = yield cache.saveCache(cachePaths, primaryKey); - if (cacheId === -1) { - return; - } - core.info(`Cache saved with the key: ${primaryKey}`); -}); -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) { + core.warning(`There are no cache folders on the disk`); + logWarning(`There are no cache folders on the disk`); + return; + 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; + } + const cacheId = yield cache.saveCache(cachePaths, primaryKey); + if (cacheId === -1) { + return; + } + core.info(`Cache saved with the key: ${primaryKey}`); +}); +function logWarning(message) { + const warningPrefix = '[warning]'; + core.info(`${warningPrefix}${message}`); +} +exports.logWarning = logWarning; +run(); /***/ }), @@ -60030,84 +60033,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; /***/ }), @@ -60116,18 +60119,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 = {})); /***/ }), @@ -60136,15 +60139,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 08d77d5..46ce932 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62626,82 +62626,82 @@ 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`); - core.setOutput(constants_1.Outputs.CacheHit, false); - 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); + const cacheKey = yield cache.restoreCache(cachePaths, primaryKey); + core.setOutput(constants_1.Outputs.CacheHit, Boolean(cacheKey)); + if (!cacheKey) { + core.info(`Cache is not found`); + core.setOutput(constants_1.Outputs.CacheHit, false); + 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); +}; /***/ }), @@ -62710,84 +62710,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; /***/ }), @@ -62796,18 +62796,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 = {})); /***/ }), @@ -62816,277 +62816,277 @@ 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__(6255)); -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, arch = os_1.default.arch()) { - return __awaiter(this, void 0, void 0, function* () { - let osPlat = os_1.default.platform(); - if (checkLatest) { - core.info('Attempting to resolve the latest version from the manifest...'); - const resolvedVersion = yield resolveVersionFromManifest(versionSpec, true, auth, arch); - 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, arch); - // 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, arch); - if (info) { - downloadPath = yield installGoVersion(info, auth, arch); - } - 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, arch); - if (!info) { - throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`); - } - try { - core.info('Install from dist'); - downloadPath = yield installGoVersion(info, undefined, arch); - } - catch (err) { - throw new Error(`Failed to download version ${versionSpec}: ${err}`); - } - } - return downloadPath; - }); -} -exports.getGo = getGo; -function resolveVersionFromManifest(versionSpec, stable, auth, arch) { - return __awaiter(this, void 0, void 0, function* () { - try { - const info = yield getInfoFromManifest(versionSpec, stable, auth, arch); - 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, arch) { - return __awaiter(this, void 0, void 0, function* () { - core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); - // Windows requires that we keep the extension (.zip) for extraction - const isWindows = os_1.default.platform() === 'win32'; - const tempDir = process.env.RUNNER_TEMP || '.'; - const fileName = isWindows ? path.join(tempDir, info.fileName) : undefined; - const downloadPath = yield tc.downloadTool(info.downloadUrl, fileName, 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), arch); - 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, arch = os_1.default.arch()) { - 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, arch); - 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, arch) { - return __awaiter(this, void 0, void 0, function* () { - let version; - version = yield findMatch(versionSpec, arch); - 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, arch = os_1.default.arch()) { - return __awaiter(this, void 0, void 0, function* () { - let archFilter = sys.getArch(arch); - 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__(6255)); +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, arch = os_1.default.arch()) { + return __awaiter(this, void 0, void 0, function* () { + let osPlat = os_1.default.platform(); + if (checkLatest) { + core.info('Attempting to resolve the latest version from the manifest...'); + const resolvedVersion = yield resolveVersionFromManifest(versionSpec, true, auth, arch); + 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, arch); + // 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, arch); + if (info) { + downloadPath = yield installGoVersion(info, auth, arch); + } + 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, arch); + if (!info) { + throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`); + } + try { + core.info('Install from dist'); + downloadPath = yield installGoVersion(info, undefined, arch); + } + catch (err) { + throw new Error(`Failed to download version ${versionSpec}: ${err}`); + } + } + return downloadPath; + }); +} +exports.getGo = getGo; +function resolveVersionFromManifest(versionSpec, stable, auth, arch) { + return __awaiter(this, void 0, void 0, function* () { + try { + const info = yield getInfoFromManifest(versionSpec, stable, auth, arch); + 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, arch) { + return __awaiter(this, void 0, void 0, function* () { + core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); + // Windows requires that we keep the extension (.zip) for extraction + const isWindows = os_1.default.platform() === 'win32'; + const tempDir = process.env.RUNNER_TEMP || '.'; + const fileName = isWindows ? path.join(tempDir, info.fileName) : undefined; + const downloadPath = yield tc.downloadTool(info.downloadUrl, fileName, 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), arch); + 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, arch = os_1.default.arch()) { + 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, arch); + 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, arch) { + return __awaiter(this, void 0, void 0, function* () { + let version; + version = yield findMatch(versionSpec, arch); + 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, arch = os_1.default.arch()) { + return __awaiter(this, void 0, void 0, function* () { + let archFilter = sys.getArch(arch); + 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; /***/ }), @@ -63095,160 +63095,160 @@ 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)); -const os_1 = __importDefault(__nccwpck_require__(2037)); -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}`); - let arch = core.getInput('architecture'); - if (!arch) { - arch = os_1.default.arch(); - } - 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, arch); - 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)); +const os_1 = __importDefault(__nccwpck_require__(2037)); +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}`); + let arch = core.getInput('architecture'); + if (!arch) { + arch = os_1.default.arch(); + } + 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, arch); + 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; +} /***/ }), @@ -63257,15 +63257,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'] + } +}; /***/ }), @@ -63274,43 +63274,43 @@ 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(arch) { - // 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', and 'x64'. - // 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; - case 'arm': - arch = 'armv6l'; - 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(arch) { + // 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', and 'x64'. + // 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; + case 'arm': + arch = 'armv6l'; + break; + } + return arch; +} +exports.getArch = getArch; /***/ }), @@ -63542,10 +63542,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-save.ts b/src/cache-save.ts index 2b58677..9deabe5 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -40,6 +40,9 @@ const cachePackages = async () => { ); if (nonExistingPaths.length === cachePaths.length) { + core.warning(`There are no cache folders on the disk`); + logWarning(`There are no cache folders on the disk`) + return; throw new Error(`There are no cache folders on the disk`); }