feat: add save-if option, closes #66

This commit is contained in:
Lucas Nogueira 2022-11-06 15:00:35 -03:00
parent b894d59a8d
commit bcbd604d7b
No known key found for this signature in database
GPG Key ID: C54D79C4018F1D19
3 changed files with 13 additions and 1 deletions

View File

@ -53,6 +53,12 @@ sensible defaults.
# Determines if the cache should be saved even when the workflow has failed. # Determines if the cache should be saved even when the workflow has failed.
# default: "false" # default: "false"
cache-on-failure: "" 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. Further examples are available in the [.github/workflows](./.github/workflows/) directory.

View File

@ -28,6 +28,10 @@ inputs:
cache-on-failure: cache-on-failure:
description: "Cache even if the build fails. Defaults to false." description: "Cache even if the build fails. Defaults to false."
required: 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: outputs:
cache-hit: cache-hit:
description: "A boolean value that indicates an exact match was found." description: "A boolean value that indicates an exact match was found."

View File

@ -13,7 +13,9 @@ process.on("uncaughtException", (e) => {
}); });
async function run() { async function run() {
if (!cache.isFeatureAvailable()) { const save = core.getInput("save-if").toLowerCase() || "true";
if (!(cache.isFeatureAvailable() && save === "true")) {
return; return;
} }