Skip to content
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1d20106
Add disk cache garbage collection
calebzulawski Feb 28, 2025
a751db8
Compile dist/
calebzulawski Feb 28, 2025
d50f6d9
Account for cache misses in garbage collection
calebzulawski Mar 6, 2025
d635e2d
Compile dist/
calebzulawski Mar 6, 2025
efb2b60
Use a unique disk cache key for each workflow run
calebzulawski Mar 7, 2025
86393ef
Compile dist/
calebzulawski Mar 7, 2025
8e4151a
Use environment variables due to missing github.context.runAttempt
calebzulawski Mar 10, 2025
f249a39
Compile dist/
calebzulawski Mar 10, 2025
a4972f6
Make cache prefix configurable, and garbage collect repository cache
calebzulawski Mar 12, 2025
56b726d
Improve GC logic when large files are present
calebzulawski Mar 12, 2025
7c87da9
Compile dist/
calebzulawski Mar 12, 2025
0cbf109
Improve diagnostics
calebzulawski Mar 12, 2025
9a66b7e
Compile dist/
calebzulawski Mar 12, 2025
86c14b1
Fix cache paths
calebzulawski Mar 12, 2025
a1980df
Compile dist/
calebzulawski Mar 12, 2025
ce74503
Change strings to booleans
calebzulawski Mar 13, 2025
b0761d7
Compile dist/
calebzulawski Mar 13, 2025
01c4b28
Add cache-prefix to docs
calebzulawski Mar 13, 2025
56224ed
Fix cache restore logic
calebzulawski Mar 13, 2025
693d902
Compile dist/
calebzulawski Mar 13, 2025
7dac383
Remove unused variable from config
calebzulawski Mar 13, 2025
402a7d4
Ensure parent directory exists before writing cache hash file
calebzulawski Mar 13, 2025
6f5d038
Compile dist/
calebzulawski Mar 13, 2025
677d2d8
Rename inputs to sort better. Emit errors when upgrading from old int…
calebzulawski Mar 17, 2025
3938147
Compile dist/
calebzulawski Mar 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 32 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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]

Expand Down
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ inputs:
description: Extra contents to write to user .bazelrc
required: false
default: ""
cache-prefix:
description: Key prefix for all caches
Copy link
Member

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.

Copy link
Contributor Author

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

required: false
default: ${{ github.job }}-${{ runner.os }}
cache-version:
description: Version of all caches
required: false
Expand All @@ -21,6 +25,10 @@ inputs:
description: Cache actions outputs based on BUILD
required: false
default: "false"
max-disk-cache-size:
description: Maximum disk cache size, in GB
required: false
default: 5
external-cache:
description: Cache external 10MB+ repositories based on MODULE.bazel/WORKSPACE
required: false
Expand All @@ -41,6 +49,10 @@ inputs:
description: Cache repositories based on MODULE.bazel/WORKSPACE
required: false
default: "false"
max-repository-cache-size:
description: Maximum repository cache size, in GB
required: false
default: 1
token:
description: GitHub token to query Bazelisk releases
required: false
Expand Down
34 changes: 9 additions & 25 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we can drop this input and move it to cache-prefix instead.

Copy link
Contributor Author

@calebzulawski calebzulawski Mar 17, 2025

Choose a reason for hiding this comment

The 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 1 in it?

const externalCacheConfig = yaml.parse(core.getInput('external-cache'))
const moduleRoot = core.getInput('module-root')
Expand Down Expand Up @@ -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') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a core.warning when disk-cache is not a boolean. This would indicate that an old interface for using disk-cache with a cache name is being used, and we can add a link to the release page with upgrade instructions (https://github.com/bazel-contrib/setup-bazel/releases/tag/0.15.0)

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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a core.warning when repository-cache is not a boolean. This would indicate that an old interface for using repository-cache with a path to a file is being used, and we can add a link to the release page with upgrade instructions (https://github.com/bazel-contrib/setup-bazel/releases/tag/0.15.0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up adding a core.error, because ultimately the action will fail

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')
Expand Down Expand Up @@ -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,
Expand All @@ -159,7 +143,7 @@ module.exports = {
},
repositoryCache: {
enabled: repositoryCacheEnabled,
files: repositoryCacheFiles,
maxSize: maxRepositoryCacheSize,
name: 'repository',
paths: [bazelRepository]
},
Expand Down
Loading