-
-
Notifications
You must be signed in to change notification settings - Fork 19
Disk cache garbage collection #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 23 commits
1d20106
a751db8
d50f6d9
d635e2d
efb2b60
86393ef
8e4151a
f249a39
a4972f6
56b726d
7c87da9
0cbf109
9a66b7e
86c14b1
a1980df
ce74503
b0761d7
01c4b28
56224ed
693d902
7dac383
402a7d4
6f5d038
677d2d8
3938147
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,33 +83,44 @@ Default `""`. | |
| ``` | ||
| </details> | ||
|
|
||
| ### `disk-cache` | ||
|
|
||
| Enable [`disk_cache`][2] and store it on GitHub based on contents of `BUILD` files. | ||
| ### `cache-prefix` | ||
|
|
||
| You can also pass a string to use as a cache key to separate caches from different workflows. | ||
| Specify a prefix used for all caches. | ||
|
|
||
| Default `false`. | ||
| Default `${{ github.job }}-${{ runner.os }}` | ||
|
|
||
| <details> | ||
| <summary>Examples</summary> | ||
|
|
||
| #### Share a single disk cache | ||
| #### Using a job matrix | ||
|
|
||
| ```yaml | ||
| - uses: bazel-contrib/[email protected] | ||
| with: | ||
| disk-cache: true | ||
| my-job: | ||
| strategy: | ||
| matrix: | ||
| os: [ubuntu-22.04, ubuntu-24.04] | ||
| mode: [dbg, opt] | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: bazel-contrib/[email protected] | ||
| with: | ||
| cache-prefix: ${{ matrix.job }}-${{ matrix.os }}-${{ matrix.mode }} | ||
| ``` | ||
| </details> | ||
|
|
||
| #### Separate disk caches between workflows | ||
| ### `disk-cache` | ||
|
|
||
| ```yaml | ||
| - uses: bazel-contrib/[email protected] | ||
| with: | ||
| disk-cache: ${{ github.workflow }}} | ||
| ``` | ||
| </details> | ||
| Enable [`disk_cache`][2] and store it on GitHub. | ||
|
|
||
| Default `false`. | ||
|
|
||
| ### `max-disk-cache-size` | ||
|
|
||
| The maximum size, in GB, allowed for the disk cache. | ||
| Exceeding this size results in garbage collection. | ||
|
|
||
| Default `5`. | ||
|
|
||
| ### `external-cache` | ||
|
|
||
|
|
@@ -206,31 +217,16 @@ Default is one of the following: | |
|
|
||
| ### `repository-cache` | ||
|
|
||
| Enable [`repository_cache`][3] and store it on GitHub based on contents of `MODULE.bazel` and `WORKSPACE` files. | ||
|
|
||
| You can also pass a file (or list of files) which contents are used to calculate cache key. | ||
| Enable [`repository_cache`][3] and store it on GitHub. | ||
|
|
||
| Default `false`. | ||
|
|
||
| <details> | ||
| <summary>Examples</summary> | ||
| ### `max-repository-cache-size` | ||
|
|
||
| #### Store a single repository cache | ||
| The maximum size, in GB, allowed for the repository cache. | ||
| Exceeding this size results in garbage collection. | ||
|
|
||
| ```yaml | ||
| - uses: bazel-contrib/[email protected] | ||
| with: | ||
| repository-cache: true | ||
| ``` | ||
|
|
||
| #### Store a repository cache from a custom location | ||
|
|
||
| ```yaml | ||
| - uses: bazel-contrib/[email protected] | ||
| with: | ||
| repository-cache: examples/gem/WORKSPACE | ||
| ``` | ||
| </details> | ||
| Default `1`. | ||
|
|
||
| ## Migrating from [`bazelbuild/setup-bazelisk`][6] | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ const core = require('@actions/core') | |
| const github = require('@actions/github') | ||
|
|
||
| const bazeliskVersion = core.getInput('bazelisk-version') | ||
| const cachePrefix = core.getInput('cache-prefix') | ||
| const cacheVersion = core.getInput('cache-version') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose we can drop this input and move it to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the purpose of this input? If the prefix is user-configurable, is it necessary at all? Should the default still have |
||
| const externalCacheConfig = yaml.parse(core.getInput('external-cache')) | ||
| const moduleRoot = core.getInput('module-root') | ||
|
|
@@ -41,32 +42,19 @@ switch (platform) { | |
| break | ||
| } | ||
|
|
||
| const baseCacheKey = `setup-bazel-${cacheVersion}-${platform}` | ||
| const baseCacheKey = `setup-bazel-${cacheVersion}-${cachePrefix}` | ||
| const bazelrc = core.getMultilineInput('bazelrc') | ||
|
|
||
| const diskCacheConfig = core.getInput('disk-cache') | ||
| const diskCacheEnabled = diskCacheConfig !== 'false' | ||
| let diskCacheName = 'disk' | ||
| const diskCacheEnabled = core.getBooleanInput('disk-cache') | ||
| const maxDiskCacheSize = core.getInput('max-disk-cache-size') | ||
| if (diskCacheEnabled) { | ||
| bazelrc.push(`common --disk_cache=${bazelDisk}`) | ||
| if (diskCacheName !== 'true') { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a |
||
| diskCacheName = `${diskCacheName}-${diskCacheConfig}` | ||
| } | ||
| } | ||
|
|
||
| const repositoryCacheConfig = core.getInput('repository-cache') | ||
| const repositoryCacheEnabled = repositoryCacheConfig !== 'false' | ||
| let repositoryCacheFiles = [ | ||
| `${moduleRoot}/MODULE.bazel`, | ||
| `${moduleRoot}/WORKSPACE.bazel`, | ||
| `${moduleRoot}/WORKSPACE.bzlmod`, | ||
| `${moduleRoot}/WORKSPACE` | ||
| ] | ||
| const repositoryCacheEnabled = core.getBooleanInput('repository-cache') | ||
|
||
| const maxRepositoryCacheSize = core.getInput('max-repository-cache-size') | ||
| if (repositoryCacheEnabled) { | ||
| bazelrc.push(`common --repository_cache=${bazelRepository}`) | ||
| if (repositoryCacheConfig !== 'true') { | ||
| repositoryCacheFiles = Array(repositoryCacheConfig).flat() | ||
| } | ||
| } | ||
|
|
||
| const googleCredentials = core.getInput('google-credentials') | ||
|
|
@@ -139,12 +127,8 @@ module.exports = { | |
| bazelrc, | ||
| diskCache: { | ||
| enabled: diskCacheEnabled, | ||
| files: [ | ||
| ...repositoryCacheFiles, | ||
| `${moduleRoot}/**/BUILD.bazel`, | ||
| `${moduleRoot}/**/BUILD` | ||
| ], | ||
| name: diskCacheName, | ||
| maxSize: maxDiskCacheSize, | ||
| name: 'disk', | ||
| paths: [bazelDisk] | ||
| }, | ||
| externalCache, | ||
|
|
@@ -159,7 +143,7 @@ module.exports = { | |
| }, | ||
| repositoryCache: { | ||
| enabled: repositoryCacheEnabled, | ||
| files: repositoryCacheFiles, | ||
| maxSize: maxRepositoryCacheSize, | ||
| name: 'repository', | ||
| paths: [bazelRepository] | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's clarify it's only used for disk/repository cache, not bazlisk/external.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way I implemented it, all of the caches use this prefix, including bazelisk and external. This resolves #73