Skip to content

Commit

Permalink
feat: add save-if option, closes #66 (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Nov 6, 2022
1 parent b894d59 commit ecee04e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -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."
Expand Down
4 changes: 3 additions & 1 deletion src/save.ts
Expand Up @@ -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;
}

Expand Down

0 comments on commit ecee04e

Please sign in to comment.