From 8a603fb6f392de406911ffe334e36195299abbda Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Fri, 17 Nov 2023 10:12:15 -0800 Subject: [PATCH] Polish. --- CHANGELOG.md | 2 ++ README.md | 19 +++++++++++++++++++ action.yml | 3 +-- src/cache.ts | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfec579..44aed25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # 1.1.0 +- Added a `cache-base` input. When provided, will only save cache on this branch/ref, but will + restore cache on all branches/refs. - Updated dependencies. # 1.0.3 diff --git a/README.md b/README.md index 696917e..682a841 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ optional. - `bins` - Comma-separated list of global binaries to install into Cargo. - `cache` - Toggle caching of directories. Defaults to `true`. +- `cache-base` - Base branch/ref to save a warmup cache on. Other branches/refs will restore from + this base. - `cache-target` - Name of the target profile to cache. Defaults to `debug`. - `channel` - Toolchain specification/channel to explicitly install. - `components` - Comma-separated list of additional components to install. @@ -135,6 +137,23 @@ The following optimizations and considerations are taken into account when cachi > The following sources are hashed for the generated cache key: `$GITHUB_JOB`, `Cargo.lock`, Rust > version, Rust commit hash, and OS. +### Warmup strategy + +Another strategy that we support is called a warmup cache, where a base branch/ref is used to +generate and save the cache (like master), and all other branches/refs will _only_ restore this +cache (and not save). + +This can be enabled with the `cache-base` input, which requires a branch/ref name. This input also +supports regex. + +```yaml +- uses: moonrepo/setup-rust@v1 + with: + cache-base: master + # With regex + cache-base: (master|main|develop) +``` + ## Compared to ### `actions-rs/*` diff --git a/action.yml b/action.yml index 2c0ba87..5055283 100644 --- a/action.yml +++ b/action.yml @@ -11,8 +11,7 @@ inputs: default: true cache-base: description: - 'Base branch or ref to save a warmup cache. Other branches and refs will restore from this - base.' + 'Base branch/ref to save a warmup cache on. Other branches/refs will restore from this base.' cache-target: description: 'Name of the target profile to cache.' default: 'debug' diff --git a/src/cache.ts b/src/cache.ts index 4856440..8a2819d 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -49,6 +49,7 @@ export async function getPrimaryCacheKey() { if (core.getInput('cache-base')) { core.debug('Using warmup strategy, not hashing Cargo.lock, GITHUB_WORKFLOW, or GITHUB_JOB'); + hasher.update('warmup'); } // When warming up, these add far too much granularity to the cache key