Skip to content

Commit

Permalink
Cache-on-failure support (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
palfrey committed Jun 28, 2021
1 parent 842ef28 commit 536c94f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/selftest.yml
Expand Up @@ -22,8 +22,10 @@ jobs:
override: true

- uses: ./
with:
cache-on-failure: true

- run: |
cargo install cargo-deny --locked
cargo check
cargo test
cargo test
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -31,6 +31,9 @@ located in the repo root.
: `target-dir`
The target directory that should be cleaned and persisted, defaults to `./target`.

: `cache-on-failure`
Cache even if the build fails, defaults to false

## Outputs

: `cache-hit`
Expand Down
5 changes: 4 additions & 1 deletion action.yml
Expand Up @@ -14,14 +14,17 @@ inputs:
target-dir:
description: "The target dir that should be cleaned and persisted, defaults to `./target`"
required: false
cache-on-failure:
description: "Cache even if the build fails. Defaults to false"
required: false
outputs:
cache-hit:
description: "A boolean value that indicates an exact match was found"
runs:
using: "node12"
main: "dist/restore/index.js"
post: "dist/save/index.js"
post-if: "success()"
post-if: "success() || env.CACHE_ON_FAILURE == 'true'"
branding:
icon: "archive"
color: "gray-dark"
3 changes: 3 additions & 0 deletions src/common.ts
Expand Up @@ -9,6 +9,9 @@ import path from "path";

process.on("uncaughtException", (e) => {
core.info(`[warning] ${e.message}`);
if (e.stack) {
core.info(e.stack)
}
});

const cwd = core.getInput("working-directory");
Expand Down
5 changes: 5 additions & 0 deletions src/restore.ts
Expand Up @@ -4,6 +4,11 @@ import { cleanTarget, getCacheConfig, getCargoBins, getPackages, stateBins, stat

async function run() {
try {
var cacheOnFailure = core.getInput("cache-on-failure").toLowerCase()
if (cacheOnFailure !== "true") {
cacheOnFailure = "false"
}
core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure)
core.exportVariable("CARGO_INCREMENTAL", 0);

const { paths, key, restoreKeys } = await getCacheConfig();
Expand Down

0 comments on commit 536c94f

Please sign in to comment.