From 2fa955d825a29821e73ec064792122ea9f70e573 Mon Sep 17 00:00:00 2001 From: Daniel Kuschny Date: Thu, 13 May 2021 21:40:34 +0200 Subject: [PATCH 1/9] Update examples.md (#588) Extend gradle notes. --- examples.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples.md b/examples.md index f3d6788..eff7fac 100644 --- a/examples.md +++ b/examples.md @@ -137,6 +137,8 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba ## Java - Gradle +>Note: Ensure no Gradle daemons are running anymore when your workflow completes. Creating the cache package might fail due to locks being held by Gradle. Refer to the [Gradle Daemon documentation](https://docs.gradle.org/current/userguide/gradle_daemon.html) on how to disable or stop the Gradle Daemons. + ```yaml - uses: actions/cache@v2 with: From cc2d767a726ddd654506e76169ec14b20dc75915 Mon Sep 17 00:00:00 2001 From: Alex Tokarev Date: Fri, 21 May 2021 20:41:57 +0300 Subject: [PATCH 2/9] Update Rust directories recommended for caching (#433) This commit applies the suggestion from The Cargo Book: https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci --- examples.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples.md b/examples.md index eff7fac..7fb2ffc 100644 --- a/examples.md +++ b/examples.md @@ -476,9 +476,11 @@ whenever possible: - uses: actions/cache@v2 with: path: | - ~/.cargo/registry - ~/.cargo/git - target + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} ``` From c64c572235d810460d0d6876e9c705ad5002b353 Mon Sep 17 00:00:00 2001 From: David Hadka Date: Thu, 27 May 2021 10:46:35 -0500 Subject: [PATCH 3/9] Catch and log unhandled exceptions stemming from closed file descriptor (#596) --- dist/restore/index.js | 394 ++++++++++++++++++++--------------------- dist/save/index.js | 396 +++++++++++++++++++++--------------------- package-lock.json | 2 +- package.json | 2 +- src/save.ts | 5 + 5 files changed, 404 insertions(+), 395 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index e13e548..7174733 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -5460,32 +5460,32 @@ Object.defineProperty(exports, "__esModule", { value: true }); /***/ (function(__unusedmodule, exports) { "use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -exports.RefKey = exports.Events = exports.State = exports.Outputs = exports.Inputs = void 0; -var Inputs; -(function (Inputs) { - Inputs["Key"] = "key"; - Inputs["Path"] = "path"; - Inputs["RestoreKeys"] = "restore-keys"; - Inputs["UploadChunkSize"] = "upload-chunk-size"; -})(Inputs = exports.Inputs || (exports.Inputs = {})); -var Outputs; -(function (Outputs) { - Outputs["CacheHit"] = "cache-hit"; -})(Outputs = exports.Outputs || (exports.Outputs = {})); -var State; -(function (State) { - State["CachePrimaryKey"] = "CACHE_KEY"; - State["CacheMatchedKey"] = "CACHE_RESULT"; -})(State = exports.State || (exports.State = {})); -var Events; -(function (Events) { - Events["Key"] = "GITHUB_EVENT_NAME"; - Events["Push"] = "push"; - Events["PullRequest"] = "pull_request"; -})(Events = exports.Events || (exports.Events = {})); -exports.RefKey = "GITHUB_REF"; + +Object.defineProperty(exports, "__esModule", { value: true }); +exports.RefKey = exports.Events = exports.State = exports.Outputs = exports.Inputs = void 0; +var Inputs; +(function (Inputs) { + Inputs["Key"] = "key"; + Inputs["Path"] = "path"; + Inputs["RestoreKeys"] = "restore-keys"; + Inputs["UploadChunkSize"] = "upload-chunk-size"; +})(Inputs = exports.Inputs || (exports.Inputs = {})); +var Outputs; +(function (Outputs) { + Outputs["CacheHit"] = "cache-hit"; +})(Outputs = exports.Outputs || (exports.Outputs = {})); +var State; +(function (State) { + State["CachePrimaryKey"] = "CACHE_KEY"; + State["CacheMatchedKey"] = "CACHE_RESULT"; +})(State = exports.State || (exports.State = {})); +var Events; +(function (Events) { + Events["Key"] = "GITHUB_EVENT_NAME"; + Events["Push"] = "push"; + Events["PullRequest"] = "pull_request"; +})(Events = exports.Events || (exports.Events = {})); +exports.RefKey = "GITHUB_REF"; /***/ }), @@ -38691,92 +38691,92 @@ exports.default = { /***/ (function(__unusedmodule, exports, __webpack_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; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0; -const core = __importStar(__webpack_require__(470)); -const constants_1 = __webpack_require__(196); -function isGhes() { - const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); - return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; -} -exports.isGhes = isGhes; -function isExactKeyMatch(key, cacheKey) { - return !!(cacheKey && - cacheKey.localeCompare(key, undefined, { - sensitivity: "accent" - }) === 0); -} -exports.isExactKeyMatch = isExactKeyMatch; -function setCacheState(state) { - core.saveState(constants_1.State.CacheMatchedKey, state); -} -exports.setCacheState = setCacheState; -function setCacheHitOutput(isCacheHit) { - core.setOutput(constants_1.Outputs.CacheHit, isCacheHit.toString()); -} -exports.setCacheHitOutput = setCacheHitOutput; -function setOutputAndState(key, cacheKey) { - setCacheHitOutput(isExactKeyMatch(key, cacheKey)); - // Store the matched cache key if it exists - cacheKey && setCacheState(cacheKey); -} -exports.setOutputAndState = setOutputAndState; -function getCacheState() { - const cacheKey = core.getState(constants_1.State.CacheMatchedKey); - if (cacheKey) { - core.debug(`Cache state/key: ${cacheKey}`); - return cacheKey; - } - return undefined; -} -exports.getCacheState = getCacheState; -function logWarning(message) { - const warningPrefix = "[warning]"; - core.info(`${warningPrefix}${message}`); -} -exports.logWarning = logWarning; -// Cache token authorized for all events that are tied to a ref -// See GitHub Context https://help.github.com/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context -function isValidEvent() { - return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]); -} -exports.isValidEvent = isValidEvent; -function getInputAsArray(name, options) { - return core - .getInput(name, options) - .split("\n") - .map(s => s.trim()) - .filter(x => x !== ""); -} -exports.getInputAsArray = getInputAsArray; -function getInputAsInt(name, options) { - const value = parseInt(core.getInput(name, options)); - if (isNaN(value) || value < 0) { - return undefined; - } - return value; -} -exports.getInputAsInt = getInputAsInt; + +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; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0; +const core = __importStar(__webpack_require__(470)); +const constants_1 = __webpack_require__(196); +function isGhes() { + const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); + return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; +} +exports.isGhes = isGhes; +function isExactKeyMatch(key, cacheKey) { + return !!(cacheKey && + cacheKey.localeCompare(key, undefined, { + sensitivity: "accent" + }) === 0); +} +exports.isExactKeyMatch = isExactKeyMatch; +function setCacheState(state) { + core.saveState(constants_1.State.CacheMatchedKey, state); +} +exports.setCacheState = setCacheState; +function setCacheHitOutput(isCacheHit) { + core.setOutput(constants_1.Outputs.CacheHit, isCacheHit.toString()); +} +exports.setCacheHitOutput = setCacheHitOutput; +function setOutputAndState(key, cacheKey) { + setCacheHitOutput(isExactKeyMatch(key, cacheKey)); + // Store the matched cache key if it exists + cacheKey && setCacheState(cacheKey); +} +exports.setOutputAndState = setOutputAndState; +function getCacheState() { + const cacheKey = core.getState(constants_1.State.CacheMatchedKey); + if (cacheKey) { + core.debug(`Cache state/key: ${cacheKey}`); + return cacheKey; + } + return undefined; +} +exports.getCacheState = getCacheState; +function logWarning(message) { + const warningPrefix = "[warning]"; + core.info(`${warningPrefix}${message}`); +} +exports.logWarning = logWarning; +// Cache token authorized for all events that are tied to a ref +// See GitHub Context https://help.github.com/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context +function isValidEvent() { + return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]); +} +exports.isValidEvent = isValidEvent; +function getInputAsArray(name, options) { + return core + .getInput(name, options) + .split("\n") + .map(s => s.trim()) + .filter(x => x !== ""); +} +exports.getInputAsArray = getInputAsArray; +function getInputAsInt(name, options) { + const value = parseInt(core.getInput(name, options)); + if (isNaN(value) || value < 0) { + return undefined; + } + return value; +} +exports.getInputAsInt = getInputAsInt; /***/ }), @@ -49180,91 +49180,91 @@ Object.defineProperty(exports, "__esModule", { value: true }); /***/ (function(__unusedmodule, exports, __webpack_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 }); -const cache = __importStar(__webpack_require__(692)); -const core = __importStar(__webpack_require__(470)); -const constants_1 = __webpack_require__(196); -const utils = __importStar(__webpack_require__(443)); -function run() { - return __awaiter(this, void 0, void 0, function* () { - try { - if (utils.isGhes()) { - utils.logWarning("Cache action is not supported on GHES"); - utils.setCacheHitOutput(false); - return; - } - // Validate inputs, this can cause task failure - if (!utils.isValidEvent()) { - utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); - return; - } - const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true }); - core.saveState(constants_1.State.CachePrimaryKey, primaryKey); - const restoreKeys = utils.getInputAsArray(constants_1.Inputs.RestoreKeys); - const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { - required: true - }); - try { - const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys); - if (!cacheKey) { - core.info(`Cache not found for input keys: ${[ - primaryKey, - ...restoreKeys - ].join(", ")}`); - return; - } - // Store the matched cache key - utils.setCacheState(cacheKey); - const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey); - utils.setCacheHitOutput(isExactKeyMatch); - core.info(`Cache restored from key: ${cacheKey}`); - } - catch (error) { - if (error.name === cache.ValidationError.name) { - throw error; - } - else { - utils.logWarning(error.message); - utils.setCacheHitOutput(false); - } - } - } - catch (error) { - core.setFailed(error.message); - } - }); -} -run(); -exports.default = 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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const cache = __importStar(__webpack_require__(692)); +const core = __importStar(__webpack_require__(470)); +const constants_1 = __webpack_require__(196); +const utils = __importStar(__webpack_require__(443)); +function run() { + return __awaiter(this, void 0, void 0, function* () { + try { + if (utils.isGhes()) { + utils.logWarning("Cache action is not supported on GHES"); + utils.setCacheHitOutput(false); + return; + } + // Validate inputs, this can cause task failure + if (!utils.isValidEvent()) { + utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); + return; + } + const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true }); + core.saveState(constants_1.State.CachePrimaryKey, primaryKey); + const restoreKeys = utils.getInputAsArray(constants_1.Inputs.RestoreKeys); + const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { + required: true + }); + try { + const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys); + if (!cacheKey) { + core.info(`Cache not found for input keys: ${[ + primaryKey, + ...restoreKeys + ].join(", ")}`); + return; + } + // Store the matched cache key + utils.setCacheState(cacheKey); + const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey); + utils.setCacheHitOutput(isExactKeyMatch); + core.info(`Cache restored from key: ${cacheKey}`); + } + catch (error) { + if (error.name === cache.ValidationError.name) { + throw error; + } + else { + utils.logWarning(error.message); + utils.setCacheHitOutput(false); + } + } + } + catch (error) { + core.setFailed(error.message); + } + }); +} +run(); +exports.default = run; /***/ }), diff --git a/dist/save/index.js b/dist/save/index.js index 1aad367..3f2985f 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -5460,32 +5460,32 @@ Object.defineProperty(exports, "__esModule", { value: true }); /***/ (function(__unusedmodule, exports) { "use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -exports.RefKey = exports.Events = exports.State = exports.Outputs = exports.Inputs = void 0; -var Inputs; -(function (Inputs) { - Inputs["Key"] = "key"; - Inputs["Path"] = "path"; - Inputs["RestoreKeys"] = "restore-keys"; - Inputs["UploadChunkSize"] = "upload-chunk-size"; -})(Inputs = exports.Inputs || (exports.Inputs = {})); -var Outputs; -(function (Outputs) { - Outputs["CacheHit"] = "cache-hit"; -})(Outputs = exports.Outputs || (exports.Outputs = {})); -var State; -(function (State) { - State["CachePrimaryKey"] = "CACHE_KEY"; - State["CacheMatchedKey"] = "CACHE_RESULT"; -})(State = exports.State || (exports.State = {})); -var Events; -(function (Events) { - Events["Key"] = "GITHUB_EVENT_NAME"; - Events["Push"] = "push"; - Events["PullRequest"] = "pull_request"; -})(Events = exports.Events || (exports.Events = {})); -exports.RefKey = "GITHUB_REF"; + +Object.defineProperty(exports, "__esModule", { value: true }); +exports.RefKey = exports.Events = exports.State = exports.Outputs = exports.Inputs = void 0; +var Inputs; +(function (Inputs) { + Inputs["Key"] = "key"; + Inputs["Path"] = "path"; + Inputs["RestoreKeys"] = "restore-keys"; + Inputs["UploadChunkSize"] = "upload-chunk-size"; +})(Inputs = exports.Inputs || (exports.Inputs = {})); +var Outputs; +(function (Outputs) { + Outputs["CacheHit"] = "cache-hit"; +})(Outputs = exports.Outputs || (exports.Outputs = {})); +var State; +(function (State) { + State["CachePrimaryKey"] = "CACHE_KEY"; + State["CacheMatchedKey"] = "CACHE_RESULT"; +})(State = exports.State || (exports.State = {})); +var Events; +(function (Events) { + Events["Key"] = "GITHUB_EVENT_NAME"; + Events["Push"] = "push"; + Events["PullRequest"] = "pull_request"; +})(Events = exports.Events || (exports.Events = {})); +exports.RefKey = "GITHUB_REF"; /***/ }), @@ -38691,92 +38691,92 @@ exports.default = { /***/ (function(__unusedmodule, exports, __webpack_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; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0; -const core = __importStar(__webpack_require__(470)); -const constants_1 = __webpack_require__(196); -function isGhes() { - const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); - return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; -} -exports.isGhes = isGhes; -function isExactKeyMatch(key, cacheKey) { - return !!(cacheKey && - cacheKey.localeCompare(key, undefined, { - sensitivity: "accent" - }) === 0); -} -exports.isExactKeyMatch = isExactKeyMatch; -function setCacheState(state) { - core.saveState(constants_1.State.CacheMatchedKey, state); -} -exports.setCacheState = setCacheState; -function setCacheHitOutput(isCacheHit) { - core.setOutput(constants_1.Outputs.CacheHit, isCacheHit.toString()); -} -exports.setCacheHitOutput = setCacheHitOutput; -function setOutputAndState(key, cacheKey) { - setCacheHitOutput(isExactKeyMatch(key, cacheKey)); - // Store the matched cache key if it exists - cacheKey && setCacheState(cacheKey); -} -exports.setOutputAndState = setOutputAndState; -function getCacheState() { - const cacheKey = core.getState(constants_1.State.CacheMatchedKey); - if (cacheKey) { - core.debug(`Cache state/key: ${cacheKey}`); - return cacheKey; - } - return undefined; -} -exports.getCacheState = getCacheState; -function logWarning(message) { - const warningPrefix = "[warning]"; - core.info(`${warningPrefix}${message}`); -} -exports.logWarning = logWarning; -// Cache token authorized for all events that are tied to a ref -// See GitHub Context https://help.github.com/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context -function isValidEvent() { - return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]); -} -exports.isValidEvent = isValidEvent; -function getInputAsArray(name, options) { - return core - .getInput(name, options) - .split("\n") - .map(s => s.trim()) - .filter(x => x !== ""); -} -exports.getInputAsArray = getInputAsArray; -function getInputAsInt(name, options) { - const value = parseInt(core.getInput(name, options)); - if (isNaN(value) || value < 0) { - return undefined; - } - return value; -} -exports.getInputAsInt = getInputAsInt; + +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; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0; +const core = __importStar(__webpack_require__(470)); +const constants_1 = __webpack_require__(196); +function isGhes() { + const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); + return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; +} +exports.isGhes = isGhes; +function isExactKeyMatch(key, cacheKey) { + return !!(cacheKey && + cacheKey.localeCompare(key, undefined, { + sensitivity: "accent" + }) === 0); +} +exports.isExactKeyMatch = isExactKeyMatch; +function setCacheState(state) { + core.saveState(constants_1.State.CacheMatchedKey, state); +} +exports.setCacheState = setCacheState; +function setCacheHitOutput(isCacheHit) { + core.setOutput(constants_1.Outputs.CacheHit, isCacheHit.toString()); +} +exports.setCacheHitOutput = setCacheHitOutput; +function setOutputAndState(key, cacheKey) { + setCacheHitOutput(isExactKeyMatch(key, cacheKey)); + // Store the matched cache key if it exists + cacheKey && setCacheState(cacheKey); +} +exports.setOutputAndState = setOutputAndState; +function getCacheState() { + const cacheKey = core.getState(constants_1.State.CacheMatchedKey); + if (cacheKey) { + core.debug(`Cache state/key: ${cacheKey}`); + return cacheKey; + } + return undefined; +} +exports.getCacheState = getCacheState; +function logWarning(message) { + const warningPrefix = "[warning]"; + core.info(`${warningPrefix}${message}`); +} +exports.logWarning = logWarning; +// Cache token authorized for all events that are tied to a ref +// See GitHub Context https://help.github.com/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context +function isValidEvent() { + return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]); +} +exports.isValidEvent = isValidEvent; +function getInputAsArray(name, options) { + return core + .getInput(name, options) + .split("\n") + .map(s => s.trim()) + .filter(x => x !== ""); +} +exports.getInputAsArray = getInputAsArray; +function getInputAsInt(name, options) { + const value = parseInt(core.getInput(name, options)); + if (isNaN(value) || value < 0) { + return undefined; + } + return value; +} +exports.getInputAsInt = getInputAsInt; /***/ }), @@ -47120,90 +47120,94 @@ exports.default = _default; /***/ (function(__unusedmodule, exports, __webpack_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 }); -const cache = __importStar(__webpack_require__(692)); -const core = __importStar(__webpack_require__(470)); -const constants_1 = __webpack_require__(196); -const utils = __importStar(__webpack_require__(443)); -function run() { - return __awaiter(this, void 0, void 0, function* () { - try { - if (utils.isGhes()) { - utils.logWarning("Cache action is not supported on GHES"); - return; - } - if (!utils.isValidEvent()) { - utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); - return; - } - const state = utils.getCacheState(); - // Inputs are re-evaluted before the post action, so we want the original key used for restore - const primaryKey = core.getState(constants_1.State.CachePrimaryKey); - if (!primaryKey) { - utils.logWarning(`Error retrieving key from state.`); - return; - } - if (utils.isExactKeyMatch(primaryKey, state)) { - core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); - return; - } - const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { - required: true - }); - try { - yield cache.saveCache(cachePaths, primaryKey, { - uploadChunkSize: utils.getInputAsInt(constants_1.Inputs.UploadChunkSize) - }); - core.info(`Cache saved with key: ${primaryKey}`); - } - catch (error) { - if (error.name === cache.ValidationError.name) { - throw error; - } - else if (error.name === cache.ReserveCacheError.name) { - core.info(error.message); - } - else { - utils.logWarning(error.message); - } - } - } - catch (error) { - utils.logWarning(error.message); - } - }); -} -run(); -exports.default = 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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const cache = __importStar(__webpack_require__(692)); +const core = __importStar(__webpack_require__(470)); +const constants_1 = __webpack_require__(196); +const utils = __importStar(__webpack_require__(443)); +// 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 => utils.logWarning(e.message)); +function run() { + return __awaiter(this, void 0, void 0, function* () { + try { + if (utils.isGhes()) { + utils.logWarning("Cache action is not supported on GHES"); + return; + } + if (!utils.isValidEvent()) { + utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); + return; + } + const state = utils.getCacheState(); + // Inputs are re-evaluted before the post action, so we want the original key used for restore + const primaryKey = core.getState(constants_1.State.CachePrimaryKey); + if (!primaryKey) { + utils.logWarning(`Error retrieving key from state.`); + return; + } + if (utils.isExactKeyMatch(primaryKey, state)) { + core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); + return; + } + const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { + required: true + }); + try { + yield cache.saveCache(cachePaths, primaryKey, { + uploadChunkSize: utils.getInputAsInt(constants_1.Inputs.UploadChunkSize) + }); + core.info(`Cache saved with key: ${primaryKey}`); + } + catch (error) { + if (error.name === cache.ValidationError.name) { + throw error; + } + else if (error.name === cache.ReserveCacheError.name) { + core.info(error.message); + } + else { + utils.logWarning(error.message); + } + } + } + catch (error) { + utils.logWarning(error.message); + } + }); +} +run(); +exports.default = run; /***/ }), diff --git a/package-lock.json b/package-lock.json index aa4f6bf..1c8a1cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "cache", - "version": "2.1.5", + "version": "2.1.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 167fe9f..5fe21e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cache", - "version": "2.1.5", + "version": "2.1.6", "private": true, "description": "Cache dependencies and build outputs", "main": "dist/restore/index.js", diff --git a/src/save.ts b/src/save.ts index 5e52249..cdca9db 100644 --- a/src/save.ts +++ b/src/save.ts @@ -4,6 +4,11 @@ import * as core from "@actions/core"; import { Events, Inputs, State } from "./constants"; import * as utils from "./utils/actionUtils"; +// 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 => utils.logWarning(e.message)); + async function run(): Promise { try { if (utils.isGhes()) { From 0638051e9af2c23d10bb70fa9beffcad6cff9ce3 Mon Sep 17 00:00:00 2001 From: Peter Mescalchin Date: Tue, 1 Jun 2021 23:39:29 +1000 Subject: [PATCH 4/9] Golang example tweak - add `go-build` path - rebuild page TOC (#577) --- examples.md | 128 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 84 insertions(+), 44 deletions(-) diff --git a/examples.md b/examples.md index 7fb2ffc..513f69d 100644 --- a/examples.md +++ b/examples.md @@ -1,39 +1,44 @@ # Examples -- [Examples](#examples) - - [C# - NuGet](#c---nuget) - - [D - DUB](#d---dub) - - [Elixir - Mix](#elixir---mix) - - [Go - Modules](#go---modules) - - [Haskell - Cabal](#haskell---cabal) - - [Java - Gradle](#java---gradle) - - [Java - Maven](#java---maven) - - [Node - npm](#node---npm) - - [macOS and Ubuntu](#macos-and-ubuntu) - - [Windows](#windows) - - [Using multiple systems and `npm config`](#using-multiple-systems-and-npm-config) - - [Node - Lerna](#node---lerna) - - [Node - Yarn](#node---yarn) - - [Node - Yarn 2](#node---yarn-2) - - [OCaml/Reason - esy](#ocamlreason---esy) - - [PHP - Composer](#php---composer) - - [Python - pip](#python---pip) - - [Simple example](#simple-example) - - [Multiple OSes in a workflow](#multiple-oss-in-a-workflow) - - [Using pip to get cache location](#using-pip-to-get-cache-location) - - [Using a script to get cache location](#using-a-script-to-get-cache-location) - - [Python - pipenv](#python---pipenv) - - [R - renv](#r---renv) - - [Simple example](#simple-example-1) - - [Multiple OSes in a workflow](#multiple-oss-in-a-workflow-1) - - [Ruby - Bundler](#ruby---bundler) - - [Rust - Cargo](#rust---cargo) - - [Scala - SBT](#scala---sbt) - - [Swift, Objective-C - Carthage](#swift-objective-c---carthage) - - [Swift, Objective-C - CocoaPods](#swift-objective-c---cocoapods) - - [Swift - Swift Package Manager](#swift---swift-package-manager) +- [C# - NuGet](#c---nuget) +- [D - DUB](#d---dub) + - [POSIX](#posix) + - [Windows](#windows) +- [Elixir - Mix](#elixir---mix) +- [Go - Modules](#go---modules) + - [Linux](#linux) + - [macOS](#macos) + - [Windows](#windows-1) +- [Haskell - Cabal](#haskell---cabal) +- [Java - Gradle](#java---gradle) +- [Java - Maven](#java---maven) +- [Node - npm](#node---npm) + - [macOS and Ubuntu](#macos-and-ubuntu) + - [Windows](#windows-2) + - [Using multiple systems and `npm config`](#using-multiple-systems-and-npm-config) +- [Node - Lerna](#node---lerna) +- [Node - Yarn](#node---yarn) +- [Node - Yarn 2](#node---yarn-2) +- [OCaml/Reason - esy](#ocamlreason---esy) +- [PHP - Composer](#php---composer) +- [Python - pip](#python---pip) + - [Simple example](#simple-example) + - [Multiple OS's in a workflow](#multiple-oss-in-a-workflow) + - [Multiple OS's in a workflow with a matrix](#multiple-oss-in-a-workflow-with-a-matrix) + - [Using pip to get cache location](#using-pip-to-get-cache-location) +- [Python - pipenv](#python---pipenv) +- [R - renv](#r---renv) + - [Simple example](#simple-example-1) + - [Multiple OS's in a workflow](#multiple-oss-in-a-workflow-1) +- [Ruby - Bundler](#ruby---bundler) +- [Rust - Cargo](#rust---cargo) +- [Scala - SBT](#scala---sbt) +- [Swift, Objective-C - Carthage](#swift-objective-c---carthage) +- [Swift, Objective-C - CocoaPods](#swift-objective-c---cocoapods) +- [Swift - Swift Package Manager](#swift---swift-package-manager) ## C# - NuGet + Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files#locking-dependencies): ```yaml @@ -47,10 +52,11 @@ Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/packa Depending on the environment, huge packages might be pre-installed in the global cache folder. With `actions/cache@v2` you can now exclude unwanted packages with [exclude pattern](https://github.com/actions/toolkit/tree/main/packages/glob#exclude-patterns) + ```yaml - uses: actions/cache@v2 with: - path: | + path: | ~/.nuget/packages !~/.nuget/packages/unwanted key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} @@ -111,10 +117,40 @@ steps: ## Go - Modules +### Linux + ```yaml - uses: actions/cache@v2 with: - path: ~/go/pkg/mod + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- +``` + +### macOS + +```yaml +- uses: actions/cache@v2 + with: + path: | + ~/Library/Caches/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- +``` + +### Windows + +```yaml +- uses: actions/cache@v2 + with: + path: | + %LocalAppData%\go-build + ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | ${{ runner.os }}-go- @@ -241,8 +277,8 @@ The yarn cache directory will depend on your operating system and version of `ya ${{ runner.os }}-yarn- ``` - ## Node - Yarn 2 + The yarn 2 cache directory will depend on your config. See https://yarnpkg.com/configuration/yarnrc#cacheFolder for more info. ```yaml @@ -260,6 +296,7 @@ The yarn 2 cache directory will depend on your config. See https://yarnpkg.com/c ``` ## OCaml/Reason - esy + Esy allows you to export built dependencies and import pre-built dependencies. ```yaml - name: Restore Cache @@ -280,13 +317,12 @@ Esy allows you to export built dependencies and import pre-built dependencies. ...(Build job)... # Re-export dependencies if anything has changed or if it is the first time - - name: Setting dependency cache + - name: Setting dependency cache run: | esy export-dependencies if: steps.restore-cache.outputs.cache-hit != 'true' ``` - ## PHP - Composer ```yaml @@ -307,11 +343,13 @@ Esy allows you to export built dependencies and import pre-built dependencies. For pip, the cache directory will vary by OS. See https://pip.pypa.io/en/stable/reference/pip_install/#caching Locations: - - Ubuntu: `~/.cache/pip` - - Windows: `~\AppData\Local\pip\Cache` - - macOS: `~/Library/Caches/pip` + +- Ubuntu: `~/.cache/pip` +- Windows: `~\AppData\Local\pip\Cache` +- macOS: `~/Library/Caches/pip` ### Simple example + ```yaml - uses: actions/cache@v2 with: @@ -410,11 +448,13 @@ jobs: For renv, the cache directory will vary by OS. Look at https://rstudio.github.io/renv/articles/renv.html#cache Locations: - - Ubuntu: `~/.local/share/renv` - - macOS: `~/Library/Application Support/renv` - - Windows: `%LOCALAPPDATA%/renv` + +- Ubuntu: `~/.local/share/renv` +- macOS: `~/Library/Application Support/renv` +- Windows: `%LOCALAPPDATA%/renv` ### Simple example + ```yaml - uses: actions/cache@v2 with: @@ -490,7 +530,7 @@ whenever possible: - name: Cache SBT uses: actions/cache@v2 with: - path: | + path: | ~/.ivy2/cache ~/.sbt key: ${{ runner.os }}-sbt-${{ hashFiles('**/build.sbt') }} From 5807af2642b6ffc80df306359122fd0ff9b571b8 Mon Sep 17 00:00:00 2001 From: andrewdotn Date: Thu, 15 Jul 2021 12:37:10 -0600 Subject: [PATCH 5/9] Fix bugs in example of how to use with pipenv (#607) * Fix bugs in example of how to use with pipenv The current example of how to use `@actions/cache` with pipenv has two problems: 1. The cached virtualenv that pipenv creates has `bin/python` as a symlink into paths like `/opt/hostedtoolcache/Python/3.7.11` that explicitly include the patch version of python. When the cache is restored onto a machine running a slightly different version of python, e.g., when GitHub upgrades its runners from python 3.7.10 to 3.7.11, then any attempt to run python in the workflow mysteriously fails with errors like `Failed to load paths: /bin/sh: 1: /home/runner/.local/share/virtualenvs/myrepo-sOIMCiTO/bin/python: not found`. Therefore the patch version of python should be included in the cache key. 2. `pipenv --install` has the unfortunate behaviour of not cleaning out any pre-existing packages. That is, if the `Pipfile` first contains dependencies on `foo` and `bar`, and then you remove `bar` from the `Pipfile` and run `pipenv install` again, `bar` is still included in the virtualenv. This can cause false-positive test failures: when a dependency is removed from the `Pipfile` but there is still code that relies on the removed dependency, tests can still pass if the dependency comes from the cache based on a previous revision of `Pipfile.lock`. Therefore `restore-keys` should not be set. This PR attempts to address both of these issues. * Explain why setup-python is included in example --- examples.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples.md b/examples.md index 513f69d..1f6ecef 100644 --- a/examples.md +++ b/examples.md @@ -435,12 +435,17 @@ jobs: ## Python - pipenv ```yaml +- name: Set up Python + # The actions/cache step below uses this id to get the exact python version + id: setup-python + uses: actions/setup-python@v2 + + ⋮ + - uses: actions/cache@v2 with: path: ~/.local/share/virtualenvs - key: ${{ runner.os }}-pipenv-${{ hashFiles('Pipfile.lock') }} - restore-keys: | - ${{ runner.os }}-pipenv- + key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipenv-${{ hashFiles('Pipfile.lock') }} ``` ## R - renv From 2ebdcff279bac9704c2b319b25ac54b63d6800c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Stanislav?= Date: Tue, 20 Jul 2021 16:02:26 +0200 Subject: [PATCH 6/9] Add "see more" link to GHE-not-supported warning (#609) * Add "see more" link to GHE-not-supported warning I lived for several months thinking that support for caching action on GHE is just a matter of time, because it's such an important thing to have. Only today, I discovered that originally it was not planned at all. And that people already created some workarounds. So I hope that linking the issue from the warning message will save other people from what happened to me :-) * Update new GHE-not-supported message in tests * Update generated dist files --- __tests__/restore.test.ts | 2 +- __tests__/save.test.ts | 2 +- dist/restore/index.js | 394 ++++++++++++++++++------------------- dist/save/index.js | 400 +++++++++++++++++++------------------- src/restore.ts | 4 +- src/save.ts | 4 +- 6 files changed, 405 insertions(+), 401 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index 446237c..4761782 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -68,7 +68,7 @@ test("restore on GHES should no-op", async () => { expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); expect(setCacheHitOutputMock).toHaveBeenCalledWith(false); expect(logWarningMock).toHaveBeenCalledWith( - "Cache action is not supported on GHES" + "Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details" ); }); diff --git a/__tests__/save.test.ts b/__tests__/save.test.ts index b806d50..30178a2 100644 --- a/__tests__/save.test.ts +++ b/__tests__/save.test.ts @@ -111,7 +111,7 @@ test("save on GHES should no-op", async () => { expect(saveCacheMock).toHaveBeenCalledTimes(0); expect(logWarningMock).toHaveBeenCalledWith( - "Cache action is not supported on GHES" + "Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details" ); }); diff --git a/dist/restore/index.js b/dist/restore/index.js index 7174733..59dd8fb 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -5460,32 +5460,32 @@ Object.defineProperty(exports, "__esModule", { value: true }); /***/ (function(__unusedmodule, exports) { "use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -exports.RefKey = exports.Events = exports.State = exports.Outputs = exports.Inputs = void 0; -var Inputs; -(function (Inputs) { - Inputs["Key"] = "key"; - Inputs["Path"] = "path"; - Inputs["RestoreKeys"] = "restore-keys"; - Inputs["UploadChunkSize"] = "upload-chunk-size"; -})(Inputs = exports.Inputs || (exports.Inputs = {})); -var Outputs; -(function (Outputs) { - Outputs["CacheHit"] = "cache-hit"; -})(Outputs = exports.Outputs || (exports.Outputs = {})); -var State; -(function (State) { - State["CachePrimaryKey"] = "CACHE_KEY"; - State["CacheMatchedKey"] = "CACHE_RESULT"; -})(State = exports.State || (exports.State = {})); -var Events; -(function (Events) { - Events["Key"] = "GITHUB_EVENT_NAME"; - Events["Push"] = "push"; - Events["PullRequest"] = "pull_request"; -})(Events = exports.Events || (exports.Events = {})); -exports.RefKey = "GITHUB_REF"; + +Object.defineProperty(exports, "__esModule", { value: true }); +exports.RefKey = exports.Events = exports.State = exports.Outputs = exports.Inputs = void 0; +var Inputs; +(function (Inputs) { + Inputs["Key"] = "key"; + Inputs["Path"] = "path"; + Inputs["RestoreKeys"] = "restore-keys"; + Inputs["UploadChunkSize"] = "upload-chunk-size"; +})(Inputs = exports.Inputs || (exports.Inputs = {})); +var Outputs; +(function (Outputs) { + Outputs["CacheHit"] = "cache-hit"; +})(Outputs = exports.Outputs || (exports.Outputs = {})); +var State; +(function (State) { + State["CachePrimaryKey"] = "CACHE_KEY"; + State["CacheMatchedKey"] = "CACHE_RESULT"; +})(State = exports.State || (exports.State = {})); +var Events; +(function (Events) { + Events["Key"] = "GITHUB_EVENT_NAME"; + Events["Push"] = "push"; + Events["PullRequest"] = "pull_request"; +})(Events = exports.Events || (exports.Events = {})); +exports.RefKey = "GITHUB_REF"; /***/ }), @@ -38691,92 +38691,92 @@ exports.default = { /***/ (function(__unusedmodule, exports, __webpack_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; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0; -const core = __importStar(__webpack_require__(470)); -const constants_1 = __webpack_require__(196); -function isGhes() { - const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); - return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; -} -exports.isGhes = isGhes; -function isExactKeyMatch(key, cacheKey) { - return !!(cacheKey && - cacheKey.localeCompare(key, undefined, { - sensitivity: "accent" - }) === 0); -} -exports.isExactKeyMatch = isExactKeyMatch; -function setCacheState(state) { - core.saveState(constants_1.State.CacheMatchedKey, state); -} -exports.setCacheState = setCacheState; -function setCacheHitOutput(isCacheHit) { - core.setOutput(constants_1.Outputs.CacheHit, isCacheHit.toString()); -} -exports.setCacheHitOutput = setCacheHitOutput; -function setOutputAndState(key, cacheKey) { - setCacheHitOutput(isExactKeyMatch(key, cacheKey)); - // Store the matched cache key if it exists - cacheKey && setCacheState(cacheKey); -} -exports.setOutputAndState = setOutputAndState; -function getCacheState() { - const cacheKey = core.getState(constants_1.State.CacheMatchedKey); - if (cacheKey) { - core.debug(`Cache state/key: ${cacheKey}`); - return cacheKey; - } - return undefined; -} -exports.getCacheState = getCacheState; -function logWarning(message) { - const warningPrefix = "[warning]"; - core.info(`${warningPrefix}${message}`); -} -exports.logWarning = logWarning; -// Cache token authorized for all events that are tied to a ref -// See GitHub Context https://help.github.com/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context -function isValidEvent() { - return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]); -} -exports.isValidEvent = isValidEvent; -function getInputAsArray(name, options) { - return core - .getInput(name, options) - .split("\n") - .map(s => s.trim()) - .filter(x => x !== ""); -} -exports.getInputAsArray = getInputAsArray; -function getInputAsInt(name, options) { - const value = parseInt(core.getInput(name, options)); - if (isNaN(value) || value < 0) { - return undefined; - } - return value; -} -exports.getInputAsInt = getInputAsInt; + +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; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0; +const core = __importStar(__webpack_require__(470)); +const constants_1 = __webpack_require__(196); +function isGhes() { + const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); + return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; +} +exports.isGhes = isGhes; +function isExactKeyMatch(key, cacheKey) { + return !!(cacheKey && + cacheKey.localeCompare(key, undefined, { + sensitivity: "accent" + }) === 0); +} +exports.isExactKeyMatch = isExactKeyMatch; +function setCacheState(state) { + core.saveState(constants_1.State.CacheMatchedKey, state); +} +exports.setCacheState = setCacheState; +function setCacheHitOutput(isCacheHit) { + core.setOutput(constants_1.Outputs.CacheHit, isCacheHit.toString()); +} +exports.setCacheHitOutput = setCacheHitOutput; +function setOutputAndState(key, cacheKey) { + setCacheHitOutput(isExactKeyMatch(key, cacheKey)); + // Store the matched cache key if it exists + cacheKey && setCacheState(cacheKey); +} +exports.setOutputAndState = setOutputAndState; +function getCacheState() { + const cacheKey = core.getState(constants_1.State.CacheMatchedKey); + if (cacheKey) { + core.debug(`Cache state/key: ${cacheKey}`); + return cacheKey; + } + return undefined; +} +exports.getCacheState = getCacheState; +function logWarning(message) { + const warningPrefix = "[warning]"; + core.info(`${warningPrefix}${message}`); +} +exports.logWarning = logWarning; +// Cache token authorized for all events that are tied to a ref +// See GitHub Context https://help.github.com/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context +function isValidEvent() { + return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]); +} +exports.isValidEvent = isValidEvent; +function getInputAsArray(name, options) { + return core + .getInput(name, options) + .split("\n") + .map(s => s.trim()) + .filter(x => x !== ""); +} +exports.getInputAsArray = getInputAsArray; +function getInputAsInt(name, options) { + const value = parseInt(core.getInput(name, options)); + if (isNaN(value) || value < 0) { + return undefined; + } + return value; +} +exports.getInputAsInt = getInputAsInt; /***/ }), @@ -49180,91 +49180,91 @@ Object.defineProperty(exports, "__esModule", { value: true }); /***/ (function(__unusedmodule, exports, __webpack_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 }); -const cache = __importStar(__webpack_require__(692)); -const core = __importStar(__webpack_require__(470)); -const constants_1 = __webpack_require__(196); -const utils = __importStar(__webpack_require__(443)); -function run() { - return __awaiter(this, void 0, void 0, function* () { - try { - if (utils.isGhes()) { - utils.logWarning("Cache action is not supported on GHES"); - utils.setCacheHitOutput(false); - return; - } - // Validate inputs, this can cause task failure - if (!utils.isValidEvent()) { - utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); - return; - } - const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true }); - core.saveState(constants_1.State.CachePrimaryKey, primaryKey); - const restoreKeys = utils.getInputAsArray(constants_1.Inputs.RestoreKeys); - const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { - required: true - }); - try { - const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys); - if (!cacheKey) { - core.info(`Cache not found for input keys: ${[ - primaryKey, - ...restoreKeys - ].join(", ")}`); - return; - } - // Store the matched cache key - utils.setCacheState(cacheKey); - const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey); - utils.setCacheHitOutput(isExactKeyMatch); - core.info(`Cache restored from key: ${cacheKey}`); - } - catch (error) { - if (error.name === cache.ValidationError.name) { - throw error; - } - else { - utils.logWarning(error.message); - utils.setCacheHitOutput(false); - } - } - } - catch (error) { - core.setFailed(error.message); - } - }); -} -run(); -exports.default = 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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const cache = __importStar(__webpack_require__(692)); +const core = __importStar(__webpack_require__(470)); +const constants_1 = __webpack_require__(196); +const utils = __importStar(__webpack_require__(443)); +function run() { + return __awaiter(this, void 0, void 0, function* () { + try { + if (utils.isGhes()) { + utils.logWarning("Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details"); + utils.setCacheHitOutput(false); + return; + } + // Validate inputs, this can cause task failure + if (!utils.isValidEvent()) { + utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); + return; + } + const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true }); + core.saveState(constants_1.State.CachePrimaryKey, primaryKey); + const restoreKeys = utils.getInputAsArray(constants_1.Inputs.RestoreKeys); + const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { + required: true + }); + try { + const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys); + if (!cacheKey) { + core.info(`Cache not found for input keys: ${[ + primaryKey, + ...restoreKeys + ].join(", ")}`); + return; + } + // Store the matched cache key + utils.setCacheState(cacheKey); + const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey); + utils.setCacheHitOutput(isExactKeyMatch); + core.info(`Cache restored from key: ${cacheKey}`); + } + catch (error) { + if (error.name === cache.ValidationError.name) { + throw error; + } + else { + utils.logWarning(error.message); + utils.setCacheHitOutput(false); + } + } + } + catch (error) { + core.setFailed(error.message); + } + }); +} +run(); +exports.default = run; /***/ }), diff --git a/dist/save/index.js b/dist/save/index.js index 3f2985f..bd78ec6 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -5460,32 +5460,32 @@ Object.defineProperty(exports, "__esModule", { value: true }); /***/ (function(__unusedmodule, exports) { "use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -exports.RefKey = exports.Events = exports.State = exports.Outputs = exports.Inputs = void 0; -var Inputs; -(function (Inputs) { - Inputs["Key"] = "key"; - Inputs["Path"] = "path"; - Inputs["RestoreKeys"] = "restore-keys"; - Inputs["UploadChunkSize"] = "upload-chunk-size"; -})(Inputs = exports.Inputs || (exports.Inputs = {})); -var Outputs; -(function (Outputs) { - Outputs["CacheHit"] = "cache-hit"; -})(Outputs = exports.Outputs || (exports.Outputs = {})); -var State; -(function (State) { - State["CachePrimaryKey"] = "CACHE_KEY"; - State["CacheMatchedKey"] = "CACHE_RESULT"; -})(State = exports.State || (exports.State = {})); -var Events; -(function (Events) { - Events["Key"] = "GITHUB_EVENT_NAME"; - Events["Push"] = "push"; - Events["PullRequest"] = "pull_request"; -})(Events = exports.Events || (exports.Events = {})); -exports.RefKey = "GITHUB_REF"; + +Object.defineProperty(exports, "__esModule", { value: true }); +exports.RefKey = exports.Events = exports.State = exports.Outputs = exports.Inputs = void 0; +var Inputs; +(function (Inputs) { + Inputs["Key"] = "key"; + Inputs["Path"] = "path"; + Inputs["RestoreKeys"] = "restore-keys"; + Inputs["UploadChunkSize"] = "upload-chunk-size"; +})(Inputs = exports.Inputs || (exports.Inputs = {})); +var Outputs; +(function (Outputs) { + Outputs["CacheHit"] = "cache-hit"; +})(Outputs = exports.Outputs || (exports.Outputs = {})); +var State; +(function (State) { + State["CachePrimaryKey"] = "CACHE_KEY"; + State["CacheMatchedKey"] = "CACHE_RESULT"; +})(State = exports.State || (exports.State = {})); +var Events; +(function (Events) { + Events["Key"] = "GITHUB_EVENT_NAME"; + Events["Push"] = "push"; + Events["PullRequest"] = "pull_request"; +})(Events = exports.Events || (exports.Events = {})); +exports.RefKey = "GITHUB_REF"; /***/ }), @@ -38691,92 +38691,92 @@ exports.default = { /***/ (function(__unusedmodule, exports, __webpack_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; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0; -const core = __importStar(__webpack_require__(470)); -const constants_1 = __webpack_require__(196); -function isGhes() { - const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); - return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; -} -exports.isGhes = isGhes; -function isExactKeyMatch(key, cacheKey) { - return !!(cacheKey && - cacheKey.localeCompare(key, undefined, { - sensitivity: "accent" - }) === 0); -} -exports.isExactKeyMatch = isExactKeyMatch; -function setCacheState(state) { - core.saveState(constants_1.State.CacheMatchedKey, state); -} -exports.setCacheState = setCacheState; -function setCacheHitOutput(isCacheHit) { - core.setOutput(constants_1.Outputs.CacheHit, isCacheHit.toString()); -} -exports.setCacheHitOutput = setCacheHitOutput; -function setOutputAndState(key, cacheKey) { - setCacheHitOutput(isExactKeyMatch(key, cacheKey)); - // Store the matched cache key if it exists - cacheKey && setCacheState(cacheKey); -} -exports.setOutputAndState = setOutputAndState; -function getCacheState() { - const cacheKey = core.getState(constants_1.State.CacheMatchedKey); - if (cacheKey) { - core.debug(`Cache state/key: ${cacheKey}`); - return cacheKey; - } - return undefined; -} -exports.getCacheState = getCacheState; -function logWarning(message) { - const warningPrefix = "[warning]"; - core.info(`${warningPrefix}${message}`); -} -exports.logWarning = logWarning; -// Cache token authorized for all events that are tied to a ref -// See GitHub Context https://help.github.com/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context -function isValidEvent() { - return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]); -} -exports.isValidEvent = isValidEvent; -function getInputAsArray(name, options) { - return core - .getInput(name, options) - .split("\n") - .map(s => s.trim()) - .filter(x => x !== ""); -} -exports.getInputAsArray = getInputAsArray; -function getInputAsInt(name, options) { - const value = parseInt(core.getInput(name, options)); - if (isNaN(value) || value < 0) { - return undefined; - } - return value; -} -exports.getInputAsInt = getInputAsInt; + +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; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0; +const core = __importStar(__webpack_require__(470)); +const constants_1 = __webpack_require__(196); +function isGhes() { + const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); + return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; +} +exports.isGhes = isGhes; +function isExactKeyMatch(key, cacheKey) { + return !!(cacheKey && + cacheKey.localeCompare(key, undefined, { + sensitivity: "accent" + }) === 0); +} +exports.isExactKeyMatch = isExactKeyMatch; +function setCacheState(state) { + core.saveState(constants_1.State.CacheMatchedKey, state); +} +exports.setCacheState = setCacheState; +function setCacheHitOutput(isCacheHit) { + core.setOutput(constants_1.Outputs.CacheHit, isCacheHit.toString()); +} +exports.setCacheHitOutput = setCacheHitOutput; +function setOutputAndState(key, cacheKey) { + setCacheHitOutput(isExactKeyMatch(key, cacheKey)); + // Store the matched cache key if it exists + cacheKey && setCacheState(cacheKey); +} +exports.setOutputAndState = setOutputAndState; +function getCacheState() { + const cacheKey = core.getState(constants_1.State.CacheMatchedKey); + if (cacheKey) { + core.debug(`Cache state/key: ${cacheKey}`); + return cacheKey; + } + return undefined; +} +exports.getCacheState = getCacheState; +function logWarning(message) { + const warningPrefix = "[warning]"; + core.info(`${warningPrefix}${message}`); +} +exports.logWarning = logWarning; +// Cache token authorized for all events that are tied to a ref +// See GitHub Context https://help.github.com/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context +function isValidEvent() { + return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]); +} +exports.isValidEvent = isValidEvent; +function getInputAsArray(name, options) { + return core + .getInput(name, options) + .split("\n") + .map(s => s.trim()) + .filter(x => x !== ""); +} +exports.getInputAsArray = getInputAsArray; +function getInputAsInt(name, options) { + const value = parseInt(core.getInput(name, options)); + if (isNaN(value) || value < 0) { + return undefined; + } + return value; +} +exports.getInputAsInt = getInputAsInt; /***/ }), @@ -47120,94 +47120,94 @@ exports.default = _default; /***/ (function(__unusedmodule, exports, __webpack_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 }); -const cache = __importStar(__webpack_require__(692)); -const core = __importStar(__webpack_require__(470)); -const constants_1 = __webpack_require__(196); -const utils = __importStar(__webpack_require__(443)); -// 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 => utils.logWarning(e.message)); -function run() { - return __awaiter(this, void 0, void 0, function* () { - try { - if (utils.isGhes()) { - utils.logWarning("Cache action is not supported on GHES"); - return; - } - if (!utils.isValidEvent()) { - utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); - return; - } - const state = utils.getCacheState(); - // Inputs are re-evaluted before the post action, so we want the original key used for restore - const primaryKey = core.getState(constants_1.State.CachePrimaryKey); - if (!primaryKey) { - utils.logWarning(`Error retrieving key from state.`); - return; - } - if (utils.isExactKeyMatch(primaryKey, state)) { - core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); - return; - } - const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { - required: true - }); - try { - yield cache.saveCache(cachePaths, primaryKey, { - uploadChunkSize: utils.getInputAsInt(constants_1.Inputs.UploadChunkSize) - }); - core.info(`Cache saved with key: ${primaryKey}`); - } - catch (error) { - if (error.name === cache.ValidationError.name) { - throw error; - } - else if (error.name === cache.ReserveCacheError.name) { - core.info(error.message); - } - else { - utils.logWarning(error.message); - } - } - } - catch (error) { - utils.logWarning(error.message); - } - }); -} -run(); -exports.default = 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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const cache = __importStar(__webpack_require__(692)); +const core = __importStar(__webpack_require__(470)); +const constants_1 = __webpack_require__(196); +const utils = __importStar(__webpack_require__(443)); +// 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 => utils.logWarning(e.message)); +function run() { + return __awaiter(this, void 0, void 0, function* () { + try { + if (utils.isGhes()) { + utils.logWarning("Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details"); + return; + } + if (!utils.isValidEvent()) { + utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); + return; + } + const state = utils.getCacheState(); + // Inputs are re-evaluted before the post action, so we want the original key used for restore + const primaryKey = core.getState(constants_1.State.CachePrimaryKey); + if (!primaryKey) { + utils.logWarning(`Error retrieving key from state.`); + return; + } + if (utils.isExactKeyMatch(primaryKey, state)) { + core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); + return; + } + const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { + required: true + }); + try { + yield cache.saveCache(cachePaths, primaryKey, { + uploadChunkSize: utils.getInputAsInt(constants_1.Inputs.UploadChunkSize) + }); + core.info(`Cache saved with key: ${primaryKey}`); + } + catch (error) { + if (error.name === cache.ValidationError.name) { + throw error; + } + else if (error.name === cache.ReserveCacheError.name) { + core.info(error.message); + } + else { + utils.logWarning(error.message); + } + } + } + catch (error) { + utils.logWarning(error.message); + } + }); +} +run(); +exports.default = run; /***/ }), diff --git a/src/restore.ts b/src/restore.ts index 0fa6333..d411459 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -7,7 +7,9 @@ import * as utils from "./utils/actionUtils"; async function run(): Promise { try { if (utils.isGhes()) { - utils.logWarning("Cache action is not supported on GHES"); + utils.logWarning( + "Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details" + ); utils.setCacheHitOutput(false); return; } diff --git a/src/save.ts b/src/save.ts index cdca9db..fc0eb73 100644 --- a/src/save.ts +++ b/src/save.ts @@ -12,7 +12,9 @@ process.on("uncaughtException", e => utils.logWarning(e.message)); async function run(): Promise { try { if (utils.isGhes()) { - utils.logWarning("Cache action is not supported on GHES"); + utils.logWarning( + "Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details" + ); return; } From 10906ba9cd642bcc07f0f38a95a57e5c1361d156 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 20 Jul 2021 10:13:00 -0400 Subject: [PATCH 7/9] Bump ws from 5.2.2 to 5.2.3 (#610) Bumps [ws](https://github.com/websockets/ws) from 5.2.2 to 5.2.3. - [Release notes](https://github.com/websockets/ws/releases) - [Commits](https://github.com/websockets/ws/compare/5.2.2...5.2.3) --- updated-dependencies: - dependency-name: ws dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1c8a1cc..8086560 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6473,9 +6473,9 @@ } }, "ws": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.2.tgz", - "integrity": "sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==", + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.3.tgz", + "integrity": "sha512-jZArVERrMsKUatIdnLzqvcfydI85dvd/Fp1u/VOpfdDWQ4c9qWXe+VIeAbQ5FrDwciAkr+lzofXLz3Kuf26AOA==", "dev": true, "requires": { "async-limiter": "~1.0.0" From c9db520cf31dc27e42864cc3687b0d70284cc5fc Mon Sep 17 00:00:00 2001 From: Brian Cristante <33549821+brcrista@users.noreply.github.com> Date: Thu, 5 Aug 2021 14:39:40 -0400 Subject: [PATCH 8/9] Create check-dist.yml (#604) * Add check-dist.yml * Fix triggers in licensed.yml * fix workflow for this repo --- .github/workflows/check-dist.yml | 50 ++++++++++++++++++++++++++++++++ .github/workflows/licensed.yml | 10 +++++-- 2 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/check-dist.yml diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml new file mode 100644 index 0000000..a19cd7a --- /dev/null +++ b/.github/workflows/check-dist.yml @@ -0,0 +1,50 @@ +# `dist/index.js` is a special file in Actions. +# When you reference an action with `uses:` in a workflow, +# `index.js` is the code that will run. +# For our project, we generate this file through a build process +# from other source files. +# We need to make sure the checked-in `index.js` actually matches what we expect it to be. +name: Check dist/ + +on: + push: + branches: + - main + paths-ignore: + - '**.md' + pull_request: + paths-ignore: + - '**.md' + workflow_dispatch: + +jobs: + check-dist: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set Node.js 12.x + uses: actions/setup-node@v1 + with: + node-version: 12.x + + - name: Install dependencies + run: npm ci + + - name: Move the committed index.js file + run: mv dist/ /tmp/ + + - name: Rebuild the index.js file + run: npm run build + + - name: Compare the expected and actual index.js files + run: git diff --ignore-all-space dist/ /tmp/dist + id: diff + + # If index.js was different than expected, upload the expected version as an artifact + - uses: actions/upload-artifact@v2 + if: ${{ failure() && steps.diff.conclusion == 'failure' }} + with: + name: dist + path: dist/ diff --git a/.github/workflows/licensed.yml b/.github/workflows/licensed.yml index ae62613..4c1dfe5 100644 --- a/.github/workflows/licensed.yml +++ b/.github/workflows/licensed.yml @@ -1,8 +1,12 @@ name: Licensed on: - push: {branches: main} - pull_request: {branches: main} + push: + branches: + - main + pull_request: + branches: + - main jobs: test: @@ -17,4 +21,4 @@ jobs: curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/2.12.2/licensed-2.12.2-linux-x64.tar.gz sudo tar -xzf licensed.tar.gz sudo mv licensed /usr/local/bin/licensed - - run: licensed status \ No newline at end of file + - run: licensed status From 6bbe742add91b3db4abf110e742a967ec789958f Mon Sep 17 00:00:00 2001 From: Brian Cristante <33549821+brcrista@users.noreply.github.com> Date: Mon, 9 Aug 2021 09:10:47 -0400 Subject: [PATCH 9/9] Use existing check-dist implementation (#618) --- .github/workflows/check-dist.yml | 14 ++++++++------ .github/workflows/workflow.yml | 11 ----------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml index a19cd7a..16c2117 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -32,14 +32,16 @@ jobs: - name: Install dependencies run: npm ci - - name: Move the committed index.js file - run: mv dist/ /tmp/ - - - name: Rebuild the index.js file + - name: Rebuild the dist/ directory run: npm run build - - name: Compare the expected and actual index.js files - run: git diff --ignore-all-space dist/ /tmp/dist + - name: Compare the expected and actual dist/ directories + run: | + if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then + echo "Detected uncommitted changes after build. See status below:" + git diff + exit 1 + fi id: diff # If index.js was different than expected, upload the expected version as an artifact diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 460d7dd..a5dd3b7 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -47,17 +47,6 @@ jobs: run: npm run lint - name: Build & Test run: npm run test - - name: Ensure dist/ folder is up-to-date - if: ${{ runner.os == 'Linux' }} - shell: bash - run: | - npm run build - if [ "$(git diff --ignore-space-at-eol | wc -l)" -gt "0" ]; then - echo "Detected uncommitted changes after build. See status below:" - git diff - exit 1 - fi - # End to end save and restore test-save: