From 2935c2ea2701cfe3735587a53ac901c7875b96b1 Mon Sep 17 00:00:00 2001 From: Timo Rothenpieler Date: Fri, 5 Nov 2021 16:19:11 +0100 Subject: [PATCH] Add option to re-evaluate cache key during post action --- README.md | 1 + action.yml | 4 ++++ src/constants.ts | 3 ++- src/save.ts | 5 +++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 408fd2e..2a187b5 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ If you are using this inside a container, a POSIX-compliant `tar` needs to be in * `key` - An explicit key for restoring and saving the cache * `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case. +* `reeval-key` - A boolean which causes the key to be re-evaluated during the Post-Action step #### Environment Variables * `SEGMENT_DOWNLOAD_TIMEOUT_MIN` - Segment download timeout (in minutes, default `60`) to abort download of the segment if not completed in the defined number of minutes. [Read more](#cache-segment-restore-timeout) diff --git a/action.yml b/action.yml index 3e158e3..5089b33 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,10 @@ inputs: upload-chunk-size: description: 'The chunk size used to split up large files during upload, in bytes' required: false + reeval-key: + description: 'Re-evaluate the cache key during the post-action' + 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/constants.ts b/src/constants.ts index 133f47d..7572770 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,7 +2,8 @@ export enum Inputs { Key = "key", Path = "path", RestoreKeys = "restore-keys", - UploadChunkSize = "upload-chunk-size" + UploadChunkSize = "upload-chunk-size", + ReEvalKey = "reeval-key" } export enum Outputs { diff --git a/src/save.ts b/src/save.ts index a0a21bf..109b392 100644 --- a/src/save.ts +++ b/src/save.ts @@ -26,8 +26,9 @@ async function run(): Promise { 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(State.CachePrimaryKey); + const primaryKey = core.getBooleanInput(Inputs.ReEvalKey) + ? core.getInput(Inputs.Key, { required: true }) + : core.getState(State.CachePrimaryKey); if (!primaryKey) { utils.logWarning(`Error retrieving key from state.`); return;