Improve cache key.

This commit is contained in:
Miles Johnson 2023-11-17 10:16:47 -08:00
parent 8a603fb6f3
commit dfc6a0d9ae

View file

@ -47,12 +47,26 @@ export async function getPrimaryCacheKey() {
core.debug(`Hashing target profile = ${cacheTarget}`); core.debug(`Hashing target profile = ${cacheTarget}`);
hasher.update(cacheTarget); hasher.update(cacheTarget);
// When warming up, loosen the cache key to allow for more cache hits
if (core.getInput('cache-base')) { if (core.getInput('cache-base')) {
core.debug('Using warmup strategy, not hashing Cargo.lock, GITHUB_WORKFLOW, or GITHUB_JOB'); core.debug('Using warmup strategy, not hashing Cargo.lock, GITHUB_WORKFLOW, or GITHUB_JOB');
hasher.update('warmup'); hasher.update('warmup');
const baseRef = process.env.GITHUB_BASE_REF ?? '';
if (
baseRef === 'master' ||
baseRef === 'main' ||
baseRef === 'trunk' ||
baseRef.startsWith('develop') ||
baseRef.startsWith('release')
) {
core.debug(`Hashing GITHUB_BASE_REF = ${baseRef}`);
hasher.update(baseRef);
}
} }
// When warming up, these add far too much granularity to the cache key // Otherwise, these add far too much granularity to the cache key
else { else {
const lockHash = await glob.hashFiles('Cargo.lock'); const lockHash = await glob.hashFiles('Cargo.lock');