mirror of
https://github.com/moonrepo/setup-rust.git
synced 2025-04-29 13:30:03 +00:00
Update api.
This commit is contained in:
parent
d87f327046
commit
d7d917b850
3 changed files with 32 additions and 20 deletions
|
@ -10,7 +10,9 @@ inputs:
|
||||||
description: 'Toggle caching of ~/.cargo/registry and /target/<cache-target> directories.'
|
description: 'Toggle caching of ~/.cargo/registry and /target/<cache-target> directories.'
|
||||||
default: true
|
default: true
|
||||||
cache-base:
|
cache-base:
|
||||||
description: 'Base branch or ref to save cache. Other branches and refs will restore from this base.'
|
description:
|
||||||
|
'Base branch or ref to save a warmup cache. Other branches and refs will restore from this
|
||||||
|
base.'
|
||||||
cache-target:
|
cache-target:
|
||||||
description: 'Name of the target profile to cache.'
|
description: 'Name of the target profile to cache.'
|
||||||
default: 'debug'
|
default: 'debug'
|
||||||
|
|
9
post.ts
9
post.ts
|
@ -3,7 +3,14 @@ import { saveCache } from './src/cargo';
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
await saveCache();
|
const base = core.getInput('cache-base');
|
||||||
|
|
||||||
|
// Only save the cache for the following 2 scenarios:
|
||||||
|
// - If not using the base warmup strategy.
|
||||||
|
// - If using the base warmup strategy, and the current ref matches.
|
||||||
|
if (!base || (base && !!(process.env.GITHUB_REF_NAME ?? '').match(base))) {
|
||||||
|
await saveCache();
|
||||||
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
core.setFailed((error as Error).message);
|
core.setFailed((error as Error).message);
|
||||||
}
|
}
|
||||||
|
|
39
src/cache.ts
39
src/cache.ts
|
@ -14,10 +14,6 @@ export function isCacheEnabled(): boolean {
|
||||||
return core.getBooleanInput('cache') && cache.isFeatureAvailable();
|
return core.getBooleanInput('cache') && cache.isFeatureAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isUsingBaseWarmupStrategy(): boolean {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getCacheTarget(): string {
|
export function getCacheTarget(): string {
|
||||||
return core.getInput('cache-target') || 'debug';
|
return core.getInput('cache-target') || 'debug';
|
||||||
}
|
}
|
||||||
|
@ -46,28 +42,35 @@ export async function getPrimaryCacheKey() {
|
||||||
core.debug(`Hashing Rust commit hash = ${RUST_HASH}`);
|
core.debug(`Hashing Rust commit hash = ${RUST_HASH}`);
|
||||||
hasher.update(RUST_HASH);
|
hasher.update(RUST_HASH);
|
||||||
|
|
||||||
const lockHash = await glob.hashFiles('Cargo.lock');
|
|
||||||
|
|
||||||
core.debug(`Hashing Cargo.lock = ${lockHash}`);
|
|
||||||
hasher.update(lockHash);
|
|
||||||
|
|
||||||
const cacheTarget = getCacheTarget();
|
const cacheTarget = getCacheTarget();
|
||||||
|
|
||||||
core.debug(`Hashing target profile = ${cacheTarget}`);
|
core.debug(`Hashing target profile = ${cacheTarget}`);
|
||||||
hasher.update(cacheTarget);
|
hasher.update(cacheTarget);
|
||||||
|
|
||||||
const workflow = process.env.GITHUB_WORKFLOW;
|
if (core.getInput('cache-base')) {
|
||||||
|
core.debug('Using warmup strategy, not hashing Cargo.lock, GITHUB_WORKFLOW, or GITHUB_JOB');
|
||||||
if (workflow) {
|
|
||||||
core.debug(`Hashing GITHUB_WORKFLOW = ${workflow}`);
|
|
||||||
hasher.update(workflow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const job = process.env.GITHUB_JOB;
|
// When warming up, these add far too much granularity to the cache key
|
||||||
|
else {
|
||||||
|
const lockHash = await glob.hashFiles('Cargo.lock');
|
||||||
|
|
||||||
if (job) {
|
core.debug(`Hashing Cargo.lock = ${lockHash}`);
|
||||||
core.debug(`Hashing GITHUB_JOB = ${job}`);
|
hasher.update(lockHash);
|
||||||
hasher.update(job);
|
|
||||||
|
const workflow = process.env.GITHUB_WORKFLOW;
|
||||||
|
|
||||||
|
if (workflow) {
|
||||||
|
core.debug(`Hashing GITHUB_WORKFLOW = ${workflow}`);
|
||||||
|
hasher.update(workflow);
|
||||||
|
}
|
||||||
|
|
||||||
|
const job = process.env.GITHUB_JOB;
|
||||||
|
|
||||||
|
if (job) {
|
||||||
|
core.debug(`Hashing GITHUB_JOB = ${job}`);
|
||||||
|
hasher.update(job);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${getCachePrefixes()[0]}-${hasher.digest('hex')}`;
|
return `${getCachePrefixes()[0]}-${hasher.digest('hex')}`;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue