Skip to content

Commit 806c1bb

Browse files
committed
Add option to customize cache key
This *shouldn't* be necessary, but the way matrix strategies work in Actions means we literally cannot automatically differentiate jobs in the same workflow with different matrix variable values. So, if the user is using a matrix to customize anything other than the OS, they'll need to specify this. Resolves: #18
1 parent 153c8d5 commit 806c1bb

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ If necessary, the caching of the global Zig cache directory can be disabled by s
5151
`use-cache: false`. Don't do this without reason: preserving the Zig cache will typically speed things up
5252
and decrease the load on GitHub's runners.
5353

54+
If you are using a [matrix strategy][matrix] for your workflow, you may need to populate the `cache-key` option
55+
with all of your matrix variables to ensure that every job is correctly cached. Unfortunately, GitHub does not
56+
provide any means for the Action to automatically distinguish jobs in a matrix. However, variables which select
57+
the runner OS can be omitted from the `cache-key`, since the runner OS is included in the cache key by default.
58+
5459
[mach-nominated]: https://machengine.org/about/nominated-zig/
60+
[matrix]: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow
5561

5662
## Details
5763

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ inputs:
1212
description: 'Whether to cache the global Zig cache directory.'
1313
required: true
1414
default: true
15+
cache-key:
16+
description: 'Additional cache key component to include when caching the global Zig cache directory. When using a matrix strategy, this should include the matrix variables to ensure all jobs are cached. Matrix variables which decide the OS can be omitted, since the OS is always included in the cache key.'
17+
required: false
18+
default: ''
1519
runs:
1620
using: 'node20'
1721
main: 'main.js'

common.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ async function getTarballExt() {
135135
async function getCachePrefix() {
136136
const tarball_name = await getTarballName();
137137
const job_name = github.context.job.replaceAll(/[^\w]/g, "_");
138-
return `setup-zig-cache-${job_name}-${tarball_name}-`;
138+
const user_key = core.getInput('cache-key');
139+
140+
return `setup-zig-cache-${job_name}-${tarball_name}-${user_key}-`;
139141
}
140142

141143
async function getZigCachePath() {

0 commit comments

Comments
 (0)