diff --git a/README.md b/README.md index e171a43..2a2461f 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,12 @@ sensible defaults. # Determines if the cache should be saved even when the workflow has failed. # default: "false" cache-on-failure: "" + + # Determiners whether the cache should be saved. + # If `false`, the cache is only restored. + # Useful for jobs where the matrix is additive e.g. additional Cargo features. + # default: "true" + save-if: "" ``` Further examples are available in the [.github/workflows](./.github/workflows/) directory. diff --git a/action.yml b/action.yml index a03405b..7469b80 100644 --- a/action.yml +++ b/action.yml @@ -28,6 +28,10 @@ inputs: cache-on-failure: description: "Cache even if the build fails. Defaults to false." required: false + save-if: + description: "Determiners whether the cache should be saved. If `false`, the cache is only restored." + required: false + default: "true" outputs: cache-hit: description: "A boolean value that indicates an exact match was found." diff --git a/src/save.ts b/src/save.ts index 261512f..583e15d 100644 --- a/src/save.ts +++ b/src/save.ts @@ -13,7 +13,9 @@ process.on("uncaughtException", (e) => { }); async function run() { - if (!cache.isFeatureAvailable()) { + const save = core.getInput("save-if").toLowerCase() || "true"; + + if (!(cache.isFeatureAvailable() && save === "true")) { return; }