From 586e886fb4aaf6d3c317eda218a0ebdf4387243a Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 11 Jun 2024 23:31:54 +0100 Subject: [PATCH] Add `use-cache` option 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. --- README.md | 4 ++++ action.yml | 4 ++++ main.js | 6 +++++- post.js | 8 +++++--- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 071d9df..d88a858 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index fb012ba..40f8376 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/main.js b/main.js index 160badd..de21add 100644 --- a/main.js +++ b/main.js @@ -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); } diff --git a/post.js b/post.js index bf3567e..96bcab8 100644 --- a/post.js +++ b/post.js @@ -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); }