From eda4a77b7cd298a53357f044f7962c369ccd0713 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 23 Dec 2022 14:24:29 +0100 Subject: [PATCH 01/14] Add new actions/cache version (with dryRun support) --- dist/restore-only/index.js | 11 ++++++++++- dist/restore/index.js | 11 ++++++++++- dist/save-only/index.js | 11 ++++++++++- dist/save/index.js | 11 ++++++++++- package-lock.json | 12 ++++++------ package.json | 2 +- 6 files changed, 47 insertions(+), 11 deletions(-) diff --git a/dist/restore-only/index.js b/dist/restore-only/index.js index f676abbf1..9c5d59fad 100644 --- a/dist/restore-only/index.js +++ b/dist/restore-only/index.js @@ -41808,7 +41808,8 @@ function getDownloadOptions(copy) { useAzureSdk: true, downloadConcurrency: 8, timeoutInMs: 30000, - segmentTimeoutInMs: 3600000 + segmentTimeoutInMs: 3600000, + dryRun: false }; if (copy) { if (typeof copy.useAzureSdk === 'boolean') { @@ -41823,6 +41824,9 @@ function getDownloadOptions(copy) { if (typeof copy.segmentTimeoutInMs === 'number') { result.segmentTimeoutInMs = copy.segmentTimeoutInMs; } + if (typeof copy.dryRun === 'boolean') { + result.dryRun = copy.dryRun; + } } const segmentDownloadTimeoutMins = process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']; if (segmentDownloadTimeoutMins && @@ -41835,6 +41839,7 @@ function getDownloadOptions(copy) { core.debug(`Request timeout (ms): ${result.timeoutInMs}`); core.debug(`Cache segment download timeout mins env var: ${process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']}`); core.debug(`Segment download timeout (ms): ${result.segmentTimeoutInMs}`); + core.debug(`Dry run: ${result.dryRun}`); return result; } exports.getDownloadOptions = getDownloadOptions; @@ -47283,6 +47288,10 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch // Cache not found return undefined; } + if (options === null || options === void 0 ? void 0 : options.dryRun) { + core.info('Dry run - skipping download'); + return cacheEntry.cacheKey; + } archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod)); core.debug(`Archive Path: ${archivePath}`); // Download the cache from the cache entry diff --git a/dist/restore/index.js b/dist/restore/index.js index 641547898..942a1136f 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -41779,7 +41779,8 @@ function getDownloadOptions(copy) { useAzureSdk: true, downloadConcurrency: 8, timeoutInMs: 30000, - segmentTimeoutInMs: 3600000 + segmentTimeoutInMs: 3600000, + dryRun: false }; if (copy) { if (typeof copy.useAzureSdk === 'boolean') { @@ -41794,6 +41795,9 @@ function getDownloadOptions(copy) { if (typeof copy.segmentTimeoutInMs === 'number') { result.segmentTimeoutInMs = copy.segmentTimeoutInMs; } + if (typeof copy.dryRun === 'boolean') { + result.dryRun = copy.dryRun; + } } const segmentDownloadTimeoutMins = process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']; if (segmentDownloadTimeoutMins && @@ -41806,6 +41810,7 @@ function getDownloadOptions(copy) { core.debug(`Request timeout (ms): ${result.timeoutInMs}`); core.debug(`Cache segment download timeout mins env var: ${process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']}`); core.debug(`Segment download timeout (ms): ${result.segmentTimeoutInMs}`); + core.debug(`Dry run: ${result.dryRun}`); return result; } exports.getDownloadOptions = getDownloadOptions; @@ -47254,6 +47259,10 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch // Cache not found return undefined; } + if (options === null || options === void 0 ? void 0 : options.dryRun) { + core.info('Dry run - skipping download'); + return cacheEntry.cacheKey; + } archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod)); core.debug(`Archive Path: ${archivePath}`); // Download the cache from the cache entry diff --git a/dist/save-only/index.js b/dist/save-only/index.js index 0d3295cdd..17d2b2eff 100644 --- a/dist/save-only/index.js +++ b/dist/save-only/index.js @@ -41920,7 +41920,8 @@ function getDownloadOptions(copy) { useAzureSdk: true, downloadConcurrency: 8, timeoutInMs: 30000, - segmentTimeoutInMs: 3600000 + segmentTimeoutInMs: 3600000, + dryRun: false }; if (copy) { if (typeof copy.useAzureSdk === 'boolean') { @@ -41935,6 +41936,9 @@ function getDownloadOptions(copy) { if (typeof copy.segmentTimeoutInMs === 'number') { result.segmentTimeoutInMs = copy.segmentTimeoutInMs; } + if (typeof copy.dryRun === 'boolean') { + result.dryRun = copy.dryRun; + } } const segmentDownloadTimeoutMins = process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']; if (segmentDownloadTimeoutMins && @@ -41947,6 +41951,7 @@ function getDownloadOptions(copy) { core.debug(`Request timeout (ms): ${result.timeoutInMs}`); core.debug(`Cache segment download timeout mins env var: ${process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']}`); core.debug(`Segment download timeout (ms): ${result.segmentTimeoutInMs}`); + core.debug(`Dry run: ${result.dryRun}`); return result; } exports.getDownloadOptions = getDownloadOptions; @@ -47395,6 +47400,10 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch // Cache not found return undefined; } + if (options === null || options === void 0 ? void 0 : options.dryRun) { + core.info('Dry run - skipping download'); + return cacheEntry.cacheKey; + } archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod)); core.debug(`Archive Path: ${archivePath}`); // Download the cache from the cache entry diff --git a/dist/save/index.js b/dist/save/index.js index 1b0a7334c..a420c5e24 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -41864,7 +41864,8 @@ function getDownloadOptions(copy) { useAzureSdk: true, downloadConcurrency: 8, timeoutInMs: 30000, - segmentTimeoutInMs: 3600000 + segmentTimeoutInMs: 3600000, + dryRun: false }; if (copy) { if (typeof copy.useAzureSdk === 'boolean') { @@ -41879,6 +41880,9 @@ function getDownloadOptions(copy) { if (typeof copy.segmentTimeoutInMs === 'number') { result.segmentTimeoutInMs = copy.segmentTimeoutInMs; } + if (typeof copy.dryRun === 'boolean') { + result.dryRun = copy.dryRun; + } } const segmentDownloadTimeoutMins = process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']; if (segmentDownloadTimeoutMins && @@ -41891,6 +41895,7 @@ function getDownloadOptions(copy) { core.debug(`Request timeout (ms): ${result.timeoutInMs}`); core.debug(`Cache segment download timeout mins env var: ${process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']}`); core.debug(`Segment download timeout (ms): ${result.segmentTimeoutInMs}`); + core.debug(`Dry run: ${result.dryRun}`); return result; } exports.getDownloadOptions = getDownloadOptions; @@ -47368,6 +47373,10 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch // Cache not found return undefined; } + if (options === null || options === void 0 ? void 0 : options.dryRun) { + core.info('Dry run - skipping download'); + return cacheEntry.cacheKey; + } archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod)); core.debug(`Archive Path: ${archivePath}`); // Download the cache from the cache entry diff --git a/package-lock.json b/package-lock.json index eb8e5f927..7e29cb467 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.2.2", "license": "MIT", "dependencies": { - "@actions/cache": "^3.1.2", + "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.2.tgz", "@actions/core": "^1.10.0", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.2" @@ -37,8 +37,9 @@ }, "node_modules/@actions/cache": { "version": "3.1.2", - "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-3.1.2.tgz", - "integrity": "sha512-3XeKcXIonfIbqvW7gPm/VLOhv1RHQ1dtTgSBCH6OUhCgSTii9bEVgu0PIms7UbLnXeMCKFzECfpbud8fJEvBbQ==", + "resolved": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.2.tgz", + "integrity": "sha512-1vcZXG2jWtEnDWq34byiQmS8tgOKAzFEIiMFPtxigm3vHOW+9FGdA2S+eWsK3NBLIbWd5erCkWgo4M0g6gw1yw==", + "license": "MIT", "dependencies": { "@actions/core": "^1.10.0", "@actions/exec": "^1.0.1", @@ -9722,9 +9723,8 @@ }, "dependencies": { "@actions/cache": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-3.1.2.tgz", - "integrity": "sha512-3XeKcXIonfIbqvW7gPm/VLOhv1RHQ1dtTgSBCH6OUhCgSTii9bEVgu0PIms7UbLnXeMCKFzECfpbud8fJEvBbQ==", + "version": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.2.tgz", + "integrity": "sha512-1vcZXG2jWtEnDWq34byiQmS8tgOKAzFEIiMFPtxigm3vHOW+9FGdA2S+eWsK3NBLIbWd5erCkWgo4M0g6gw1yw==", "requires": { "@actions/core": "^1.10.0", "@actions/exec": "^1.0.1", diff --git a/package.json b/package.json index 7046c205a..6926cac8d 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "author": "GitHub", "license": "MIT", "dependencies": { - "@actions/cache": "^3.1.2", + "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.2.tgz", "@actions/core": "^1.10.0", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.2" From 1bb6d2503c37dc49ae8811b2e76bf1a7126082a7 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 23 Dec 2022 14:26:44 +0100 Subject: [PATCH 02/14] Add dry-run option --- __tests__/restore.test.ts | 71 +++++++++++++++++++++++++++++++++-- __tests__/restoreImpl.test.ts | 62 ++++++++++++++++++++++++++---- __tests__/restoreOnly.test.ts | 28 ++++++++++++-- action.yml | 4 ++ dist/restore-only/index.js | 5 ++- dist/restore/index.js | 5 ++- dist/save-only/index.js | 3 +- dist/save/index.js | 3 +- restore/README.md | 1 + restore/action.yml | 6 ++- src/constants.ts | 3 +- src/restoreImpl.ts | 2 +- src/utils/testUtils.ts | 4 ++ 13 files changed, 172 insertions(+), 25 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index ab768ba0e..23af60244 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -74,7 +74,15 @@ test("restore with no cache found", async () => { await run(); expect(restoreCacheMock).toHaveBeenCalledTimes(1); - expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); + expect(restoreCacheMock).toHaveBeenCalledWith( + [path], + key, + [], + { + dryRun: false + }, + false + ); expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); expect(stateMock).toHaveBeenCalledTimes(1); @@ -113,7 +121,9 @@ test("restore with restore keys and no cache found", async () => { [path], key, [restoreKey], - {}, + { + dryRun: false + }, false ); @@ -149,7 +159,15 @@ test("restore with cache found for key", async () => { await run(); expect(restoreCacheMock).toHaveBeenCalledTimes(1); - expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); + expect(restoreCacheMock).toHaveBeenCalledWith( + [path], + key, + [], + { + dryRun: false + }, + false + ); expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key); @@ -190,7 +208,9 @@ test("restore with cache found for restore key", async () => { [path], key, [restoreKey], - {}, + { + dryRun: false + }, false ); @@ -205,3 +225,46 @@ test("restore with cache found for restore key", async () => { ); expect(failedMock).toHaveBeenCalledTimes(0); }); + +test("restore with dry-run set", async () => { + const path = "node_modules"; + const key = "node-test"; + testUtils.setInputs({ + path: path, + key, + dryRun: "true" + }); + + const infoMock = jest.spyOn(core, "info"); + const failedMock = jest.spyOn(core, "setFailed"); + const stateMock = jest.spyOn(core, "saveState"); + const setCacheHitOutputMock = jest.spyOn(core, "setOutput"); + const restoreCacheMock = jest + .spyOn(cache, "restoreCache") + .mockImplementationOnce(() => { + return Promise.resolve(key); + }); + + await run(); + + expect(restoreCacheMock).toHaveBeenCalledTimes(1); + expect(restoreCacheMock).toHaveBeenCalledWith( + [path], + key, + [], + { + dryRun: true + }, + false + ); + + expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); + expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key); + expect(stateMock).toHaveBeenCalledTimes(2); + + expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); + expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true"); + + expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`); + expect(failedMock).toHaveBeenCalledTimes(0); +}); diff --git a/__tests__/restoreImpl.test.ts b/__tests__/restoreImpl.test.ts index 9bc4fc33e..54c78f876 100644 --- a/__tests__/restoreImpl.test.ts +++ b/__tests__/restoreImpl.test.ts @@ -122,7 +122,15 @@ test("restore on GHES with AC available ", async () => { await run(new StateProvider()); expect(restoreCacheMock).toHaveBeenCalledTimes(1); - expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); + expect(restoreCacheMock).toHaveBeenCalledWith( + [path], + key, + [], + { + dryRun: false + }, + false + ); expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); @@ -172,7 +180,9 @@ test("restore with too many keys should fail", async () => { [path], key, restoreKeys, - {}, + { + dryRun: false + }, false ); expect(failedMock).toHaveBeenCalledWith( @@ -192,7 +202,15 @@ test("restore with large key should fail", async () => { const restoreCacheMock = jest.spyOn(cache, "restoreCache"); await run(new StateProvider()); expect(restoreCacheMock).toHaveBeenCalledTimes(1); - expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); + expect(restoreCacheMock).toHaveBeenCalledWith( + [path], + key, + [], + { + dryRun: false + }, + false + ); expect(failedMock).toHaveBeenCalledWith( `Key Validation Error: ${key} cannot be larger than 512 characters.` ); @@ -210,7 +228,15 @@ test("restore with invalid key should fail", async () => { const restoreCacheMock = jest.spyOn(cache, "restoreCache"); await run(new StateProvider()); expect(restoreCacheMock).toHaveBeenCalledTimes(1); - expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); + expect(restoreCacheMock).toHaveBeenCalledWith( + [path], + key, + [], + { + dryRun: false + }, + false + ); expect(failedMock).toHaveBeenCalledWith( `Key Validation Error: ${key} cannot contain commas.` ); @@ -237,7 +263,15 @@ test("restore with no cache found", async () => { await run(new StateProvider()); expect(restoreCacheMock).toHaveBeenCalledTimes(1); - expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); + expect(restoreCacheMock).toHaveBeenCalledWith( + [path], + key, + [], + { + dryRun: false + }, + false + ); expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); expect(failedMock).toHaveBeenCalledTimes(0); @@ -274,7 +308,9 @@ test("restore with restore keys and no cache found", async () => { [path], key, [restoreKey], - {}, + { + dryRun: false + }, false ); @@ -308,7 +344,15 @@ test("restore with cache found for key", async () => { await run(new StateProvider()); expect(restoreCacheMock).toHaveBeenCalledTimes(1); - expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); + expect(restoreCacheMock).toHaveBeenCalledWith( + [path], + key, + [], + { + dryRun: false + }, + false + ); expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); @@ -346,7 +390,9 @@ test("restore with cache found for restore key", async () => { [path], key, [restoreKey], - {}, + { + dryRun: false + }, false ); diff --git a/__tests__/restoreOnly.test.ts b/__tests__/restoreOnly.test.ts index ab6991414..83ab6fa04 100644 --- a/__tests__/restoreOnly.test.ts +++ b/__tests__/restoreOnly.test.ts @@ -75,7 +75,15 @@ test("restore with no cache found", async () => { await run(); expect(restoreCacheMock).toHaveBeenCalledTimes(1); - expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); + expect(restoreCacheMock).toHaveBeenCalledWith( + [path], + key, + [], + { + dryRun: false + }, + false + ); expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key); expect(outputMock).toHaveBeenCalledTimes(1); @@ -113,7 +121,9 @@ test("restore with restore keys and no cache found", async () => { [path], key, [restoreKey], - {}, + { + dryRun: false + }, false ); @@ -146,7 +156,15 @@ test("restore with cache found for key", async () => { await run(); expect(restoreCacheMock).toHaveBeenCalledTimes(1); - expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); + expect(restoreCacheMock).toHaveBeenCalledWith( + [path], + key, + [], + { + dryRun: false + }, + false + ); expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key); expect(outputMock).toHaveBeenCalledWith("cache-hit", "true"); @@ -185,7 +203,9 @@ test("restore with cache found for restore key", async () => { [path], key, [restoreKey], - {}, + { + dryRun: false + }, false ); diff --git a/action.yml b/action.yml index 424e191d3..695fe0115 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,10 @@ inputs: restore-keys: description: 'An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.' required: false + dry-run: + description: 'Skip downloading cache. Only check if cache entry exists' + required: false + default: "false" upload-chunk-size: description: 'The chunk size used to split up large files during upload, in bytes' required: false diff --git a/dist/restore-only/index.js b/dist/restore-only/index.js index 9c5d59fad..0608c3ee9 100644 --- a/dist/restore-only/index.js +++ b/dist/restore-only/index.js @@ -4978,7 +4978,8 @@ var Inputs; Inputs["Path"] = "path"; Inputs["RestoreKeys"] = "restore-keys"; Inputs["UploadChunkSize"] = "upload-chunk-size"; - Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; // Input for cache, restore, save action + Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; + Inputs["DryRun"] = "dry-run"; // Input for cache, restore action })(Inputs = exports.Inputs || (exports.Inputs = {})); var Outputs; (function (Outputs) { @@ -50504,7 +50505,7 @@ function restoreImpl(stateProvider) { required: true }); const enableCrossOsArchive = utils.getInputAsBool(constants_1.Inputs.EnableCrossOsArchive); - const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, {}, enableCrossOsArchive); + const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, { dryRun: core.getBooleanInput(constants_1.Inputs.DryRun) }, enableCrossOsArchive); if (!cacheKey) { core.info(`Cache not found for input keys: ${[ primaryKey, diff --git a/dist/restore/index.js b/dist/restore/index.js index 942a1136f..0d32c3dfb 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -4978,7 +4978,8 @@ var Inputs; Inputs["Path"] = "path"; Inputs["RestoreKeys"] = "restore-keys"; Inputs["UploadChunkSize"] = "upload-chunk-size"; - Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; // Input for cache, restore, save action + Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; + Inputs["DryRun"] = "dry-run"; // Input for cache, restore action })(Inputs = exports.Inputs || (exports.Inputs = {})); var Outputs; (function (Outputs) { @@ -50504,7 +50505,7 @@ function restoreImpl(stateProvider) { required: true }); const enableCrossOsArchive = utils.getInputAsBool(constants_1.Inputs.EnableCrossOsArchive); - const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, {}, enableCrossOsArchive); + const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, { dryRun: core.getBooleanInput(constants_1.Inputs.DryRun) }, enableCrossOsArchive); if (!cacheKey) { core.info(`Cache not found for input keys: ${[ primaryKey, diff --git a/dist/save-only/index.js b/dist/save-only/index.js index 17d2b2eff..23a38afee 100644 --- a/dist/save-only/index.js +++ b/dist/save-only/index.js @@ -5034,7 +5034,8 @@ var Inputs; Inputs["Path"] = "path"; Inputs["RestoreKeys"] = "restore-keys"; Inputs["UploadChunkSize"] = "upload-chunk-size"; - Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; // Input for cache, restore, save action + Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; + Inputs["DryRun"] = "dry-run"; // Input for cache, restore action })(Inputs = exports.Inputs || (exports.Inputs = {})); var Outputs; (function (Outputs) { diff --git a/dist/save/index.js b/dist/save/index.js index a420c5e24..ddc4e9b25 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -4978,7 +4978,8 @@ var Inputs; Inputs["Path"] = "path"; Inputs["RestoreKeys"] = "restore-keys"; Inputs["UploadChunkSize"] = "upload-chunk-size"; - Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; // Input for cache, restore, save action + Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; + Inputs["DryRun"] = "dry-run"; // Input for cache, restore action })(Inputs = exports.Inputs || (exports.Inputs = {})); var Outputs; (function (Outputs) { diff --git a/restore/README.md b/restore/README.md index e6592d632..261f8319d 100644 --- a/restore/README.md +++ b/restore/README.md @@ -7,6 +7,7 @@ The restore action, as the name suggest, restores a cache. It acts similar to th * `path` - A list of files, directories, and wildcard patterns to cache and restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob) for supported patterns. * `key` - String used while saving cache for restoring the cache * `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key. +* `dry-run` - Skip downloading cache. Only check if cache entry exists ## Outputs diff --git a/restore/action.yml b/restore/action.yml index 8989197a1..b0c7660b0 100644 --- a/restore/action.yml +++ b/restore/action.yml @@ -15,6 +15,10 @@ inputs: description: 'An optional boolean when enabled, allows windows runners to restore caches that were saved on other platforms' default: 'false' required: false + dry-run: + description: 'Skip downloading cache. Only check if cache entry exists' + required: false + default: "false" outputs: cache-hit: description: 'A boolean value to indicate an exact match was found for the primary key' @@ -27,4 +31,4 @@ runs: main: '../dist/restore-only/index.js' branding: icon: 'archive' - color: 'gray-dark' \ No newline at end of file + color: 'gray-dark' diff --git a/src/constants.ts b/src/constants.ts index 97fa2a0b7..2753adaef 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -3,7 +3,8 @@ export enum Inputs { Path = "path", // Input for cache, restore, save action RestoreKeys = "restore-keys", // Input for cache, restore action UploadChunkSize = "upload-chunk-size", // Input for cache, save action - EnableCrossOsArchive = "enableCrossOsArchive" // Input for cache, restore, save action + EnableCrossOsArchive = "enableCrossOsArchive", // Input for cache, restore, save action + DryRun = "dry-run" // Input for cache, restore action } export enum Outputs { diff --git a/src/restoreImpl.ts b/src/restoreImpl.ts index 6214cfd74..207db4294 100644 --- a/src/restoreImpl.ts +++ b/src/restoreImpl.ts @@ -39,7 +39,7 @@ async function restoreImpl( cachePaths, primaryKey, restoreKeys, - {}, + { dryRun: core.getBooleanInput(Inputs.DryRun) }, enableCrossOsArchive ); diff --git a/src/utils/testUtils.ts b/src/utils/testUtils.ts index c0a3f43c2..2e5491184 100644 --- a/src/utils/testUtils.ts +++ b/src/utils/testUtils.ts @@ -14,11 +14,13 @@ interface CacheInput { key: string; restoreKeys?: string[]; enableCrossOsArchive?: boolean; + dryRun?: string; } export function setInputs(input: CacheInput): void { setInput(Inputs.Path, input.path); setInput(Inputs.Key, input.key); + setInput(Inputs.DryRun, "false"); input.restoreKeys && setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n")); input.enableCrossOsArchive !== undefined && @@ -26,12 +28,14 @@ export function setInputs(input: CacheInput): void { Inputs.EnableCrossOsArchive, input.enableCrossOsArchive.toString() ); + input.dryRun && setInput(Inputs.DryRun, input.dryRun); } export function clearInputs(): void { delete process.env[getInputName(Inputs.Path)]; delete process.env[getInputName(Inputs.Key)]; delete process.env[getInputName(Inputs.RestoreKeys)]; + delete process.env[getInputName(Inputs.DryRun)]; delete process.env[getInputName(Inputs.UploadChunkSize)]; delete process.env[getInputName(Inputs.EnableCrossOsArchive)]; } From e614c5820dc749474c9ec51c051e188d434f0007 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 8 Jan 2023 12:10:17 +0100 Subject: [PATCH 03/14] Changes after rebase --- __tests__/restore.test.ts | 2 +- action.yml | 8 ++++---- dist/restore-only/index.js | 3 ++- dist/restore/index.js | 3 ++- restore/action.yml | 2 +- src/restoreImpl.ts | 3 ++- src/utils/testUtils.ts | 8 ++++---- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index 23af60244..e267b62af 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -232,7 +232,7 @@ test("restore with dry-run set", async () => { testUtils.setInputs({ path: path, key, - dryRun: "true" + dryRun: true }); const infoMock = jest.spyOn(core, "info"); diff --git a/action.yml b/action.yml index 695fe0115..c34633362 100644 --- a/action.yml +++ b/action.yml @@ -11,10 +11,6 @@ inputs: restore-keys: description: 'An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.' required: false - dry-run: - description: 'Skip downloading cache. Only check if cache entry exists' - required: false - default: "false" upload-chunk-size: description: 'The chunk size used to split up large files during upload, in bytes' required: false @@ -22,6 +18,10 @@ inputs: description: 'An optional boolean when enabled, allows windows runners to save or restore caches that can be restored or saved respectively on other platforms' default: 'false' required: false + dry-run: + description: 'Skip downloading cache. Only check if cache entry exists' + default: 'false' + required: false outputs: cache-hit: description: 'A boolean value to indicate an exact match was found for the primary key' diff --git a/dist/restore-only/index.js b/dist/restore-only/index.js index 0608c3ee9..23971c479 100644 --- a/dist/restore-only/index.js +++ b/dist/restore-only/index.js @@ -50505,7 +50505,8 @@ function restoreImpl(stateProvider) { required: true }); const enableCrossOsArchive = utils.getInputAsBool(constants_1.Inputs.EnableCrossOsArchive); - const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, { dryRun: core.getBooleanInput(constants_1.Inputs.DryRun) }, enableCrossOsArchive); + const dryRun = utils.getInputAsBool(constants_1.Inputs.DryRun); + const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, { dryRun: dryRun }, enableCrossOsArchive); if (!cacheKey) { core.info(`Cache not found for input keys: ${[ primaryKey, diff --git a/dist/restore/index.js b/dist/restore/index.js index 0d32c3dfb..c85a85177 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -50505,7 +50505,8 @@ function restoreImpl(stateProvider) { required: true }); const enableCrossOsArchive = utils.getInputAsBool(constants_1.Inputs.EnableCrossOsArchive); - const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, { dryRun: core.getBooleanInput(constants_1.Inputs.DryRun) }, enableCrossOsArchive); + const dryRun = utils.getInputAsBool(constants_1.Inputs.DryRun); + const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, { dryRun: dryRun }, enableCrossOsArchive); if (!cacheKey) { core.info(`Cache not found for input keys: ${[ primaryKey, diff --git a/restore/action.yml b/restore/action.yml index b0c7660b0..67e4c7378 100644 --- a/restore/action.yml +++ b/restore/action.yml @@ -17,8 +17,8 @@ inputs: required: false dry-run: description: 'Skip downloading cache. Only check if cache entry exists' + default: 'false' required: false - default: "false" outputs: cache-hit: description: 'A boolean value to indicate an exact match was found for the primary key' diff --git a/src/restoreImpl.ts b/src/restoreImpl.ts index 207db4294..f9aa3134f 100644 --- a/src/restoreImpl.ts +++ b/src/restoreImpl.ts @@ -34,12 +34,13 @@ async function restoreImpl( const enableCrossOsArchive = utils.getInputAsBool( Inputs.EnableCrossOsArchive ); + const dryRun = utils.getInputAsBool(Inputs.DryRun); const cacheKey = await cache.restoreCache( cachePaths, primaryKey, restoreKeys, - { dryRun: core.getBooleanInput(Inputs.DryRun) }, + { dryRun: dryRun }, enableCrossOsArchive ); diff --git a/src/utils/testUtils.ts b/src/utils/testUtils.ts index 2e5491184..ee5ea83aa 100644 --- a/src/utils/testUtils.ts +++ b/src/utils/testUtils.ts @@ -14,13 +14,12 @@ interface CacheInput { key: string; restoreKeys?: string[]; enableCrossOsArchive?: boolean; - dryRun?: string; + dryRun?: boolean; } export function setInputs(input: CacheInput): void { setInput(Inputs.Path, input.path); setInput(Inputs.Key, input.key); - setInput(Inputs.DryRun, "false"); input.restoreKeys && setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n")); input.enableCrossOsArchive !== undefined && @@ -28,14 +27,15 @@ export function setInputs(input: CacheInput): void { Inputs.EnableCrossOsArchive, input.enableCrossOsArchive.toString() ); - input.dryRun && setInput(Inputs.DryRun, input.dryRun); + input.dryRun !== undefined && + setInput(Inputs.DryRun, input.dryRun.toString()); } export function clearInputs(): void { delete process.env[getInputName(Inputs.Path)]; delete process.env[getInputName(Inputs.Key)]; delete process.env[getInputName(Inputs.RestoreKeys)]; - delete process.env[getInputName(Inputs.DryRun)]; delete process.env[getInputName(Inputs.UploadChunkSize)]; delete process.env[getInputName(Inputs.EnableCrossOsArchive)]; + delete process.env[getInputName(Inputs.DryRun)]; } From d1960e64f9751be69d0675ea0cf11b058f7ea878 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 16 Jan 2023 23:02:59 +0100 Subject: [PATCH 04/14] Update readme --- README.md | 1 + restore/README.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7ecac5c40..840231ca5 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are requir * `key` - An explicit key for restoring and saving the cache. Refer [creating a cache key](#creating-a-cache-key). * `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key. * `enableCrossOsArchive` - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: false +* `dry-run` - Skip downloading cache. Only check if cache entry exists. Default: false #### Environment Variables diff --git a/restore/README.md b/restore/README.md index 8de4c8bfb..b3f091957 100644 --- a/restore/README.md +++ b/restore/README.md @@ -7,7 +7,7 @@ The restore action, as the name suggest, restores a cache. It acts similar to th * `path` - A list of files, directories, and wildcard patterns to cache and restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob) for supported patterns. * `key` - String used while saving cache for restoring the cache * `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key. -* `dry-run` - Skip downloading cache. Only check if cache entry exists +* `dry-run` - Skip downloading cache. Only check if cache entry exists. Default: false ## Outputs From 2ef4e0621f2ee9db2045a813fb11017b03436b51 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Wed, 18 Jan 2023 12:21:26 +0100 Subject: [PATCH 05/14] Rename option to lookup-only --- README.md | 2 +- __tests__/restore.test.ts | 12 ++++++------ __tests__/restoreImpl.test.ts | 16 ++++++++-------- __tests__/restoreOnly.test.ts | 8 ++++---- action.yml | 2 +- dist/restore-only/index.js | 18 +++++++++--------- dist/restore/index.js | 18 +++++++++--------- dist/save-only/index.js | 14 +++++++------- dist/save/index.js | 14 +++++++------- package-lock.json | 12 ++++++------ package.json | 2 +- restore/README.md | 2 +- restore/action.yml | 2 +- src/constants.ts | 2 +- src/restoreImpl.ts | 4 ++-- src/utils/testUtils.ts | 8 ++++---- 16 files changed, 68 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 840231ca5..9dd6aec75 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are requir * `key` - An explicit key for restoring and saving the cache. Refer [creating a cache key](#creating-a-cache-key). * `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key. * `enableCrossOsArchive` - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: false -* `dry-run` - Skip downloading cache. Only check if cache entry exists. Default: false +* `lookup-only` - Skip downloading cache. Only check if cache entry exists. Default: false #### Environment Variables diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index e267b62af..20a4390b9 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -79,7 +79,7 @@ test("restore with no cache found", async () => { key, [], { - dryRun: false + lookupOnly: false }, false ); @@ -122,7 +122,7 @@ test("restore with restore keys and no cache found", async () => { key, [restoreKey], { - dryRun: false + lookupOnly: false }, false ); @@ -164,7 +164,7 @@ test("restore with cache found for key", async () => { key, [], { - dryRun: false + lookupOnly: false }, false ); @@ -209,7 +209,7 @@ test("restore with cache found for restore key", async () => { key, [restoreKey], { - dryRun: false + lookupOnly: false }, false ); @@ -232,7 +232,7 @@ test("restore with dry-run set", async () => { testUtils.setInputs({ path: path, key, - dryRun: true + lookupOnly: true }); const infoMock = jest.spyOn(core, "info"); @@ -253,7 +253,7 @@ test("restore with dry-run set", async () => { key, [], { - dryRun: true + lookupOnly: true }, false ); diff --git a/__tests__/restoreImpl.test.ts b/__tests__/restoreImpl.test.ts index 54c78f876..315fc7a99 100644 --- a/__tests__/restoreImpl.test.ts +++ b/__tests__/restoreImpl.test.ts @@ -127,7 +127,7 @@ test("restore on GHES with AC available ", async () => { key, [], { - dryRun: false + lookupOnly: false }, false ); @@ -181,7 +181,7 @@ test("restore with too many keys should fail", async () => { key, restoreKeys, { - dryRun: false + lookupOnly: false }, false ); @@ -207,7 +207,7 @@ test("restore with large key should fail", async () => { key, [], { - dryRun: false + lookupOnly: false }, false ); @@ -233,7 +233,7 @@ test("restore with invalid key should fail", async () => { key, [], { - dryRun: false + lookupOnly: false }, false ); @@ -268,7 +268,7 @@ test("restore with no cache found", async () => { key, [], { - dryRun: false + lookupOnly: false }, false ); @@ -309,7 +309,7 @@ test("restore with restore keys and no cache found", async () => { key, [restoreKey], { - dryRun: false + lookupOnly: false }, false ); @@ -349,7 +349,7 @@ test("restore with cache found for key", async () => { key, [], { - dryRun: false + lookupOnly: false }, false ); @@ -391,7 +391,7 @@ test("restore with cache found for restore key", async () => { key, [restoreKey], { - dryRun: false + lookupOnly: false }, false ); diff --git a/__tests__/restoreOnly.test.ts b/__tests__/restoreOnly.test.ts index 83ab6fa04..800c2e1c7 100644 --- a/__tests__/restoreOnly.test.ts +++ b/__tests__/restoreOnly.test.ts @@ -80,7 +80,7 @@ test("restore with no cache found", async () => { key, [], { - dryRun: false + lookupOnly: false }, false ); @@ -122,7 +122,7 @@ test("restore with restore keys and no cache found", async () => { key, [restoreKey], { - dryRun: false + lookupOnly: false }, false ); @@ -161,7 +161,7 @@ test("restore with cache found for key", async () => { key, [], { - dryRun: false + lookupOnly: false }, false ); @@ -204,7 +204,7 @@ test("restore with cache found for restore key", async () => { key, [restoreKey], { - dryRun: false + lookupOnly: false }, false ); diff --git a/action.yml b/action.yml index c34633362..8ce0593b7 100644 --- a/action.yml +++ b/action.yml @@ -18,7 +18,7 @@ inputs: description: 'An optional boolean when enabled, allows windows runners to save or restore caches that can be restored or saved respectively on other platforms' default: 'false' required: false - dry-run: + lookup-only: description: 'Skip downloading cache. Only check if cache entry exists' default: 'false' required: false diff --git a/dist/restore-only/index.js b/dist/restore-only/index.js index 23971c479..563a51900 100644 --- a/dist/restore-only/index.js +++ b/dist/restore-only/index.js @@ -4979,7 +4979,7 @@ var Inputs; Inputs["RestoreKeys"] = "restore-keys"; Inputs["UploadChunkSize"] = "upload-chunk-size"; Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; - Inputs["DryRun"] = "dry-run"; // Input for cache, restore action + Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action })(Inputs = exports.Inputs || (exports.Inputs = {})); var Outputs; (function (Outputs) { @@ -41810,7 +41810,7 @@ function getDownloadOptions(copy) { downloadConcurrency: 8, timeoutInMs: 30000, segmentTimeoutInMs: 3600000, - dryRun: false + lookupOnly: false }; if (copy) { if (typeof copy.useAzureSdk === 'boolean') { @@ -41825,8 +41825,8 @@ function getDownloadOptions(copy) { if (typeof copy.segmentTimeoutInMs === 'number') { result.segmentTimeoutInMs = copy.segmentTimeoutInMs; } - if (typeof copy.dryRun === 'boolean') { - result.dryRun = copy.dryRun; + if (typeof copy.lookupOnly === 'boolean') { + result.lookupOnly = copy.lookupOnly; } } const segmentDownloadTimeoutMins = process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']; @@ -41840,7 +41840,7 @@ function getDownloadOptions(copy) { core.debug(`Request timeout (ms): ${result.timeoutInMs}`); core.debug(`Cache segment download timeout mins env var: ${process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']}`); core.debug(`Segment download timeout (ms): ${result.segmentTimeoutInMs}`); - core.debug(`Dry run: ${result.dryRun}`); + core.debug(`Lookup only: ${result.lookupOnly}`); return result; } exports.getDownloadOptions = getDownloadOptions; @@ -47289,8 +47289,8 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch // Cache not found return undefined; } - if (options === null || options === void 0 ? void 0 : options.dryRun) { - core.info('Dry run - skipping download'); + if (options === null || options === void 0 ? void 0 : options.lookupOnly) { + core.info('Lookup only - skipping download'); return cacheEntry.cacheKey; } archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod)); @@ -50505,8 +50505,8 @@ function restoreImpl(stateProvider) { required: true }); const enableCrossOsArchive = utils.getInputAsBool(constants_1.Inputs.EnableCrossOsArchive); - const dryRun = utils.getInputAsBool(constants_1.Inputs.DryRun); - const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, { dryRun: dryRun }, enableCrossOsArchive); + const lookupOnly = utils.getInputAsBool(constants_1.Inputs.LookupOnly); + const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, { lookupOnly: lookupOnly }, enableCrossOsArchive); if (!cacheKey) { core.info(`Cache not found for input keys: ${[ primaryKey, diff --git a/dist/restore/index.js b/dist/restore/index.js index c85a85177..4bc80fdee 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -4979,7 +4979,7 @@ var Inputs; Inputs["RestoreKeys"] = "restore-keys"; Inputs["UploadChunkSize"] = "upload-chunk-size"; Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; - Inputs["DryRun"] = "dry-run"; // Input for cache, restore action + Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action })(Inputs = exports.Inputs || (exports.Inputs = {})); var Outputs; (function (Outputs) { @@ -41781,7 +41781,7 @@ function getDownloadOptions(copy) { downloadConcurrency: 8, timeoutInMs: 30000, segmentTimeoutInMs: 3600000, - dryRun: false + lookupOnly: false }; if (copy) { if (typeof copy.useAzureSdk === 'boolean') { @@ -41796,8 +41796,8 @@ function getDownloadOptions(copy) { if (typeof copy.segmentTimeoutInMs === 'number') { result.segmentTimeoutInMs = copy.segmentTimeoutInMs; } - if (typeof copy.dryRun === 'boolean') { - result.dryRun = copy.dryRun; + if (typeof copy.lookupOnly === 'boolean') { + result.lookupOnly = copy.lookupOnly; } } const segmentDownloadTimeoutMins = process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']; @@ -41811,7 +41811,7 @@ function getDownloadOptions(copy) { core.debug(`Request timeout (ms): ${result.timeoutInMs}`); core.debug(`Cache segment download timeout mins env var: ${process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']}`); core.debug(`Segment download timeout (ms): ${result.segmentTimeoutInMs}`); - core.debug(`Dry run: ${result.dryRun}`); + core.debug(`Lookup only: ${result.lookupOnly}`); return result; } exports.getDownloadOptions = getDownloadOptions; @@ -47260,8 +47260,8 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch // Cache not found return undefined; } - if (options === null || options === void 0 ? void 0 : options.dryRun) { - core.info('Dry run - skipping download'); + if (options === null || options === void 0 ? void 0 : options.lookupOnly) { + core.info('Lookup only - skipping download'); return cacheEntry.cacheKey; } archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod)); @@ -50505,8 +50505,8 @@ function restoreImpl(stateProvider) { required: true }); const enableCrossOsArchive = utils.getInputAsBool(constants_1.Inputs.EnableCrossOsArchive); - const dryRun = utils.getInputAsBool(constants_1.Inputs.DryRun); - const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, { dryRun: dryRun }, enableCrossOsArchive); + const lookupOnly = utils.getInputAsBool(constants_1.Inputs.LookupOnly); + const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, { lookupOnly: lookupOnly }, enableCrossOsArchive); if (!cacheKey) { core.info(`Cache not found for input keys: ${[ primaryKey, diff --git a/dist/save-only/index.js b/dist/save-only/index.js index 23a38afee..d849d9474 100644 --- a/dist/save-only/index.js +++ b/dist/save-only/index.js @@ -5035,7 +5035,7 @@ var Inputs; Inputs["RestoreKeys"] = "restore-keys"; Inputs["UploadChunkSize"] = "upload-chunk-size"; Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; - Inputs["DryRun"] = "dry-run"; // Input for cache, restore action + Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action })(Inputs = exports.Inputs || (exports.Inputs = {})); var Outputs; (function (Outputs) { @@ -41922,7 +41922,7 @@ function getDownloadOptions(copy) { downloadConcurrency: 8, timeoutInMs: 30000, segmentTimeoutInMs: 3600000, - dryRun: false + lookupOnly: false }; if (copy) { if (typeof copy.useAzureSdk === 'boolean') { @@ -41937,8 +41937,8 @@ function getDownloadOptions(copy) { if (typeof copy.segmentTimeoutInMs === 'number') { result.segmentTimeoutInMs = copy.segmentTimeoutInMs; } - if (typeof copy.dryRun === 'boolean') { - result.dryRun = copy.dryRun; + if (typeof copy.lookupOnly === 'boolean') { + result.lookupOnly = copy.lookupOnly; } } const segmentDownloadTimeoutMins = process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']; @@ -41952,7 +41952,7 @@ function getDownloadOptions(copy) { core.debug(`Request timeout (ms): ${result.timeoutInMs}`); core.debug(`Cache segment download timeout mins env var: ${process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']}`); core.debug(`Segment download timeout (ms): ${result.segmentTimeoutInMs}`); - core.debug(`Dry run: ${result.dryRun}`); + core.debug(`Lookup only: ${result.lookupOnly}`); return result; } exports.getDownloadOptions = getDownloadOptions; @@ -47401,8 +47401,8 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch // Cache not found return undefined; } - if (options === null || options === void 0 ? void 0 : options.dryRun) { - core.info('Dry run - skipping download'); + if (options === null || options === void 0 ? void 0 : options.lookupOnly) { + core.info('Lookup only - skipping download'); return cacheEntry.cacheKey; } archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod)); diff --git a/dist/save/index.js b/dist/save/index.js index ddc4e9b25..700525133 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -4979,7 +4979,7 @@ var Inputs; Inputs["RestoreKeys"] = "restore-keys"; Inputs["UploadChunkSize"] = "upload-chunk-size"; Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive"; - Inputs["DryRun"] = "dry-run"; // Input for cache, restore action + Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action })(Inputs = exports.Inputs || (exports.Inputs = {})); var Outputs; (function (Outputs) { @@ -41866,7 +41866,7 @@ function getDownloadOptions(copy) { downloadConcurrency: 8, timeoutInMs: 30000, segmentTimeoutInMs: 3600000, - dryRun: false + lookupOnly: false }; if (copy) { if (typeof copy.useAzureSdk === 'boolean') { @@ -41881,8 +41881,8 @@ function getDownloadOptions(copy) { if (typeof copy.segmentTimeoutInMs === 'number') { result.segmentTimeoutInMs = copy.segmentTimeoutInMs; } - if (typeof copy.dryRun === 'boolean') { - result.dryRun = copy.dryRun; + if (typeof copy.lookupOnly === 'boolean') { + result.lookupOnly = copy.lookupOnly; } } const segmentDownloadTimeoutMins = process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']; @@ -41896,7 +41896,7 @@ function getDownloadOptions(copy) { core.debug(`Request timeout (ms): ${result.timeoutInMs}`); core.debug(`Cache segment download timeout mins env var: ${process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']}`); core.debug(`Segment download timeout (ms): ${result.segmentTimeoutInMs}`); - core.debug(`Dry run: ${result.dryRun}`); + core.debug(`Lookup only: ${result.lookupOnly}`); return result; } exports.getDownloadOptions = getDownloadOptions; @@ -47374,8 +47374,8 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch // Cache not found return undefined; } - if (options === null || options === void 0 ? void 0 : options.dryRun) { - core.info('Dry run - skipping download'); + if (options === null || options === void 0 ? void 0 : options.lookupOnly) { + core.info('Lookup only - skipping download'); return cacheEntry.cacheKey; } archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod)); diff --git a/package-lock.json b/package-lock.json index a00db4292..31d505294 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.2.3", "license": "MIT", "dependencies": { - "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.2.tgz", + "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.3.tgz", "@actions/core": "^1.10.0", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.2" @@ -36,9 +36,9 @@ } }, "node_modules/@actions/cache": { - "version": "3.1.2", - "resolved": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.2.tgz", - "integrity": "sha512-1vcZXG2jWtEnDWq34byiQmS8tgOKAzFEIiMFPtxigm3vHOW+9FGdA2S+eWsK3NBLIbWd5erCkWgo4M0g6gw1yw==", + "version": "3.1.3", + "resolved": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.3.tgz", + "integrity": "sha512-MuG08PR5rNlFjrWJPTvs6uzF2W7ddovjFZHd1ivwehn+Epj01v7MIDDfd7ooeXJ104/ksCj0JhEDr2SxvhxxWA==", "license": "MIT", "dependencies": { "@actions/core": "^1.10.0", @@ -9723,8 +9723,8 @@ }, "dependencies": { "@actions/cache": { - "version": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.2.tgz", - "integrity": "sha512-1vcZXG2jWtEnDWq34byiQmS8tgOKAzFEIiMFPtxigm3vHOW+9FGdA2S+eWsK3NBLIbWd5erCkWgo4M0g6gw1yw==", + "version": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.3.tgz", + "integrity": "sha512-MuG08PR5rNlFjrWJPTvs6uzF2W7ddovjFZHd1ivwehn+Epj01v7MIDDfd7ooeXJ104/ksCj0JhEDr2SxvhxxWA==", "requires": { "@actions/core": "^1.10.0", "@actions/exec": "^1.0.1", diff --git a/package.json b/package.json index 734f9e4f4..eee966919 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "author": "GitHub", "license": "MIT", "dependencies": { - "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.2.tgz", + "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.3.tgz", "@actions/core": "^1.10.0", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.2" diff --git a/restore/README.md b/restore/README.md index b3f091957..a6d8b6769 100644 --- a/restore/README.md +++ b/restore/README.md @@ -7,7 +7,7 @@ The restore action, as the name suggest, restores a cache. It acts similar to th * `path` - A list of files, directories, and wildcard patterns to cache and restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob) for supported patterns. * `key` - String used while saving cache for restoring the cache * `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key. -* `dry-run` - Skip downloading cache. Only check if cache entry exists. Default: false +* `lookup-only` - Skip downloading cache. Only check if cache entry exists. Default: false ## Outputs diff --git a/restore/action.yml b/restore/action.yml index 67e4c7378..db6f05ae3 100644 --- a/restore/action.yml +++ b/restore/action.yml @@ -15,7 +15,7 @@ inputs: description: 'An optional boolean when enabled, allows windows runners to restore caches that were saved on other platforms' default: 'false' required: false - dry-run: + lookup-only: description: 'Skip downloading cache. Only check if cache entry exists' default: 'false' required: false diff --git a/src/constants.ts b/src/constants.ts index 2753adaef..f3340f953 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -4,7 +4,7 @@ export enum Inputs { RestoreKeys = "restore-keys", // Input for cache, restore action UploadChunkSize = "upload-chunk-size", // Input for cache, save action EnableCrossOsArchive = "enableCrossOsArchive", // Input for cache, restore, save action - DryRun = "dry-run" // Input for cache, restore action + LookupOnly = "lookup-only" // Input for cache, restore action } export enum Outputs { diff --git a/src/restoreImpl.ts b/src/restoreImpl.ts index f9aa3134f..0675b419d 100644 --- a/src/restoreImpl.ts +++ b/src/restoreImpl.ts @@ -34,13 +34,13 @@ async function restoreImpl( const enableCrossOsArchive = utils.getInputAsBool( Inputs.EnableCrossOsArchive ); - const dryRun = utils.getInputAsBool(Inputs.DryRun); + const lookupOnly = utils.getInputAsBool(Inputs.LookupOnly); const cacheKey = await cache.restoreCache( cachePaths, primaryKey, restoreKeys, - { dryRun: dryRun }, + { lookupOnly: lookupOnly }, enableCrossOsArchive ); diff --git a/src/utils/testUtils.ts b/src/utils/testUtils.ts index ee5ea83aa..4479c6ecc 100644 --- a/src/utils/testUtils.ts +++ b/src/utils/testUtils.ts @@ -14,7 +14,7 @@ interface CacheInput { key: string; restoreKeys?: string[]; enableCrossOsArchive?: boolean; - dryRun?: boolean; + lookupOnly?: boolean; } export function setInputs(input: CacheInput): void { @@ -27,8 +27,8 @@ export function setInputs(input: CacheInput): void { Inputs.EnableCrossOsArchive, input.enableCrossOsArchive.toString() ); - input.dryRun !== undefined && - setInput(Inputs.DryRun, input.dryRun.toString()); + input.lookupOnly !== undefined && + setInput(Inputs.LookupOnly, input.lookupOnly.toString()); } export function clearInputs(): void { @@ -37,5 +37,5 @@ export function clearInputs(): void { delete process.env[getInputName(Inputs.RestoreKeys)]; delete process.env[getInputName(Inputs.UploadChunkSize)]; delete process.env[getInputName(Inputs.EnableCrossOsArchive)]; - delete process.env[getInputName(Inputs.DryRun)]; + delete process.env[getInputName(Inputs.LookupOnly)]; } From 9478269f867041f247107af8f795f68e0d1a560e Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:34:51 +0100 Subject: [PATCH 06/14] Update test name --- __tests__/restore.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index 4e133d387..4573ec81d 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -357,7 +357,7 @@ test("restore with fail on cache miss disabled and no cache found", async () => expect(failedMock).toHaveBeenCalledTimes(0); }); -test("restore with dry-run set", async () => { +test("restore with lookup-only set", async () => { const path = "node_modules"; const key = "node-test"; testUtils.setInputs({ From c022fd886e59dae7a57d612fea29b794c9a7f6d3 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:35:15 +0100 Subject: [PATCH 07/14] Update package.json + changelog --- README.md | 1 + RELEASES.md | 3 +++ package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 289024233..8a6fcc466 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac * Two new actions available for granular control over caches - [restore](restore/action.yml) and [save](save/action.yml) * Support cross-os caching as an opt-in feature. See [Cross OS caching](./tips-and-workarounds.md#cross-os-cache) for more info. * Added option to fail job on cache miss. See [Exit workflow on cache miss](./restore/README.md#exit-workflow-on-cache-miss) for more info. +* Added option to lookup cache without downloading it. Refer [here](https://github.com/actions/cache/blob/v2/README.md) for previous versions diff --git a/RELEASES.md b/RELEASES.md index 50cfd919f..a58e5843e 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -70,3 +70,6 @@ ### 3.2.4 - Added option to fail job on cache miss. + +### 3.3.0 +- Added option to lookup cache without downloading it. diff --git a/package-lock.json b/package-lock.json index 010c342fb..c6dd2610a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cache", - "version": "3.2.4", + "version": "3.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "cache", - "version": "3.2.4", + "version": "3.3.0", "license": "MIT", "dependencies": { "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.3.tgz", diff --git a/package.json b/package.json index 6222c7866..3a5cd3da8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cache", - "version": "3.2.4", + "version": "3.3.0", "private": true, "description": "Cache dependencies and build outputs", "main": "dist/restore/index.js", From 28513d5388d4931850b63e51e8245e228d76de3a Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 9 Feb 2023 16:40:55 +0100 Subject: [PATCH 08/14] Update README --- README.md | 2 +- restore/README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6fbbd38fa..2df614403 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are requir * `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key. * `enableCrossOsArchive` - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: `false` * `fail-on-cache-miss` - Fail the workflow if cache entry is not found. Default: `false` -* `lookup-only` - Skip downloading cache. Only check if cache entry exists. Default: false +* `lookup-only` - Skip downloading cache. Only check if cache entry exists. Default: `false` #### Environment Variables diff --git a/restore/README.md b/restore/README.md index 9e4654d95..a0be630f5 100644 --- a/restore/README.md +++ b/restore/README.md @@ -9,8 +9,8 @@ The restore action restores a cache. It works similarly to the `cache` action ex * `key` - An explicit key for a cache entry. See [creating a cache key](../README.md#creating-a-cache-key). * `path` - A list of files, directories, and wildcard patterns to restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob) for supported patterns. * `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key. -* `fail-on-cache-miss` - Fail the workflow if cache entry is not found. Default: false -* `lookup-only` - Skip downloading cache. Only check if cache entry exists. Default: false +* `fail-on-cache-miss` - Fail the workflow if cache entry is not found. Default: `false` +* `lookup-only` - Skip downloading cache. Only check if cache entry exists. Default: `false` ### Outputs From 380a44a2bb3a89d3fba6c67d93f92a90404c7583 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 10 Feb 2023 22:35:10 +0100 Subject: [PATCH 09/14] Update custom package version --- package-lock.json | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index c6dd2610a..bbeaac330 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.3.0", "license": "MIT", "dependencies": { - "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.3.tgz", + "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.4.tgz", "@actions/core": "^1.10.0", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.2" @@ -36,9 +36,9 @@ } }, "node_modules/@actions/cache": { - "version": "3.1.3", - "resolved": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.3.tgz", - "integrity": "sha512-MuG08PR5rNlFjrWJPTvs6uzF2W7ddovjFZHd1ivwehn+Epj01v7MIDDfd7ooeXJ104/ksCj0JhEDr2SxvhxxWA==", + "version": "3.1.4", + "resolved": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.4.tgz", + "integrity": "sha512-QdXk4YhfILpIUZBctx3Q7eM6cT/F1Pe7n0S09WyfAiZA991AfEXxzXgh8tKNhxf90rY62GDfOLvVr/0xieyQOg==", "license": "MIT", "dependencies": { "@actions/core": "^1.10.0", @@ -9723,8 +9723,8 @@ }, "dependencies": { "@actions/cache": { - "version": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.3.tgz", - "integrity": "sha512-MuG08PR5rNlFjrWJPTvs6uzF2W7ddovjFZHd1ivwehn+Epj01v7MIDDfd7ooeXJ104/ksCj0JhEDr2SxvhxxWA==", + "version": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.4.tgz", + "integrity": "sha512-QdXk4YhfILpIUZBctx3Q7eM6cT/F1Pe7n0S09WyfAiZA991AfEXxzXgh8tKNhxf90rY62GDfOLvVr/0xieyQOg==", "requires": { "@actions/core": "^1.10.0", "@actions/exec": "^1.0.1", diff --git a/package.json b/package.json index 3a5cd3da8..d3695b818 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "author": "GitHub", "license": "MIT", "dependencies": { - "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.3.tgz", + "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.4.tgz", "@actions/core": "^1.10.0", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.2" From 9771ee3aa39d2ce90b54c6ee4c0fd326c9d82456 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 21 Feb 2023 12:59:55 +0100 Subject: [PATCH 10/14] Update custom package version --- .licenses/npm/@actions/cache.dep.yml | 2 +- package-lock.json | 12 ++++++------ package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.licenses/npm/@actions/cache.dep.yml b/.licenses/npm/@actions/cache.dep.yml index ddbc31623..f9f6985aa 100644 --- a/.licenses/npm/@actions/cache.dep.yml +++ b/.licenses/npm/@actions/cache.dep.yml @@ -1,6 +1,6 @@ --- name: "@actions/cache" -version: 3.1.4 +version: 3.1.5 type: npm summary: homepage: diff --git a/package-lock.json b/package-lock.json index bbeaac330..d41088220 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.3.0", "license": "MIT", "dependencies": { - "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.4.tgz", + "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.5.tgz", "@actions/core": "^1.10.0", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.2" @@ -36,9 +36,9 @@ } }, "node_modules/@actions/cache": { - "version": "3.1.4", - "resolved": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.4.tgz", - "integrity": "sha512-QdXk4YhfILpIUZBctx3Q7eM6cT/F1Pe7n0S09WyfAiZA991AfEXxzXgh8tKNhxf90rY62GDfOLvVr/0xieyQOg==", + "version": "3.1.5", + "resolved": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.5.tgz", + "integrity": "sha512-GN5fFSW8Le8ITPvjPgotxI+V4yZYtORxfab6i3GfNQ7f+qbi7JqWOsKEYJvI9eKSdWp3YPiekzRrKUpNRrmziQ==", "license": "MIT", "dependencies": { "@actions/core": "^1.10.0", @@ -9723,8 +9723,8 @@ }, "dependencies": { "@actions/cache": { - "version": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.4.tgz", - "integrity": "sha512-QdXk4YhfILpIUZBctx3Q7eM6cT/F1Pe7n0S09WyfAiZA991AfEXxzXgh8tKNhxf90rY62GDfOLvVr/0xieyQOg==", + "version": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.5.tgz", + "integrity": "sha512-GN5fFSW8Le8ITPvjPgotxI+V4yZYtORxfab6i3GfNQ7f+qbi7JqWOsKEYJvI9eKSdWp3YPiekzRrKUpNRrmziQ==", "requires": { "@actions/core": "^1.10.0", "@actions/exec": "^1.0.1", diff --git a/package.json b/package.json index d3695b818..a4d5d173c 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "author": "GitHub", "license": "MIT", "dependencies": { - "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.4.tgz", + "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.5.tgz", "@actions/core": "^1.10.0", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.2" From d57039cf5c0221e2abe9352fbdb1a8ddfc7ff608 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Wed, 8 Mar 2023 21:47:30 +0100 Subject: [PATCH 11/14] Update @actions/cache to 3.2.0 --- .licenses/npm/@actions/cache.dep.yml | 2 +- package-lock.json | 14 +++++++------- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.licenses/npm/@actions/cache.dep.yml b/.licenses/npm/@actions/cache.dep.yml index f9f6985aa..bde674f61 100644 --- a/.licenses/npm/@actions/cache.dep.yml +++ b/.licenses/npm/@actions/cache.dep.yml @@ -1,6 +1,6 @@ --- name: "@actions/cache" -version: 3.1.5 +version: 3.2.0 type: npm summary: homepage: diff --git a/package-lock.json b/package-lock.json index d41088220..7751fc241 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.3.0", "license": "MIT", "dependencies": { - "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.5.tgz", + "@actions/cache": "^3.2.0", "@actions/core": "^1.10.0", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.2" @@ -36,10 +36,9 @@ } }, "node_modules/@actions/cache": { - "version": "3.1.5", - "resolved": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.5.tgz", - "integrity": "sha512-GN5fFSW8Le8ITPvjPgotxI+V4yZYtORxfab6i3GfNQ7f+qbi7JqWOsKEYJvI9eKSdWp3YPiekzRrKUpNRrmziQ==", - "license": "MIT", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-3.2.0.tgz", + "integrity": "sha512-bCjN0+gPLaZZbpOoeK/1ve7J5MO+zv8FpcdKOWF3Tb9to0bWDpvgn9D2c/lC22oPUtHnCWQhLNVMfsWF4OBhNw==", "dependencies": { "@actions/core": "^1.10.0", "@actions/exec": "^1.0.1", @@ -9723,8 +9722,9 @@ }, "dependencies": { "@actions/cache": { - "version": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.5.tgz", - "integrity": "sha512-GN5fFSW8Le8ITPvjPgotxI+V4yZYtORxfab6i3GfNQ7f+qbi7JqWOsKEYJvI9eKSdWp3YPiekzRrKUpNRrmziQ==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-3.2.0.tgz", + "integrity": "sha512-bCjN0+gPLaZZbpOoeK/1ve7J5MO+zv8FpcdKOWF3Tb9to0bWDpvgn9D2c/lC22oPUtHnCWQhLNVMfsWF4OBhNw==", "requires": { "@actions/core": "^1.10.0", "@actions/exec": "^1.0.1", diff --git a/package.json b/package.json index a4d5d173c..2ace307c1 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "author": "GitHub", "license": "MIT", "dependencies": { - "@actions/cache": "https://github.com/cdce8p/toolkit/raw/cache-dry-run-release/packages/cache/actions-cache-3.1.5.tgz", + "@actions/cache": "^3.2.0", "@actions/core": "^1.10.0", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.2" From 84097c060632df2addcc25a2f9a82973dcc68909 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 9 Mar 2023 11:00:37 +0100 Subject: [PATCH 12/14] Code review --- __tests__/restore.test.ts | 4 +++- action.yml | 2 +- dist/restore-only/index.js | 7 ++++++- dist/restore/index.js | 7 ++++++- restore/README.md | 2 +- restore/action.yml | 2 +- src/restoreImpl.ts | 6 +++++- 7 files changed, 23 insertions(+), 7 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index 4573ec81d..faab1cdae 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -396,6 +396,8 @@ test("restore with lookup-only set", async () => { expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true"); - expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`); + expect(infoMock).toHaveBeenCalledWith( + `Cache would have been restored from key: ${key}` + ); expect(failedMock).toHaveBeenCalledTimes(0); }); diff --git a/action.yml b/action.yml index 1eb19b96f..5c6fa8731 100644 --- a/action.yml +++ b/action.yml @@ -23,7 +23,7 @@ inputs: default: 'false' required: false lookup-only: - description: 'Skip downloading cache. Only check if cache entry exists' + description: 'Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache' default: 'false' required: false outputs: diff --git a/dist/restore-only/index.js b/dist/restore-only/index.js index 70c54b887..c0c021436 100644 --- a/dist/restore-only/index.js +++ b/dist/restore-only/index.js @@ -50520,7 +50520,12 @@ function restoreImpl(stateProvider) { stateProvider.setState(constants_1.State.CacheMatchedKey, cacheKey); const isExactKeyMatch = utils.isExactKeyMatch(core.getInput(constants_1.Inputs.Key, { required: true }), cacheKey); core.setOutput(constants_1.Outputs.CacheHit, isExactKeyMatch.toString()); - core.info(`Cache restored from key: ${cacheKey}`); + if (lookupOnly) { + core.info(`Cache would have been restored from key: ${cacheKey}`); + } + else { + core.info(`Cache restored from key: ${cacheKey}`); + } return cacheKey; } catch (error) { diff --git a/dist/restore/index.js b/dist/restore/index.js index e55e25b56..83fc4f64e 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -50520,7 +50520,12 @@ function restoreImpl(stateProvider) { stateProvider.setState(constants_1.State.CacheMatchedKey, cacheKey); const isExactKeyMatch = utils.isExactKeyMatch(core.getInput(constants_1.Inputs.Key, { required: true }), cacheKey); core.setOutput(constants_1.Outputs.CacheHit, isExactKeyMatch.toString()); - core.info(`Cache restored from key: ${cacheKey}`); + if (lookupOnly) { + core.info(`Cache would have been restored from key: ${cacheKey}`); + } + else { + core.info(`Cache restored from key: ${cacheKey}`); + } return cacheKey; } catch (error) { diff --git a/restore/README.md b/restore/README.md index a0be630f5..6571aef71 100644 --- a/restore/README.md +++ b/restore/README.md @@ -10,7 +10,7 @@ The restore action restores a cache. It works similarly to the `cache` action ex * `path` - A list of files, directories, and wildcard patterns to restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob) for supported patterns. * `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key. * `fail-on-cache-miss` - Fail the workflow if cache entry is not found. Default: `false` -* `lookup-only` - Skip downloading cache. Only check if cache entry exists. Default: `false` +* `lookup-only` - Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache. Default: `false` ### Outputs diff --git a/restore/action.yml b/restore/action.yml index 6dbca0061..21be5f059 100644 --- a/restore/action.yml +++ b/restore/action.yml @@ -20,7 +20,7 @@ inputs: default: 'false' required: false lookup-only: - description: 'Skip downloading cache. Only check if cache entry exists' + description: 'Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache' default: 'false' required: false outputs: diff --git a/src/restoreImpl.ts b/src/restoreImpl.ts index 048d9faa7..275a97135 100644 --- a/src/restoreImpl.ts +++ b/src/restoreImpl.ts @@ -70,7 +70,11 @@ async function restoreImpl( ); core.setOutput(Outputs.CacheHit, isExactKeyMatch.toString()); - core.info(`Cache restored from key: ${cacheKey}`); + if (lookupOnly) { + core.info(`Cache would have been restored from key: ${cacheKey}`); + } else { + core.info(`Cache restored from key: ${cacheKey}`); + } return cacheKey; } catch (error: unknown) { From 184089677819e7bce02066372d76e0449c7a2c8f Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 9 Mar 2023 11:46:09 +0100 Subject: [PATCH 13/14] Update log statement --- __tests__/restore.test.ts | 2 +- dist/restore-only/index.js | 2 +- dist/restore/index.js | 2 +- src/restoreImpl.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index faab1cdae..c8c4029bc 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -397,7 +397,7 @@ test("restore with lookup-only set", async () => { expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true"); expect(infoMock).toHaveBeenCalledWith( - `Cache would have been restored from key: ${key}` + `Cache found and can be restored from key: ${key}` ); expect(failedMock).toHaveBeenCalledTimes(0); }); diff --git a/dist/restore-only/index.js b/dist/restore-only/index.js index c0c021436..883dfbcad 100644 --- a/dist/restore-only/index.js +++ b/dist/restore-only/index.js @@ -50521,7 +50521,7 @@ function restoreImpl(stateProvider) { const isExactKeyMatch = utils.isExactKeyMatch(core.getInput(constants_1.Inputs.Key, { required: true }), cacheKey); core.setOutput(constants_1.Outputs.CacheHit, isExactKeyMatch.toString()); if (lookupOnly) { - core.info(`Cache would have been restored from key: ${cacheKey}`); + core.info(`Cache found and can be restored from key: ${cacheKey}`); } else { core.info(`Cache restored from key: ${cacheKey}`); diff --git a/dist/restore/index.js b/dist/restore/index.js index 83fc4f64e..2fe23bc38 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -50521,7 +50521,7 @@ function restoreImpl(stateProvider) { const isExactKeyMatch = utils.isExactKeyMatch(core.getInput(constants_1.Inputs.Key, { required: true }), cacheKey); core.setOutput(constants_1.Outputs.CacheHit, isExactKeyMatch.toString()); if (lookupOnly) { - core.info(`Cache would have been restored from key: ${cacheKey}`); + core.info(`Cache found and can be restored from key: ${cacheKey}`); } else { core.info(`Cache restored from key: ${cacheKey}`); diff --git a/src/restoreImpl.ts b/src/restoreImpl.ts index 275a97135..797bc74f9 100644 --- a/src/restoreImpl.ts +++ b/src/restoreImpl.ts @@ -71,7 +71,7 @@ async function restoreImpl( core.setOutput(Outputs.CacheHit, isExactKeyMatch.toString()); if (lookupOnly) { - core.info(`Cache would have been restored from key: ${cacheKey}`); + core.info(`Cache found and can be restored from key: ${cacheKey}`); } else { core.info(`Cache restored from key: ${cacheKey}`); } From b417e128396d9373100d934ae04076b0121c750b Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 9 Mar 2023 13:15:14 +0100 Subject: [PATCH 14/14] Move test case --- __tests__/restore.test.ts | 45 ----------------------------------- __tests__/restoreImpl.test.ts | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index c8c4029bc..c51c293b1 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -356,48 +356,3 @@ test("restore with fail on cache miss disabled and no cache found", async () => ); expect(failedMock).toHaveBeenCalledTimes(0); }); - -test("restore with lookup-only set", async () => { - const path = "node_modules"; - const key = "node-test"; - testUtils.setInputs({ - path: path, - key, - lookupOnly: true - }); - - const infoMock = jest.spyOn(core, "info"); - const failedMock = jest.spyOn(core, "setFailed"); - const stateMock = jest.spyOn(core, "saveState"); - const setCacheHitOutputMock = jest.spyOn(core, "setOutput"); - const restoreCacheMock = jest - .spyOn(cache, "restoreCache") - .mockImplementationOnce(() => { - return Promise.resolve(key); - }); - - await run(); - - expect(restoreCacheMock).toHaveBeenCalledTimes(1); - expect(restoreCacheMock).toHaveBeenCalledWith( - [path], - key, - [], - { - lookupOnly: true - }, - false - ); - - expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); - expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key); - expect(stateMock).toHaveBeenCalledTimes(2); - - expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); - expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true"); - - expect(infoMock).toHaveBeenCalledWith( - `Cache found and can be restored from key: ${key}` - ); - expect(failedMock).toHaveBeenCalledTimes(0); -}); diff --git a/__tests__/restoreImpl.test.ts b/__tests__/restoreImpl.test.ts index 315fc7a99..d6f13ba1d 100644 --- a/__tests__/restoreImpl.test.ts +++ b/__tests__/restoreImpl.test.ts @@ -404,3 +404,48 @@ test("restore with cache found for restore key", async () => { ); expect(failedMock).toHaveBeenCalledTimes(0); }); + +test("restore with lookup-only set", async () => { + const path = "node_modules"; + const key = "node-test"; + testUtils.setInputs({ + path: path, + key, + lookupOnly: true + }); + + const infoMock = jest.spyOn(core, "info"); + const failedMock = jest.spyOn(core, "setFailed"); + const stateMock = jest.spyOn(core, "saveState"); + const setCacheHitOutputMock = jest.spyOn(core, "setOutput"); + const restoreCacheMock = jest + .spyOn(cache, "restoreCache") + .mockImplementationOnce(() => { + return Promise.resolve(key); + }); + + await run(new StateProvider()); + + expect(restoreCacheMock).toHaveBeenCalledTimes(1); + expect(restoreCacheMock).toHaveBeenCalledWith( + [path], + key, + [], + { + lookupOnly: true + }, + false + ); + + expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); + expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key); + expect(stateMock).toHaveBeenCalledTimes(2); + + expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); + expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true"); + + expect(infoMock).toHaveBeenCalledWith( + `Cache found and can be restored from key: ${key}` + ); + expect(failedMock).toHaveBeenCalledTimes(0); +});