mirror of
https://github.com/Swatinem/rust-cache.git
synced 2024-11-22 22:06:07 +08:00
Adds an option to do lookup-only of the cache (#217)
This commit is contained in:
parent
68b3cb7503
commit
c00f3025ca
@ -60,7 +60,7 @@ sensible defaults.
|
|||||||
# default: "false"
|
# default: "false"
|
||||||
cache-all-crates: ""
|
cache-all-crates: ""
|
||||||
|
|
||||||
# Determiners whether the cache should be saved.
|
# Determines whether the cache should be saved.
|
||||||
# If `false`, the cache is only restored.
|
# If `false`, the cache is only restored.
|
||||||
# Useful for jobs where the matrix is additive e.g. additional Cargo features,
|
# Useful for jobs where the matrix is additive e.g. additional Cargo features,
|
||||||
# or when only runs from `master` should be saved to the cache.
|
# or when only runs from `master` should be saved to the cache.
|
||||||
@ -69,6 +69,12 @@ sensible defaults.
|
|||||||
# To only cache runs from `master`:
|
# To only cache runs from `master`:
|
||||||
save-if: ${{ github.ref == 'refs/heads/master' }}
|
save-if: ${{ github.ref == 'refs/heads/master' }}
|
||||||
|
|
||||||
|
# Determines whether the cache should be restored.
|
||||||
|
# If `true` the cache key will be checked and the `cache-hit` output will be set
|
||||||
|
# but the cache itself won't be restored
|
||||||
|
# default: "false"
|
||||||
|
lookup-only: ""
|
||||||
|
|
||||||
# Specifies what to use as the backend providing cache
|
# Specifies what to use as the backend providing cache
|
||||||
# Can be set to either "github" or "buildjet"
|
# Can be set to either "github" or "buildjet"
|
||||||
# default: "github"
|
# default: "github"
|
||||||
|
@ -40,6 +40,10 @@ inputs:
|
|||||||
description: "Determines which provider to use for caching. Options are github or buildjet, defaults to github."
|
description: "Determines which provider to use for caching. Options are github or buildjet, defaults to github."
|
||||||
required: false
|
required: false
|
||||||
default: "github"
|
default: "github"
|
||||||
|
lookup-only:
|
||||||
|
description: "Check if a cache entry exists without downloading the cache"
|
||||||
|
required: false
|
||||||
|
default: "false"
|
||||||
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."
|
||||||
|
7
dist/restore/index.js
vendored
7
dist/restore/index.js
vendored
@ -77876,20 +77876,21 @@ async function run() {
|
|||||||
if (cacheOnFailure !== "true") {
|
if (cacheOnFailure !== "true") {
|
||||||
cacheOnFailure = "false";
|
cacheOnFailure = "false";
|
||||||
}
|
}
|
||||||
|
var lookupOnly = lib_core.getInput("lookup-only").toLowerCase() === "true";
|
||||||
lib_core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure);
|
lib_core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure);
|
||||||
lib_core.exportVariable("CARGO_INCREMENTAL", 0);
|
lib_core.exportVariable("CARGO_INCREMENTAL", 0);
|
||||||
const config = await CacheConfig.new();
|
const config = await CacheConfig.new();
|
||||||
config.printInfo(cacheProvider);
|
config.printInfo(cacheProvider);
|
||||||
lib_core.info("");
|
lib_core.info("");
|
||||||
lib_core.info(`... Restoring cache ...`);
|
lib_core.info(`... ${lookupOnly ? "Checking" : "Restoring"} cache ...`);
|
||||||
const key = config.cacheKey;
|
const key = config.cacheKey;
|
||||||
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
|
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
|
||||||
// https://github.com/actions/toolkit/pull/1378
|
// https://github.com/actions/toolkit/pull/1378
|
||||||
// TODO: remove this once the underlying bug is fixed.
|
// TODO: remove this once the underlying bug is fixed.
|
||||||
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey]);
|
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], { lookupOnly });
|
||||||
if (restoreKey) {
|
if (restoreKey) {
|
||||||
const match = restoreKey === key;
|
const match = restoreKey === key;
|
||||||
lib_core.info(`Restored from cache key "${restoreKey}" full match: ${match}.`);
|
lib_core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
// pre-clean the target directory on cache mismatch
|
// pre-clean the target directory on cache mismatch
|
||||||
for (const workspace of config.workspaces) {
|
for (const workspace of config.workspaces) {
|
||||||
|
@ -24,6 +24,8 @@ async function run() {
|
|||||||
if (cacheOnFailure !== "true") {
|
if (cacheOnFailure !== "true") {
|
||||||
cacheOnFailure = "false";
|
cacheOnFailure = "false";
|
||||||
}
|
}
|
||||||
|
var lookupOnly = core.getInput("lookup-only").toLowerCase() === "true";
|
||||||
|
|
||||||
core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure);
|
core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure);
|
||||||
core.exportVariable("CARGO_INCREMENTAL", 0);
|
core.exportVariable("CARGO_INCREMENTAL", 0);
|
||||||
|
|
||||||
@ -31,15 +33,24 @@ async function run() {
|
|||||||
config.printInfo(cacheProvider);
|
config.printInfo(cacheProvider);
|
||||||
core.info("");
|
core.info("");
|
||||||
|
|
||||||
core.info(`... Restoring cache ...`);
|
core.info(`... ${lookupOnly ? "Checking" : "Restoring"} cache ...`);
|
||||||
const key = config.cacheKey;
|
const key = config.cacheKey;
|
||||||
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
|
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
|
||||||
// https://github.com/actions/toolkit/pull/1378
|
// https://github.com/actions/toolkit/pull/1378
|
||||||
// TODO: remove this once the underlying bug is fixed.
|
// TODO: remove this once the underlying bug is fixed.
|
||||||
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey]);
|
const restoreKey = await cacheProvider.cache.restoreCache(
|
||||||
|
config.cachePaths.slice(),
|
||||||
|
key,
|
||||||
|
[config.restoreKey],
|
||||||
|
{ lookupOnly }
|
||||||
|
);
|
||||||
if (restoreKey) {
|
if (restoreKey) {
|
||||||
const match = restoreKey === key;
|
const match = restoreKey === key;
|
||||||
core.info(`Restored from cache key "${restoreKey}" full match: ${match}.`);
|
core.info(
|
||||||
|
`${
|
||||||
|
lookupOnly ? "Found" : "Restored from"
|
||||||
|
} cache key "${restoreKey}" full match: ${match}.`
|
||||||
|
);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
// pre-clean the target directory on cache mismatch
|
// pre-clean the target directory on cache mismatch
|
||||||
for (const workspace of config.workspaces) {
|
for (const workspace of config.workspaces) {
|
||||||
|
Loading…
Reference in New Issue
Block a user