allow saving cache to be optional (#131)
This commit is contained in:
parent
00e306f4a9
commit
be4ac32ff6
4 changed files with 35 additions and 0 deletions
24
README.md
24
README.md
|
|
@ -83,6 +83,30 @@ Default `""`.
|
|||
```
|
||||
</details>
|
||||
|
||||
### `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`.
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
#### 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' }}
|
||||
```
|
||||
</details>
|
||||
|
||||
### `disk-cache`
|
||||
|
||||
Enable [`disk_cache`][2] and store it on GitHub based on contents of `BUILD` files.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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`],
|
||||
|
|
|
|||
5
post.js
5
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue