diff --git a/README.md b/README.md index c6ad114..1759a93 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,30 @@ Default `""`. ``` +### `cache-save` + +Whether to save caches at the end of the workflow. + +Set to `false` for pull requests to allow cache restoration without saving, +which prevents PRs from polluting the cache while still benefiting from it. + +Default `true`. + +
+ Examples + + #### Disable cache saving on pull requests + + ```yaml + - uses: bazel-contrib/setup-bazel@0.16.0 + with: + bazelisk-cache: true + disk-cache: ${{ github.workflow }} + repository-cache: true + cache-save: ${{ github.event_name != 'pull_request' }} + ``` +
+ ### `disk-cache` Enable [`disk_cache`][2] and store it on GitHub based on contents of `BUILD` files. diff --git a/action.yml b/action.yml index e047d11..5544e59 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,10 @@ inputs: description: Extra contents to write to user .bazelrc required: false default: "" + cache-save: + description: Whether to save caches. Set to false for pull requests to allow restores but prevent saves. + required: false + default: "true" cache-version: description: Version of all caches required: false diff --git a/config.js b/config.js index d6aec2e..de6ccee 100644 --- a/config.js +++ b/config.js @@ -5,6 +5,7 @@ const core = require('@actions/core') const github = require('@actions/github') const bazeliskVersion = core.getInput('bazelisk-version') +const cacheSave = core.getBooleanInput('cache-save') const cacheVersion = core.getInput('cache-version') const moduleRoot = core.getInput('module-root') @@ -137,6 +138,7 @@ core.exportVariable('BAZELISK_GITHUB_TOKEN', token) module.exports = { baseCacheKey, + cacheSave, bazeliskCache: { enabled: core.getBooleanInput('bazelisk-cache'), files: [`${moduleRoot}/.bazelversion`], diff --git a/post.js b/post.js index 85b2dd7..7c639e7 100644 --- a/post.js +++ b/post.js @@ -13,6 +13,11 @@ async function run() { } async function saveCaches() { + if (!config.cacheSave) { + core.info('Cache saving is disabled (cache-save: false)') + return + } + await saveCache(config.bazeliskCache) await saveCache(config.diskCache) await saveCache(config.repositoryCache)