Skip to content

Commit

Permalink
Support bazelisk-version input
Browse files Browse the repository at this point in the history
Also adds instruction on how to migrate from bazelbuild/setup-bazelisk
  • Loading branch information
p0deje committed Feb 7, 2024
1 parent 1ee945b commit 14997dc
Show file tree
Hide file tree
Showing 10 changed files with 6,425 additions and 2,702 deletions.
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# setup-bazel

This action allows to properly configure Bazel on all supported operating systems
This action allows to properly configure Bazelisk and Bazel on all operating systems
and provides an advanced fine-grained caching to improve workflows performance.

## Inputs
Expand All @@ -11,6 +11,15 @@ 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 `""`.

### `bazelrc`

Extra contents to write to a user's [`bazelrc`][4] file.
Expand Down Expand Up @@ -49,6 +58,14 @@ Default `false`.
- uses: p0deje/setup-bazel@0.4.0
```
### Custom Bazelisk version
```yaml
- uses: p0deje/setup-bazel@0.4.0
with:
bazelisk-version: 1.19.0
```
### Additional `.bazelrc` options

```yaml
Expand Down Expand Up @@ -97,8 +114,18 @@ Default `false`.
ruby: ${{ matrix.os == 'windows' && 'false' || '.ruby-version' }}
```

## Migrating from [`bazelbuild/setup-bazelisk`][6]

You can simply replace `bazelbuild/setup-bazelisk` action with `p0deje/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].


[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
[8]: https://github.com/actions/runner-images/pull/490
16 changes: 12 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
name: Setup Bazel
description: Configure Bazel(isk) and its caches

inputs:
bazelisk-cache:
description: Caches Bazelisk downloads based on .bazelversion
required: false
default: false
default: "false"
bazelisk-version:
description: The Bazelisk version to download and use if necessary
default: ""
bazelrc:
description: Extra contents to write to user .bazelrc
required: false
default: ""
cache-version:
description: Version of all caches
required: false
default: 1
default: "1"
disk-cache:
description: Cache actions outputs based on BUILD
required: false
default: false
default: "false"
external-cache:
description: Cache external 10MB+ repositories based on WORKSPACE
required: false
Expand All @@ -28,7 +32,11 @@ inputs:
repository-cache:
description: Cache repositories based on WORKSPACE
required: false
default: false
default: "false"
token:
description: GitHub token to query Bazelisk releases
required: false
default: ${{ github.token }}

runs:
using: node16
Expand Down
8 changes: 7 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ const yaml = require('yaml')
const core = require('@actions/core')
const github = require('@actions/github')

const bazeliskVersion = core.getInput('bazelisk-version')
const cacheVersion = core.getInput('cache-version')
const externalCacheConfig = yaml.parse(core.getInput('external-cache'))

const homeDir = os.homedir()
const arch = os.arch()
const platform = os.platform()

let bazelDisk = core.toPosixPath(`${homeDir}/.cache/bazel-disk`)
Expand Down Expand Up @@ -108,6 +110,7 @@ module.exports = {
name: 'bazelisk',
paths: [core.toPosixPath(`${userCacheDir}/bazelisk`)]
},
bazeliskVersion,
bazelrc,
diskCache: {
enabled: diskCacheEnabled,
Expand All @@ -124,7 +127,10 @@ module.exports = {
bazelOutputBase: core.toPosixPath(bazelOutputBase),
bazelrc: bazelrcPaths
},
platform,
os: {
arch,
platform,
},
repositoryCache: {
enabled: repositoryCacheEnabled,
files: [
Expand Down
Loading

0 comments on commit 14997dc

Please sign in to comment.