Cache-on-failure support (#22)

This commit is contained in:
Tom Parker-Shemilt 2021-06-28 22:18:07 +01:00 committed by GitHub
parent 842ef286ff
commit 536c94f32c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 2 deletions

View File

@ -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

View File

@ -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`

View File

@ -14,6 +14,9 @@ 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"
@ -21,7 +24,7 @@ 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"

View File

@ -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");

View File

@ -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();