Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ optional.
- `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`.
- `cache-extra-identifier` - Additional identifier to include in cache key for matrix jobs or custom cache separation.
- `channel` - Toolchain specification/channel to explicitly install.
- `components` - Comma-separated list of additional components to install.
- `inherit-toolchain` - Inherit all toolchain settings from the `rust-toolchain.toml` file. Defaults
Expand Down Expand Up @@ -119,6 +120,19 @@ be changed with the `cache-target` input, which defaults to `debug`.
cache-target: release
```

For matrix jobs where the cache key would otherwise be identical, you can use `cache-extra-identifier` to ensure unique cache keys:

```yaml
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
rust: [stable, beta]
steps:
- uses: moonrepo/setup-rust@v1
with:
cache-extra-identifier: ${{ matrix.os }}-${{ matrix.rust }}
```

The following optimizations and considerations are taken into account when caching:

- `~/.cargo`
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ inputs:
cache-target:
description: 'Name of the target profile to cache.'
default: 'debug'
cache-extra-identifier:
description: 'Additional identifier to include in cache key for matrix jobs or custom cache separation.'
channel:
description: 'Toolchain specification/channel to explicitly install.'
components:
Expand Down
7 changes: 7 additions & 0 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ export async function getPrimaryCacheKey() {
core.debug(`Hashing GITHUB_JOB = ${job}`);
hasher.update(job);
}

const extraIdentifier = core.getInput('cache-extra-identifier');

if (extraIdentifier) {
core.debug(`Hashing cache-extra-identifier = ${extraIdentifier}`);
hasher.update(extraIdentifier);
}
}

return `${getCachePrefixes()[0]}-${hasher.digest('hex')}`;
Expand Down