setup-bazel/README.md

264 lines
5.8 KiB
Markdown
Raw Normal View History

2023-01-04 16:31:00 -08:00
# setup-bazel
This action allows to properly configure Bazelisk and Bazel on all operating systems
2023-01-04 16:31:00 -08:00
and provides an advanced fine-grained caching to improve workflows performance.
2024-02-26 10:48:45 -08:00
## Usage
```yaml
2025-05-27 15:16:11 +00:00
- uses: bazel-contrib/setup-bazel@0.15.0
2024-02-26 10:48:45 -08:00
with:
# Avoid downloading Bazel every time.
bazelisk-cache: true
# Store build cache per workflow.
disk-cache: ${{ github.workflow }}
# Share repository cache between workflows.
repository-cache: true
```
2023-01-04 16:31:00 -08:00
## Inputs
### `bazelisk-cache`
Cache [`bazelisk`][1] downloads based on contents of a `.bazelversion` file.
Default `false`.
### `bazelisk-version`
[`bazelisk`][1] version to download and use.
Supports semver specification and ranges.
Leave empty to use [pre-installed Bazelisk][8].
Default `""`.
2024-02-26 10:48:45 -08:00
<details>
<summary>Examples</summary>
#### Install Bazelisk 1.x
```yaml
2025-05-27 15:16:11 +00:00
- uses: bazel-contrib/setup-bazel@0.15.0
2024-02-26 10:48:45 -08:00
with:
bazelisk-version: 1.x
```
#### Install exact Bazelisk version
```yaml
2025-05-27 15:16:11 +00:00
- uses: bazel-contrib/setup-bazel@0.15.0
2024-02-26 10:48:45 -08:00
with:
bazelisk-version: 1.19.0
```
</details>
2023-01-04 16:31:00 -08:00
### `bazelrc`
Extra contents to write to a user's [`bazelrc`][4] file.
2024-02-26 10:48:45 -08:00
You can use multiline YAML strings.
2023-01-04 16:31:00 -08:00
Default `""`.
2024-02-26 10:48:45 -08:00
<details>
<summary>Examples</summary>
#### Enable Bzlmod
```yaml
2025-05-27 15:16:11 +00:00
- uses: bazel-contrib/setup-bazel@0.15.0
2024-02-26 10:48:45 -08:00
with:
bazelrc: common --enable_bzlmod
```
#### Add colors and timestamps
```yaml
2025-05-27 15:16:11 +00:00
- uses: bazel-contrib/setup-bazel@0.15.0
2024-02-26 10:48:45 -08:00
with:
bazelrc: |
build --color=yes
build --show_timestamps
```
</details>
2023-01-04 16:31:00 -08:00
### `disk-cache`
Enable [`disk_cache`][2] and store it on GitHub based on contents of `BUILD` files.
You can also pass a string to use as a cache key to separate caches from different workflows.
Default `false`.
2024-02-26 10:48:45 -08:00
<details>
<summary>Examples</summary>
#### Share a single disk cache
```yaml
2025-05-27 15:16:11 +00:00
- uses: bazel-contrib/setup-bazel@0.15.0
2024-02-26 10:48:45 -08:00
with:
disk-cache: true
```
#### Separate disk caches between workflows
```yaml
2025-05-27 15:16:11 +00:00
- uses: bazel-contrib/setup-bazel@0.15.0
2024-02-26 10:48:45 -08:00
with:
disk-cache: ${{ github.workflow }}}
```
</details>
2023-01-04 16:31:00 -08:00
### `external-cache`
2024-02-26 10:57:57 -08:00
Cache `external/` repositories based on contents of `MODULE.bazel` and `WORKSPACE` files.
2023-01-04 16:31:00 -08:00
Only repositories exceeding 10MB are being cached.
2024-02-26 10:48:45 -08:00
Each repository is stored in a separate cache.
2023-01-04 16:31:00 -08:00
2024-02-26 10:48:45 -08:00
You can also pass a `manifest` object where key is the name of the external repository
and value is a file (or list of files) which contents are used to calculate cache key.
If the value is `false`, the external repository won't be cached.
2023-01-04 16:31:00 -08:00
Default `false`.
2024-02-26 10:48:45 -08:00
<details>
<summary>Examples</summary>
2023-01-04 16:31:00 -08:00
2024-02-26 10:48:45 -08:00
#### Enable external repositories caches
2023-01-04 16:31:00 -08:00
2024-02-26 10:48:45 -08:00
```yaml
2025-05-27 15:16:11 +00:00
- uses: bazel-contrib/setup-bazel@0.15.0
2024-02-26 10:48:45 -08:00
with:
external-cache: true
```
2023-01-04 16:31:00 -08:00
2024-02-26 10:48:45 -08:00
#### Cache NPM repositories based on `package-lock.json` contents
2023-01-04 16:31:00 -08:00
2024-02-26 10:48:45 -08:00
```yaml
2025-05-27 15:16:11 +00:00
- uses: bazel-contrib/setup-bazel@0.15.0
2024-02-26 10:48:45 -08:00
with:
external-cache: |
manifest:
npm: package-lock.json
```
2024-02-26 10:48:45 -08:00
#### Do not cache Ruby on Windows
2024-02-26 10:48:45 -08:00
```yaml
2025-05-27 15:16:11 +00:00
- uses: bazel-contrib/setup-bazel@0.15.0
2024-02-26 10:48:45 -08:00
with:
external-cache: |
manifest:
ruby: ${{ runner.os == 'Windows' && 'false' || 'true' }}
```
</details>
2023-01-04 16:31:00 -08:00
2024-02-26 10:48:45 -08:00
### `google-credentials`
2023-01-04 16:31:00 -08:00
2024-02-26 10:48:45 -08:00
Google Cloud account key to use for [remote caching authentication][9].
2023-01-04 16:31:00 -08:00
2024-02-26 10:48:45 -08:00
Default `""`.
2023-01-04 16:31:00 -08:00
2024-02-26 10:48:45 -08:00
<details>
<summary>Examples</summary>
2023-01-04 16:31:00 -08:00
2024-02-26 10:48:45 -08:00
#### Authenticate via key
2023-01-04 16:31:00 -08:00
2024-02-26 10:48:45 -08:00
```yaml
2025-05-27 15:16:11 +00:00
- uses: bazel-contrib/setup-bazel@0.15.0
2024-02-26 10:48:45 -08:00
with:
google-credentials: ${{ secrets.GOOGLE_CLOUD_KEY }}
```
</details>
2023-01-04 16:31:00 -08:00
### `module-root`
Bazel module root directory, where `MODULE.bazel` and `WORKSPACE` is found.
Change this value to the module root if it's not the repository root.
Default `"."`.
2024-10-31 07:12:35 -07:00
### `output-base`
Change Bazel output base directory.
You might want to change it when running on self-hosted runners with a custom directory layout.
Default is one of the following:
- `$HOME/.bazel` on Linux and macOS
- `D:/_bazel` on Windows
<details>
<summary>Examples</summary>
#### Use `C` drive letter
```yaml
2025-05-27 15:16:11 +00:00
- uses: bazel-contrib/setup-bazel@0.15.0
2024-10-31 07:12:35 -07:00
with:
output-base: C:/_bazel
```
</details>
2023-01-04 16:31:00 -08:00
2024-02-26 10:48:45 -08:00
### `repository-cache`
2024-02-26 10:57:57 -08:00
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.
2024-02-26 10:48:45 -08:00
Default `false`.
<details>
<summary>Examples</summary>
#### Store a single repository cache
```yaml
2025-05-27 15:16:11 +00:00
- uses: bazel-contrib/setup-bazel@0.15.0
with:
repository-cache: true
```
#### Store a repository cache from a custom location
```yaml
2025-05-27 15:16:11 +00:00
- uses: bazel-contrib/setup-bazel@0.15.0
with:
repository-cache: examples/gem/WORKSPACE
```
</details>
## Migrating from [`bazelbuild/setup-bazelisk`][6]
2024-03-11 08:25:23 -07:00
You can simply replace `bazelbuild/setup-bazelisk` action with `bazel-contrib/setup-bazel`.
However, if you used a `bazel-version` input before, you will need to remove it in favor
[other ways to specify Bazel version][7].
2024-02-26 10:57:57 -08:00
## Development
To build action, run the following command:
```sh
$ npm run build
```
2024-04-12 12:15:08 -05:00
## Release
Use [Release][10] workflow to cut a new release.
2023-01-04 16:31:00 -08:00
[1]: https://github.com/bazelbuild/bazelisk
[2]: https://bazel.build/remote/caching#disk-cache
[3]: https://docs-staging.bazel.build/2338/versions/main/guide.html#the-repository-cache
[4]: https://bazel.build/run/bazelrc
[5]: https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
[6]: https://github.com/bazelbuild/setup-bazelisk
[7]: https://github.com/bazelbuild/bazelisk/blob/master/README.md#how-does-bazelisk-know-which-bazel-version-to-run
2024-02-26 10:48:45 -08:00
[8]: https://github.com/actions/runner-images/pull/490
2024-03-01 11:15:47 -08:00
[9]: https://bazel.build/reference/command-line-reference#flag--google_credentials
2024-04-12 12:15:08 -05:00
[10]: https://github.com/bazel-contrib/setup-bazel/actions/workflows/release.yml