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
This commit is contained in:
mlugg
2025-03-10 16:12:40 +00:00
parent 153c8d5202
commit 806c1bbc96
3 changed files with 13 additions and 1 deletions
+6
View File
@@ -51,7 +51,13 @@ If necessary, the caching of the global Zig cache directory can be disabled by s
`use-cache: false`. Don't do this without reason: preserving the Zig cache will typically speed things up `use-cache: false`. Don't do this without reason: preserving the Zig cache will typically speed things up
and decrease the load on GitHub's runners. and decrease the load on GitHub's runners.
If you are using a [matrix strategy][matrix] for your workflow, you may need to populate the `cache-key` option
with all of your matrix variables to ensure that every job is correctly cached. Unfortunately, GitHub does not
provide any means for the Action to automatically distinguish jobs in a matrix. However, variables which select
the runner OS can be omitted from the `cache-key`, since the runner OS is included in the cache key by default.
[mach-nominated]: https://machengine.org/about/nominated-zig/ [mach-nominated]: https://machengine.org/about/nominated-zig/
[matrix]: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow
## Details ## Details
+4
View File
@@ -12,6 +12,10 @@ inputs:
description: 'Whether to cache the global Zig cache directory.' description: 'Whether to cache the global Zig cache directory.'
required: true required: true
default: true default: true
cache-key:
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.'
required: false
default: ''
runs: runs:
using: 'node20' using: 'node20'
main: 'main.js' main: 'main.js'
+3 -1
View File
@@ -135,7 +135,9 @@ async function getTarballExt() {
async function getCachePrefix() { async function getCachePrefix() {
const tarball_name = await getTarballName(); const tarball_name = await getTarballName();
const job_name = github.context.job.replaceAll(/[^\w]/g, "_"); const job_name = github.context.job.replaceAll(/[^\w]/g, "_");
return `setup-zig-cache-${job_name}-${tarball_name}-`; const user_key = core.getInput('cache-key');
return `setup-zig-cache-${job_name}-${tarball_name}-${user_key}-`;
} }
async function getZigCachePath() { async function getZigCachePath() {