Skip to content

Commit c00f302

Browse files
authored
Adds an option to do lookup-only of the cache (#217)
1 parent 68b3cb7 commit c00f302

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ sensible defaults.
6060
# default: "false"
6161
cache-all-crates: ""
6262

63-
# Determiners whether the cache should be saved.
63+
# Determines whether the cache should be saved.
6464
# If `false`, the cache is only restored.
6565
# Useful for jobs where the matrix is additive e.g. additional Cargo features,
6666
# or when only runs from `master` should be saved to the cache.
@@ -69,6 +69,12 @@ sensible defaults.
6969
# To only cache runs from `master`:
7070
save-if: ${{ github.ref == 'refs/heads/master' }}
7171

72+
# Determines whether the cache should be restored.
73+
# If `true` the cache key will be checked and the `cache-hit` output will be set
74+
# but the cache itself won't be restored
75+
# default: "false"
76+
lookup-only: ""
77+
7278
# Specifies what to use as the backend providing cache
7379
# Can be set to either "github" or "buildjet"
7480
# default: "github"

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ inputs:
4040
description: "Determines which provider to use for caching. Options are github or buildjet, defaults to github."
4141
required: false
4242
default: "github"
43+
lookup-only:
44+
description: "Check if a cache entry exists without downloading the cache"
45+
required: false
46+
default: "false"
4347
outputs:
4448
cache-hit:
4549
description: "A boolean value that indicates an exact match was found."

dist/restore/index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -77876,20 +77876,21 @@ async function run() {
7787677876
if (cacheOnFailure !== "true") {
7787777877
cacheOnFailure = "false";
7787877878
}
77879+
var lookupOnly = lib_core.getInput("lookup-only").toLowerCase() === "true";
7787977880
lib_core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure);
7788077881
lib_core.exportVariable("CARGO_INCREMENTAL", 0);
7788177882
const config = await CacheConfig.new();
7788277883
config.printInfo(cacheProvider);
7788377884
lib_core.info("");
77884-
lib_core.info(`... Restoring cache ...`);
77885+
lib_core.info(`... ${lookupOnly ? "Checking" : "Restoring"} cache ...`);
7788577886
const key = config.cacheKey;
7788677887
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
7788777888
// https://github.com/actions/toolkit/pull/1378
7788877889
// TODO: remove this once the underlying bug is fixed.
77889-
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey]);
77890+
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], { lookupOnly });
7789077891
if (restoreKey) {
7789177892
const match = restoreKey === key;
77892-
lib_core.info(`Restored from cache key "${restoreKey}" full match: ${match}.`);
77893+
lib_core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);
7789377894
if (!match) {
7789477895
// pre-clean the target directory on cache mismatch
7789577896
for (const workspace of config.workspaces) {

src/restore.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,33 @@ async function run() {
2424
if (cacheOnFailure !== "true") {
2525
cacheOnFailure = "false";
2626
}
27+
var lookupOnly = core.getInput("lookup-only").toLowerCase() === "true";
28+
2729
core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure);
2830
core.exportVariable("CARGO_INCREMENTAL", 0);
2931

3032
const config = await CacheConfig.new();
3133
config.printInfo(cacheProvider);
3234
core.info("");
3335

34-
core.info(`... Restoring cache ...`);
36+
core.info(`... ${lookupOnly ? "Checking" : "Restoring"} cache ...`);
3537
const key = config.cacheKey;
3638
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
3739
// https://github.com/actions/toolkit/pull/1378
3840
// TODO: remove this once the underlying bug is fixed.
39-
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey]);
41+
const restoreKey = await cacheProvider.cache.restoreCache(
42+
config.cachePaths.slice(),
43+
key,
44+
[config.restoreKey],
45+
{ lookupOnly }
46+
);
4047
if (restoreKey) {
4148
const match = restoreKey === key;
42-
core.info(`Restored from cache key "${restoreKey}" full match: ${match}.`);
49+
core.info(
50+
`${
51+
lookupOnly ? "Found" : "Restored from"
52+
} cache key "${restoreKey}" full match: ${match}.`
53+
);
4354
if (!match) {
4455
// pre-clean the target directory on cache mismatch
4556
for (const workspace of config.workspaces) {

0 commit comments

Comments
 (0)