From 3f0646840edee93389c02eae5d2e4b78a01fef82 Mon Sep 17 00:00:00 2001 From: Enrico Minack Date: Mon, 4 Nov 2024 18:23:58 +0100 Subject: [PATCH 1/3] Add option to cache action to not save --- action.yml | 4 ++++ package-lock.json | 4 ++-- src/constants.ts | 3 ++- src/save.ts | 8 +++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 7af7458..86b6d2d 100644 --- a/action.yml +++ b/action.yml @@ -26,6 +26,10 @@ inputs: description: 'Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache' default: 'false' required: false + save: + description: 'Do not run the post step to save the cache if false' + default: 'true' + required: false save-always: description: 'Run the post step to save the cache even if another step before fails' default: 'false' diff --git a/package-lock.json b/package-lock.json index b3e6311..fddd60a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cache", - "version": "4.1.1", + "version": "4.1.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "cache", - "version": "4.1.1", + "version": "4.1.2", "license": "MIT", "dependencies": { "@actions/cache": "^3.2.3", diff --git a/src/constants.ts b/src/constants.ts index 0158ae0..f7ce717 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -5,7 +5,8 @@ export enum Inputs { UploadChunkSize = "upload-chunk-size", // Input for cache, save action EnableCrossOsArchive = "enableCrossOsArchive", // Input for cache, restore, save action FailOnCacheMiss = "fail-on-cache-miss", // Input for cache, restore action - LookupOnly = "lookup-only" // Input for cache, restore action + LookupOnly = "lookup-only", // Input for cache, restore action + Save = "save" // Input for save action } export enum Outputs { diff --git a/src/save.ts b/src/save.ts index 34f7e69..2b95fd1 100644 --- a/src/save.ts +++ b/src/save.ts @@ -1,3 +1,9 @@ +import * as core from "@actions/core"; + +import { Inputs } from "./constants"; import { saveRun } from "./saveImpl"; -saveRun(true); +const doSave = core.getInput(Inputs.Save); +if (doSave) { + saveRun(true); +} From afe0db9f6447f344dd063b83ae84aa5e59db3cec Mon Sep 17 00:00:00 2001 From: Enrico Minack Date: Mon, 4 Nov 2024 18:35:25 +0100 Subject: [PATCH 2/3] Add end-to-end test --- .github/workflows/workflow.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 5fd1dab..9a51899 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -35,6 +35,29 @@ jobs: run: npm run test # End to end save and restore + test-dont-save: + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + fail-fast: false + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Generate files in working directory + shell: bash + run: __tests__/create-cache-files.sh ${{ runner.os }} test-cache + - name: Generate files outside working directory + shell: bash + run: __tests__/create-cache-files.sh ${{ runner.os }} ~/test-cache + - name: Save cache + uses: ./ + with: + key: test-${{ runner.os }}-${{ github.run_id }} + path: | + test-cache + ~/test-cache + save: ${{ matrix.os == 'ubuntu-latest' }} test-save: strategy: matrix: From f9a5292a1e4477be722e95ac50393402b783cbfe Mon Sep 17 00:00:00 2001 From: Enrico Minack Date: Mon, 4 Nov 2024 18:40:15 +0100 Subject: [PATCH 3/3] Build dist --- dist/restore-only/index.js | 3 +- dist/restore/index.js | 3 +- dist/save-only/index.js | 3 +- dist/save/index.js | 63 +++++++++++++++++++++++++++++--------- 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/dist/restore-only/index.js b/dist/restore-only/index.js index 828dbd1..f6f1ea4 100644 --- a/dist/restore-only/index.js +++ b/dist/restore-only/index.js @@ -59324,7 +59324,8 @@ var Inputs; Inputs["UploadChunkSize"] = "upload-chunk-size"; Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; Inputs["FailOnCacheMiss"] = "fail-on-cache-miss"; - Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action + Inputs["LookupOnly"] = "lookup-only"; + Inputs["Save"] = "save"; // Input for save action })(Inputs = exports.Inputs || (exports.Inputs = {})); var Outputs; (function (Outputs) { diff --git a/dist/restore/index.js b/dist/restore/index.js index dbf9432..8052285 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -59324,7 +59324,8 @@ var Inputs; Inputs["UploadChunkSize"] = "upload-chunk-size"; Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; Inputs["FailOnCacheMiss"] = "fail-on-cache-miss"; - Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action + Inputs["LookupOnly"] = "lookup-only"; + Inputs["Save"] = "save"; // Input for save action })(Inputs = exports.Inputs || (exports.Inputs = {})); var Outputs; (function (Outputs) { diff --git a/dist/save-only/index.js b/dist/save-only/index.js index 434fac7..4370dc4 100644 --- a/dist/save-only/index.js +++ b/dist/save-only/index.js @@ -59324,7 +59324,8 @@ var Inputs; Inputs["UploadChunkSize"] = "upload-chunk-size"; Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; Inputs["FailOnCacheMiss"] = "fail-on-cache-miss"; - Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action + Inputs["LookupOnly"] = "lookup-only"; + Inputs["Save"] = "save"; // Input for save action })(Inputs = exports.Inputs || (exports.Inputs = {})); var Outputs; (function (Outputs) { diff --git a/dist/save/index.js b/dist/save/index.js index b8828f3..4e094c8 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -59324,7 +59324,8 @@ var Inputs; Inputs["UploadChunkSize"] = "upload-chunk-size"; Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; Inputs["FailOnCacheMiss"] = "fail-on-cache-miss"; - Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action + Inputs["LookupOnly"] = "lookup-only"; + Inputs["Save"] = "save"; // Input for save action })(Inputs = exports.Inputs || (exports.Inputs = {})); var Outputs; (function (Outputs) { @@ -59346,6 +59347,46 @@ var Events; exports.RefKey = "GITHUB_REF"; +/***/ }), + +/***/ 5131: +/***/ (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; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (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.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +const core = __importStar(__nccwpck_require__(2186)); +const constants_1 = __nccwpck_require__(9042); +const saveImpl_1 = __nccwpck_require__(6589); +const doSave = core.getInput(constants_1.Inputs.Save); +if (doSave) { + (0, saveImpl_1.saveRun)(true); +} + + /***/ }), /***/ 6589: @@ -59876,18 +59917,12 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"] /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; /******/ /************************************************************************/ -var __webpack_exports__ = {}; -// This entry need to be wrapped in an IIFE because it need to be in strict mode. -(() => { -"use strict"; -var exports = __webpack_exports__; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -const saveImpl_1 = __nccwpck_require__(6589); -(0, saveImpl_1.saveRun)(true); - -})(); - -module.exports = __webpack_exports__; +/******/ +/******/ // startup +/******/ // Load entry module and return exports +/******/ // This entry module is referenced by other modules so it can't be inlined +/******/ var __webpack_exports__ = __nccwpck_require__(5131); +/******/ module.exports = __webpack_exports__; +/******/ /******/ })() ; \ No newline at end of file