Skip to content

Commit

Permalink
Add use-cache option
Browse files Browse the repository at this point in the history
This option can be used to disable preservation of the global Zig cache
directory across runs. This option is only applicable in rare cases, and
should not be used by the majority of users.
  • Loading branch information
mlugg committed Jun 11, 2024
1 parent 9cfad99 commit 586e886
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ be https://ziglang.org/download to avoid the official website being hit with lar
If you've experienced issues with a default mirror, please open an issue, and I will communicate with the
mirror's owner or remove it from the list.

If necessary, the caching of the global Zig cache directory can be disabled by setting the option
`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.

[mach-nominated]: https://machengine.org/about/nominated-zig/

## Details
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ inputs:
description: 'Override of Zig download mirror to use, e.g. "https://pkg.machengine.org/zig".'
required: false
default: ''
use-cache:
description: 'Whether to cache the global Zig cache directory.'
required: true
default: true
runs:
using: 'node20'
main: 'main.js'
Expand Down
6 changes: 5 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ async function main() {
}

core.addPath(zig_dir);
await cache.restoreCache([await common.getZigCachePath()], await common.getCachePrefix());

// Direct Zig to use the global cache as every local cache, so that we get maximum benefit from the caching above.
core.exportVariable('ZIG_LOCAL_CACHE_DIR', await common.getZigCachePath());

if (core.getBooleanInput('use-cache')) {
await cache.restoreCache([await common.getZigCachePath()], await common.getCachePrefix());
}
} catch (err) {
core.setFailed(err.message);
}
Expand Down
8 changes: 5 additions & 3 deletions post.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ const common = require('./common');

async function main() {
try {
const prefix = await common.getCachePrefix();
const name = prefix + github.context.runId;
await cache.saveCache([await common.getZigCachePath()], name);
if (core.getBooleanInput('use-cache')) {
const prefix = await common.getCachePrefix();
const name = prefix + github.context.runId;
await cache.saveCache([await common.getZigCachePath()], name);
}
} catch (err) {
core.setFailed(err.message);
}
Expand Down

0 comments on commit 586e886

Please sign in to comment.