Compare commits
139 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30962902d2 | ||
|
|
417f3387fe | ||
|
|
887da5f6b9 | ||
|
|
3217c4f420 | ||
|
|
18fd541ab1 | ||
|
|
e74b1abaf7 | ||
|
|
3af227a251 | ||
|
|
c9a2a71272 | ||
|
|
09d5e77e57 | ||
|
|
5a2f9a2f05 | ||
|
|
bb67c3ebd7 | ||
|
|
b6a8ab687e | ||
|
|
083175551c | ||
|
|
b607b8f591 | ||
|
|
be4ac32ff6 | ||
|
|
00e306f4a9 | ||
|
|
b26a6f0e11 | ||
|
|
dbfe7273a9 | ||
|
|
1dc7f4819d | ||
|
|
82d28f5023 | ||
|
|
1bf89734c9 | ||
|
|
e820d6a037 | ||
|
|
66d3c1cddb | ||
|
|
271e4c2614 | ||
|
|
43d7d5ceab | ||
|
|
905421c656 | ||
|
|
5528b8082a | ||
|
|
39aba44572 | ||
|
|
51f283a17f | ||
|
|
7594e1b588 | ||
|
|
1ff8ab47ae | ||
|
|
6fe279591f | ||
|
|
81ef0d9acc | ||
|
|
4432ac8a23 | ||
|
|
2fab424f7c | ||
|
|
798f81ecfc | ||
|
|
22f06fe4d3 | ||
|
|
812c6371ef | ||
|
|
f22529d52b | ||
|
|
b1c5ac5231 | ||
|
|
b02abd0245 | ||
|
|
ec193958e9 | ||
|
|
25ec8ddd82 | ||
|
|
54c9086be8 | ||
|
|
20a70d3f31 | ||
|
|
4d8cee1d8a | ||
|
|
3d67a4f0cf | ||
|
|
976e823acb | ||
|
|
4fd964a13a | ||
|
|
40aa0be72e | ||
|
|
f26390261c | ||
|
|
14421f585a | ||
|
|
9ccf8a2650 | ||
|
|
c46b5ab465 | ||
|
|
f3b2b002ba | ||
|
|
e8776f58fb | ||
|
|
e0e802d0ce | ||
|
|
98248079ae | ||
|
|
bb67a55494 | ||
|
|
663f88d97a | ||
|
|
bc949b7ed4 | ||
|
|
30f539412d | ||
|
|
768017f3c7 | ||
|
|
6cabfc01da | ||
|
|
529dbc2648 | ||
|
|
104a0a36a0 | ||
|
|
c50333a369 | ||
|
|
451432a104 | ||
|
|
465f1612ad | ||
|
|
438b351914 | ||
|
|
99f63cfeed | ||
|
|
bbf8fe8b21 | ||
|
|
0f9296f333 | ||
|
|
89b8ef0f1d | ||
|
|
fda5cfcc5a | ||
|
|
8d0361d6cf | ||
|
|
3e48ddd52f | ||
|
|
0acdc344dc | ||
|
|
f3f50ea679 | ||
|
|
2ebddb28d9 | ||
|
|
93a72482ba | ||
|
|
3736b3b360 | ||
|
|
b136f2f9d4 | ||
|
|
41b624e715 | ||
|
|
f02085cc85 | ||
|
|
90b3523338 | ||
|
|
e49447a08d | ||
|
|
5d804ff512 | ||
|
|
0d27eba2b7 | ||
|
|
735c9d1fec | ||
|
|
101c7f5cf1 | ||
|
|
a125380b35 | ||
|
|
d4889c5698 | ||
|
|
812d05bd7b | ||
|
|
121a042b5d | ||
|
|
330cba8289 | ||
|
|
0fa4d31c00 | ||
|
|
e403ad5071 | ||
|
|
a948e3e824 | ||
|
|
a70df706fa | ||
|
|
363eb36ada | ||
|
|
f92f4331c7 | ||
|
|
c4b6956617 | ||
|
|
57947c1f02 | ||
|
|
06441bbdcd | ||
|
|
67f0a68f0e | ||
|
|
78f3ff98e3 | ||
|
|
155526ac0d | ||
|
|
6e5145c6a9 | ||
|
|
9676c3194c | ||
|
|
f5feac6e9d | ||
|
|
7d9487bea5 | ||
|
|
c776e115ed | ||
|
|
10af16b874 | ||
|
|
b388b84bb6 | ||
|
|
c033bc050f | ||
|
|
1cc0c15a80 | ||
|
|
2e3586828e | ||
|
|
8b1f4bfa4d | ||
|
|
b7383df9e2 | ||
|
|
c423f000c1 | ||
|
|
6632e95245 | ||
|
|
ef5b98eedd | ||
|
|
abf706cba9 | ||
|
|
5058960dd0 | ||
|
|
527d41d462 | ||
|
|
2eb83dc753 | ||
|
|
c7b4d0412f | ||
|
|
1428e4eb46 | ||
|
|
fcc0a6a0df | ||
|
|
8b3d6f9169 | ||
|
|
299d048546 | ||
|
|
0565e39cc0 | ||
|
|
8b62d10a25 | ||
|
|
42a3e0dfad | ||
|
|
14997dcb06 | ||
|
|
1ee945be88 | ||
|
|
e2ceb8f4c3 | ||
|
|
fb0c8c5285 |
17 changed files with 125316 additions and 104704 deletions
25
.github/workflows/ci.yml
vendored
Normal file
25
.github/workflows/ci.yml
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
name: CI
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
setup-bazel:
|
||||||
|
runs-on: ${{ matrix.os }}-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os:
|
||||||
|
- macos
|
||||||
|
- ubuntu
|
||||||
|
- windows
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: ./
|
||||||
|
- if: failure() && runner.debug == '1'
|
||||||
|
uses: mxschmitt/action-tmate@v3
|
||||||
37
.github/workflows/release.yml
vendored
Normal file
37
.github/workflows/release.yml
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
name: Release
|
||||||
|
run-name: Release ${{ inputs.tag }}
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag:
|
||||||
|
description: Tag to release
|
||||||
|
required: true
|
||||||
|
default: 0.1.0
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions/setup-node@v6
|
||||||
|
with:
|
||||||
|
cache: npm
|
||||||
|
node-version-file: package.json
|
||||||
|
- run: |
|
||||||
|
sed -ri 's/"version": ".+"/"version": "${{ inputs.tag }}"/' package.json
|
||||||
|
sed -ri 's/setup-bazel@.+$/setup-bazel@${{ inputs.tag }}/g' README.md
|
||||||
|
- run: npm install
|
||||||
|
- run: npm run build
|
||||||
|
- run: |
|
||||||
|
git config user.name github-actions
|
||||||
|
git config user.email github-actions@github.com
|
||||||
|
- run: git commit -am "Release ${{ inputs.tag }}"
|
||||||
|
- run: git push
|
||||||
|
- run: git tag -a ${{ inputs.tag }} -m "Release ${{ inputs.tag }}"
|
||||||
|
- run: git push --tags
|
||||||
|
- run: gh release create ${{ inputs.tag }} --generate-notes
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
|
@ -1 +1 @@
|
||||||
nodejs 16.15.0
|
nodejs 24.14.0
|
||||||
|
|
|
||||||
291
README.md
291
README.md
|
|
@ -1,8 +1,21 @@
|
||||||
# setup-bazel
|
# 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.
|
and provides an advanced fine-grained caching to improve workflows performance.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
|
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
|
||||||
|
```
|
||||||
|
|
||||||
## Inputs
|
## Inputs
|
||||||
|
|
||||||
### `bazelisk-cache`
|
### `bazelisk-cache`
|
||||||
|
|
@ -11,12 +24,89 @@ Cache [`bazelisk`][1] downloads based on contents of a `.bazelversion` file.
|
||||||
|
|
||||||
Default `false`.
|
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 `""`.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
#### Install Bazelisk 1.x
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
|
with:
|
||||||
|
bazelisk-version: 1.x
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Install exact Bazelisk version
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
|
with:
|
||||||
|
bazelisk-version: 1.19.0
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
### `bazelrc`
|
### `bazelrc`
|
||||||
|
|
||||||
Extra contents to write to a user's [`bazelrc`][4] file.
|
Extra contents to write to a user's [`bazelrc`][4] file.
|
||||||
|
|
||||||
|
You can use multiline YAML strings.
|
||||||
|
|
||||||
Default `""`.
|
Default `""`.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
#### Enable Bzlmod
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
|
with:
|
||||||
|
bazelrc: common --enable_bzlmod
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Add colors and timestamps
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
|
with:
|
||||||
|
bazelrc: |
|
||||||
|
build --color=yes
|
||||||
|
build --show_timestamps
|
||||||
|
```
|
||||||
|
</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.18.0
|
||||||
|
with:
|
||||||
|
bazelisk-cache: true
|
||||||
|
disk-cache: ${{ github.workflow }}
|
||||||
|
repository-cache: true
|
||||||
|
cache-save: ${{ github.event_name != 'pull_request' }}
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
### `disk-cache`
|
### `disk-cache`
|
||||||
|
|
||||||
Enable [`disk_cache`][2] and store it on GitHub based on contents of `BUILD` files.
|
Enable [`disk_cache`][2] and store it on GitHub based on contents of `BUILD` files.
|
||||||
|
|
@ -25,70 +115,183 @@ You can also pass a string to use as a cache key to separate caches from differe
|
||||||
|
|
||||||
Default `false`.
|
Default `false`.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
#### Share a single disk cache
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
|
with:
|
||||||
|
disk-cache: true
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Separate disk caches between workflows
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
|
with:
|
||||||
|
disk-cache: ${{ github.workflow }}
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
### `external-cache`
|
### `external-cache`
|
||||||
|
|
||||||
Cache `external/` repositories based on contents of a `WORKSPACE` file.
|
Cache `external/` repositories based on contents of `MODULE.bazel` and `WORKSPACE` files.
|
||||||
Only repositories exceeding 10MB are being cached.
|
Only repositories exceeding 10MB are being cached.
|
||||||
|
Each repository is stored in a separate cache.
|
||||||
|
|
||||||
You can also pass a YAML object where key is the name of the external repository
|
You can also pass a `manifest` object where key is the name of the external repository
|
||||||
and value is the list of files which contents are used to calculate cache key.
|
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.
|
||||||
|
|
||||||
Default `false`.
|
Default `false`.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
#### Enable external repositories caches
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
|
with:
|
||||||
|
external-cache: true
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Cache NPM repositories based on `package-lock.json` contents
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
|
with:
|
||||||
|
external-cache: |
|
||||||
|
manifest:
|
||||||
|
npm: package-lock.json
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Do not cache Ruby on Windows
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
|
with:
|
||||||
|
external-cache: |
|
||||||
|
manifest:
|
||||||
|
ruby: ${{ runner.os == 'Windows' && 'false' || 'true' }}
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
|
### `google-credentials`
|
||||||
|
|
||||||
|
Google Cloud account key to use for [remote caching authentication][9].
|
||||||
|
|
||||||
|
Default `""`.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
#### Authenticate via key
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
|
with:
|
||||||
|
google-credentials: ${{ secrets.GOOGLE_CLOUD_KEY }}
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
|
### `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 `"."`.
|
||||||
|
|
||||||
|
### `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
|
||||||
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
|
with:
|
||||||
|
output-base: C:/_bazel
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
### `repository-cache`
|
### `repository-cache`
|
||||||
|
|
||||||
Enable [`repository_cache`][3] and store it on GitHub based on contents of a `WORKSPACE` file.
|
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.
|
||||||
|
|
||||||
Default `false`.
|
Default `false`.
|
||||||
|
|
||||||
## Examples
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
### Simple configuration
|
#### Store a single repository cache
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: p0deje/setup-bazel@0.3.2
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
|
with:
|
||||||
|
repository-cache: true
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Store a repository cache from a custom location
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
|
with:
|
||||||
|
repository-cache: examples/gem/WORKSPACE
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Store a repository cache from a list of custom locations
|
||||||
|
```yaml
|
||||||
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
|
with:
|
||||||
|
repository-cache: |
|
||||||
|
- MODULE.bazel
|
||||||
|
- requirements_locked.txt
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
|
## Migrating from [`bazelbuild/setup-bazelisk`][6]
|
||||||
|
|
||||||
|
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].
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
To build action, run the following command:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ npm install
|
||||||
|
$ npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
### Additional `.bazelrc` options
|
## Release
|
||||||
|
|
||||||
```yaml
|
Use [Release][10] workflow to cut a new release.
|
||||||
- uses: p0deje/setup-bazel@0.3.2
|
|
||||||
with:
|
|
||||||
bazelrc: |
|
|
||||||
build --show_timestamps
|
|
||||||
```
|
|
||||||
|
|
||||||
### Full caching enabled
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
- uses: p0deje/setup-bazel@0.3.2
|
|
||||||
with:
|
|
||||||
bazelisk-cache: true
|
|
||||||
disk-cache: true
|
|
||||||
external-cache: true
|
|
||||||
repository-cache: true
|
|
||||||
```
|
|
||||||
|
|
||||||
### Separate disk cache between workflows
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
- uses: p0deje/setup-bazel@0.3.2
|
|
||||||
with:
|
|
||||||
disk-cache: ${{ github.workflow }}}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Cache external repository based on different files
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
- uses: p0deje/setup-bazel@0.3.2
|
|
||||||
with:
|
|
||||||
external-cache: |
|
|
||||||
manifest:
|
|
||||||
npm: package-lock.json
|
|
||||||
```
|
|
||||||
|
|
||||||
[1]: https://github.com/bazelbuild/bazelisk
|
[1]: https://github.com/bazelbuild/bazelisk
|
||||||
[2]: https://bazel.build/remote/caching#disk-cache
|
[2]: https://bazel.build/remote/caching#disk-cache
|
||||||
[3]: https://docs-staging.bazel.build/2338/versions/main/guide.html#the-repository-cache
|
[3]: https://docs-staging.bazel.build/2338/versions/main/guide.html#the-repository-cache
|
||||||
[4]: https://bazel.build/run/bazelrc
|
[4]: https://bazel.build/run/bazelrc
|
||||||
[5]: https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
|
[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
|
||||||
|
[9]: https://bazel.build/reference/command-line-reference#flag--google_credentials
|
||||||
|
[10]: https://github.com/bazel-contrib/setup-bazel/actions/workflows/release.yml
|
||||||
|
|
|
||||||
39
action.yml
39
action.yml
|
|
@ -1,36 +1,57 @@
|
||||||
name: Setup Bazel
|
name: Setup Bazel environment
|
||||||
|
description: Setup a Bazel environment, including Bazelisk and fine-grained caching
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
bazelisk-cache:
|
bazelisk-cache:
|
||||||
description: Caches Bazelisk downloads based on .bazelversion
|
description: Caches Bazelisk downloads based on .bazelversion
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: "false"
|
||||||
|
bazelisk-version:
|
||||||
|
description: The Bazelisk version to download and use if necessary
|
||||||
|
default: ""
|
||||||
bazelrc:
|
bazelrc:
|
||||||
description: Extra contents to write to user .bazelrc
|
description: Extra contents to write to user .bazelrc
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
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:
|
cache-version:
|
||||||
description: Version of all caches
|
description: Version of all caches
|
||||||
required: false
|
required: false
|
||||||
default: 1
|
default: "1"
|
||||||
disk-cache:
|
disk-cache:
|
||||||
description: Cache actions outputs based on BUILD
|
description: Cache actions outputs based on BUILD
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: "false"
|
||||||
external-cache:
|
external-cache:
|
||||||
description: Cache external 10MB+ repositories based on WORKSPACE
|
description: Cache external 10MB+ repositories based on MODULE.bazel/WORKSPACE
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ""
|
||||||
google-credentials:
|
google-credentials:
|
||||||
description: Google Cloud account key for remote cache
|
description: Google Cloud account key for remote cache
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ""
|
||||||
repository-cache:
|
module-root:
|
||||||
description: Cache repositories based on WORKSPACE
|
description: Bazel module root directory. Default is `.`
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: "."
|
||||||
|
output-base:
|
||||||
|
description: Bazel output base directory. Default is $HOME/.cache/bazel (POSIX) or D:/_bazel (Windows)
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
|
repository-cache:
|
||||||
|
description: Cache repositories based on MODULE.bazel/WORKSPACE
|
||||||
|
required: false
|
||||||
|
default: "false"
|
||||||
|
token:
|
||||||
|
description: GitHub token to query Bazelisk releases
|
||||||
|
required: false
|
||||||
|
default: ${{ github.token }}
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: node16
|
using: node20
|
||||||
main: dist/main/index.js
|
main: dist/main/index.js
|
||||||
post: dist/post/index.js
|
post: dist/post/index.js
|
||||||
|
post-if: "!cancelled()"
|
||||||
|
|
|
||||||
83
config.js
83
config.js
|
|
@ -4,15 +4,31 @@ const yaml = require('yaml')
|
||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
const github = require('@actions/github')
|
const github = require('@actions/github')
|
||||||
|
|
||||||
|
const bazeliskVersion = core.getInput('bazelisk-version')
|
||||||
|
const cacheSave = core.getBooleanInput('cache-save')
|
||||||
const cacheVersion = core.getInput('cache-version')
|
const cacheVersion = core.getInput('cache-version')
|
||||||
const externalCacheConfig = yaml.parse(core.getInput('external-cache'))
|
const moduleRoot = core.getInput('module-root')
|
||||||
|
|
||||||
const homeDir = os.homedir()
|
const homeDir = os.homedir()
|
||||||
|
const arch = os.arch()
|
||||||
const platform = os.platform()
|
const platform = os.platform()
|
||||||
|
|
||||||
|
let bazelOutputBase = core.getInput('output-base')
|
||||||
|
if (!bazelOutputBase) {
|
||||||
|
if (platform === 'win32') {
|
||||||
|
// check if GITHUB_WORKSPACE starts with D:
|
||||||
|
if (process.env.GITHUB_WORKSPACE?.toLowerCase()?.startsWith('d:')) {
|
||||||
|
bazelOutputBase = 'D:/_bazel'
|
||||||
|
} else {
|
||||||
|
bazelOutputBase = `C:/_bazel`
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bazelOutputBase = `${homeDir}/.bazel`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let bazelDisk = core.toPosixPath(`${homeDir}/.cache/bazel-disk`)
|
let bazelDisk = core.toPosixPath(`${homeDir}/.cache/bazel-disk`)
|
||||||
let bazelRepository = core.toPosixPath(`${homeDir}/.cache/bazel-repo`)
|
let bazelRepository = core.toPosixPath(`${homeDir}/.cache/bazel-repo`)
|
||||||
let bazelOutputBase = `${homeDir}/.bazel`
|
|
||||||
let bazelrcPaths = [core.toPosixPath(`${homeDir}/.bazelrc`)]
|
let bazelrcPaths = [core.toPosixPath(`${homeDir}/.bazelrc`)]
|
||||||
let userCacheDir = `${homeDir}/.cache`
|
let userCacheDir = `${homeDir}/.cache`
|
||||||
|
|
||||||
|
|
@ -21,9 +37,8 @@ switch (platform) {
|
||||||
userCacheDir = `${homeDir}/Library/Caches`
|
userCacheDir = `${homeDir}/Library/Caches`
|
||||||
break
|
break
|
||||||
case 'win32':
|
case 'win32':
|
||||||
bazelDisk = 'D:/_bazel-disk'
|
bazelDisk = `${bazelOutputBase}-disk`
|
||||||
bazelRepository = 'D:/_bazel-repo'
|
bazelRepository = `${bazelOutputBase}-repo`
|
||||||
bazelOutputBase = 'D:/_bazel'
|
|
||||||
userCacheDir = `${homeDir}/AppData/Local`
|
userCacheDir = `${homeDir}/AppData/Local`
|
||||||
if (process.env.HOME) {
|
if (process.env.HOME) {
|
||||||
bazelrcPaths.push(core.toPosixPath(`${process.env.HOME}/.bazelrc`))
|
bazelrcPaths.push(core.toPosixPath(`${process.env.HOME}/.bazelrc`))
|
||||||
|
|
@ -31,34 +46,48 @@ switch (platform) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseCacheKey = `setup-bazel-${cacheVersion}-${platform}`
|
const baseCacheKey = `setup-bazel-${cacheVersion}-${platform}-${arch}`
|
||||||
const bazelrc = core.getMultilineInput('bazelrc')
|
const bazelrc = core.getMultilineInput('bazelrc')
|
||||||
|
|
||||||
const diskCacheConfig = core.getInput('disk-cache')
|
const diskCacheConfig = core.getInput('disk-cache')
|
||||||
const diskCacheEnabled = diskCacheConfig !== 'false'
|
const diskCacheEnabled = diskCacheConfig !== 'false'
|
||||||
let diskCacheName = 'disk'
|
let diskCacheName = 'disk'
|
||||||
if (diskCacheEnabled) {
|
if (diskCacheEnabled) {
|
||||||
|
// Before Bazel 6.3, providing --disk_cache to common is an error,
|
||||||
|
// with Bazel 6.3 and onwards, common accepts any legal Bazel option
|
||||||
|
// https://github.com/bazelbuild/bazel/issues/3054
|
||||||
bazelrc.push(`build --disk_cache=${bazelDisk}`)
|
bazelrc.push(`build --disk_cache=${bazelDisk}`)
|
||||||
if (diskCacheName !== 'true') {
|
if (diskCacheName !== 'true') {
|
||||||
diskCacheName = `${diskCacheName}-${diskCacheConfig}`
|
diskCacheName = `${diskCacheName}-${diskCacheConfig}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const repositoryCacheEnabled = core.getBooleanInput('repository-cache')
|
const repositoryCacheConfig = yaml.parse(core.getInput('repository-cache'))
|
||||||
|
const repositoryCacheEnabled = repositoryCacheConfig !== false
|
||||||
|
let repositoryCacheFiles = [
|
||||||
|
`${moduleRoot}/MODULE.bazel`,
|
||||||
|
`${moduleRoot}/WORKSPACE.bazel`,
|
||||||
|
`${moduleRoot}/WORKSPACE.bzlmod`,
|
||||||
|
`${moduleRoot}/WORKSPACE`
|
||||||
|
]
|
||||||
if (repositoryCacheEnabled) {
|
if (repositoryCacheEnabled) {
|
||||||
bazelrc.push(`build --repository_cache=${bazelRepository}`)
|
bazelrc.push(`common --repository_cache=${bazelRepository}`)
|
||||||
|
if (repositoryCacheConfig !== true) {
|
||||||
|
repositoryCacheFiles = Array(repositoryCacheConfig).flat()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const googleCredentials = core.getInput('google-credentials')
|
const googleCredentials = core.getInput('google-credentials')
|
||||||
const googleCredentialsSaved = (core.getState('google-credentials-path').length > 0)
|
const googleCredentialsSaved = (core.getState('google-credentials-path').length > 0)
|
||||||
if (googleCredentials.length > 0 && !googleCredentialsSaved) {
|
if (googleCredentials.length > 0 && !googleCredentialsSaved) {
|
||||||
const tmpDir = core.toPosixPath(fs.mkdtempSync(os.tmpdir()))
|
const tmpDir = core.toPosixPath(fs.mkdtempSync(process.env.RUNNER_TEMP))
|
||||||
const googleCredentialsPath = `${tmpDir}/key.json`
|
const googleCredentialsPath = `${tmpDir}/key.json`
|
||||||
fs.writeFileSync(googleCredentialsPath, googleCredentials)
|
fs.writeFileSync(googleCredentialsPath, googleCredentials)
|
||||||
bazelrc.push(`build --google_credentials=${googleCredentialsPath}`)
|
bazelrc.push(`build --google_credentials=${googleCredentialsPath}`)
|
||||||
core.saveState('google-credentials-path', googleCredentialsPath)
|
core.saveState('google-credentials-path', googleCredentialsPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const externalCacheConfig = yaml.parse(core.getInput('external-cache'))
|
||||||
const bazelExternal = core.toPosixPath(`${bazelOutputBase}/external`)
|
const bazelExternal = core.toPosixPath(`${bazelOutputBase}/external`)
|
||||||
const externalCache = {}
|
const externalCache = {}
|
||||||
if (externalCacheConfig) {
|
if (externalCacheConfig) {
|
||||||
|
|
@ -71,16 +100,21 @@ if (externalCacheConfig) {
|
||||||
externalCache.baseCacheKey = `${baseCacheKey}-external-`
|
externalCache.baseCacheKey = `${baseCacheKey}-external-`
|
||||||
externalCache.manifest = {
|
externalCache.manifest = {
|
||||||
files: [
|
files: [
|
||||||
'WORKSPACE.bazel',
|
`${moduleRoot}/MODULE.bazel`,
|
||||||
'WORKSPACE'
|
`${moduleRoot}/WORKSPACE.bazel`,
|
||||||
|
`${moduleRoot}/WORKSPACE.bzlmod`,
|
||||||
|
`${moduleRoot}/WORKSPACE`
|
||||||
],
|
],
|
||||||
name: `external-${manifestName}-manifest`,
|
name: `external-${manifestName}-manifest`,
|
||||||
path: `${os.tmpdir()}/external-cache-manifest.txt`
|
path: `${os.tmpdir()}/external-cache-manifest.txt`
|
||||||
}
|
}
|
||||||
externalCache.default = {
|
externalCache.default = {
|
||||||
|
enabled: true,
|
||||||
files: [
|
files: [
|
||||||
'WORKSPACE.bazel',
|
`${moduleRoot}/MODULE.bazel`,
|
||||||
'WORKSPACE'
|
`${moduleRoot}/WORKSPACE.bazel`,
|
||||||
|
`${moduleRoot}/WORKSPACE.bzlmod`,
|
||||||
|
`${moduleRoot}/WORKSPACE`
|
||||||
],
|
],
|
||||||
name: (name) => { return `external-${name}` },
|
name: (name) => { return `external-${name}` },
|
||||||
paths: (name) => {
|
paths: (name) => {
|
||||||
|
|
@ -93,25 +127,32 @@ if (externalCacheConfig) {
|
||||||
|
|
||||||
for (const name in externalCacheConfig.manifest) {
|
for (const name in externalCacheConfig.manifest) {
|
||||||
externalCache[name] = {
|
externalCache[name] = {
|
||||||
|
enabled: externalCacheConfig.manifest[name] != false,
|
||||||
files: Array(externalCacheConfig.manifest[name]).flat()
|
files: Array(externalCacheConfig.manifest[name]).flat()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const token = core.getInput('token')
|
||||||
|
core.exportVariable('BAZELISK_GITHUB_TOKEN', token)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
baseCacheKey,
|
baseCacheKey,
|
||||||
|
cacheSave,
|
||||||
bazeliskCache: {
|
bazeliskCache: {
|
||||||
enabled: core.getBooleanInput('bazelisk-cache'),
|
enabled: core.getBooleanInput('bazelisk-cache'),
|
||||||
files: ['.bazelversion'],
|
files: [`${moduleRoot}/.bazelversion`],
|
||||||
name: 'bazelisk',
|
name: 'bazelisk',
|
||||||
paths: [core.toPosixPath(`${userCacheDir}/bazelisk`)]
|
paths: [core.toPosixPath(`${userCacheDir}/bazelisk`)]
|
||||||
},
|
},
|
||||||
|
bazeliskVersion,
|
||||||
bazelrc,
|
bazelrc,
|
||||||
diskCache: {
|
diskCache: {
|
||||||
enabled: diskCacheEnabled,
|
enabled: diskCacheEnabled,
|
||||||
files: [
|
files: [
|
||||||
'**/BUILD.bazel',
|
...repositoryCacheFiles,
|
||||||
'**/BUILD'
|
`${moduleRoot}/**/BUILD.bazel`,
|
||||||
|
`${moduleRoot}/**/BUILD`
|
||||||
],
|
],
|
||||||
name: diskCacheName,
|
name: diskCacheName,
|
||||||
paths: [bazelDisk]
|
paths: [bazelDisk]
|
||||||
|
|
@ -122,13 +163,13 @@ module.exports = {
|
||||||
bazelOutputBase: core.toPosixPath(bazelOutputBase),
|
bazelOutputBase: core.toPosixPath(bazelOutputBase),
|
||||||
bazelrc: bazelrcPaths
|
bazelrc: bazelrcPaths
|
||||||
},
|
},
|
||||||
platform,
|
os: {
|
||||||
|
arch,
|
||||||
|
platform,
|
||||||
|
},
|
||||||
repositoryCache: {
|
repositoryCache: {
|
||||||
enabled: repositoryCacheEnabled,
|
enabled: repositoryCacheEnabled,
|
||||||
files: [
|
files: repositoryCacheFiles,
|
||||||
'WORKSPACE.bazel',
|
|
||||||
'WORKSPACE'
|
|
||||||
],
|
|
||||||
name: 'repository',
|
name: 'repository',
|
||||||
paths: [bazelRepository]
|
paths: [bazelRepository]
|
||||||
},
|
},
|
||||||
|
|
|
||||||
115761
dist/main/index.js
vendored
115761
dist/main/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/main/index.js.map
vendored
2
dist/main/index.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/main/sourcemap-register.js
vendored
2
dist/main/sourcemap-register.js
vendored
File diff suppressed because one or more lines are too long
112580
dist/post/index.js
vendored
112580
dist/post/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/post/index.js.map
vendored
2
dist/post/index.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/post/sourcemap-register.js
vendored
2
dist/post/sourcemap-register.js
vendored
File diff suppressed because one or more lines are too long
128
index.js
128
index.js
|
|
@ -2,10 +2,12 @@ const fs = require('fs')
|
||||||
const { setTimeout } = require('timers/promises')
|
const { setTimeout } = require('timers/promises')
|
||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
const cache = require('@actions/cache')
|
const cache = require('@actions/cache')
|
||||||
|
const github = require('@actions/github')
|
||||||
const glob = require('@actions/glob')
|
const glob = require('@actions/glob')
|
||||||
|
const tc = require('@actions/tool-cache')
|
||||||
const config = require('./config')
|
const config = require('./config')
|
||||||
|
|
||||||
async function run () {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
await setupBazel()
|
await setupBazel()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -13,21 +15,98 @@ async function run () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setupBazel () {
|
async function setupBazel() {
|
||||||
core.startGroup('Configure Bazel')
|
core.startGroup('Configure Bazel')
|
||||||
console.log('Configuration:')
|
core.info('Configuration:')
|
||||||
console.log(JSON.stringify(config, null, 2))
|
core.info(JSON.stringify(config, null, 2))
|
||||||
|
|
||||||
await setupBazelrc()
|
await setupBazelrc()
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
|
|
||||||
|
await setupBazelisk()
|
||||||
await restoreCache(config.bazeliskCache)
|
await restoreCache(config.bazeliskCache)
|
||||||
await restoreCache(config.diskCache)
|
await restoreCache(config.diskCache)
|
||||||
await restoreCache(config.repositoryCache)
|
await restoreCache(config.repositoryCache)
|
||||||
await restoreExternalCaches(config.externalCache)
|
await restoreExternalCaches(config.externalCache)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setupBazelrc () {
|
async function setupBazelisk() {
|
||||||
|
if (config.bazeliskVersion.length == 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
core.startGroup('Setup Bazelisk')
|
||||||
|
let toolPath = tc.find('bazelisk', config.bazeliskVersion)
|
||||||
|
if (toolPath) {
|
||||||
|
core.debug(`Found in cache @ ${toolPath}`)
|
||||||
|
} else {
|
||||||
|
toolPath = await downloadBazelisk()
|
||||||
|
}
|
||||||
|
core.addPath(toolPath)
|
||||||
|
core.endGroup()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function downloadBazelisk() {
|
||||||
|
const version = config.bazeliskVersion
|
||||||
|
core.debug(`Attempting to download ${version}`)
|
||||||
|
|
||||||
|
// Possible values are 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x' and 'x64'.
|
||||||
|
// Bazelisk filenames use 'amd64' and 'arm64'.
|
||||||
|
let arch = config.os.arch
|
||||||
|
if (arch == 'x64') {
|
||||||
|
arch = 'amd64'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Possible values are 'aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos' and 'win32'.
|
||||||
|
// Bazelisk filenames use 'darwin', 'linux' and 'windows'.
|
||||||
|
let platform = config.os.platform
|
||||||
|
if (platform == "win32") {
|
||||||
|
platform = "windows"
|
||||||
|
}
|
||||||
|
|
||||||
|
let filename = `bazelisk-${platform}-${arch}`
|
||||||
|
if (platform == 'windows') {
|
||||||
|
filename = `${filename}.exe`
|
||||||
|
}
|
||||||
|
|
||||||
|
const token = process.env.BAZELISK_GITHUB_TOKEN
|
||||||
|
const octokit = github.getOctokit(token, {
|
||||||
|
baseUrl: 'https://api.github.com'
|
||||||
|
})
|
||||||
|
const { data: releases } = await octokit.rest.repos.listReleases({
|
||||||
|
owner: 'bazelbuild',
|
||||||
|
repo: 'bazelisk'
|
||||||
|
})
|
||||||
|
|
||||||
|
// Find version matching semver specification.
|
||||||
|
const tagName = tc.evaluateVersions(releases.map((r) => r.tag_name), version)
|
||||||
|
const release = releases.find((r) => r.tag_name === tagName)
|
||||||
|
if (!release) {
|
||||||
|
throw new Error(`Unable to find Bazelisk version ${version}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const asset = release.assets.find((a) => a.name == filename)
|
||||||
|
if (!asset) {
|
||||||
|
throw new Error(`Unable to find Bazelisk version ${version} for platform ${platform}/${arch}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = asset.browser_download_url
|
||||||
|
core.debug(`Downloading from ${url}`)
|
||||||
|
const downloadPath = await tc.downloadTool(url, undefined, `token ${token}`)
|
||||||
|
|
||||||
|
core.debug('Adding to the cache...');
|
||||||
|
fs.chmodSync(downloadPath, '755');
|
||||||
|
let bazel_name = "bazel";
|
||||||
|
if (platform == 'windows') {
|
||||||
|
bazel_name = `${bazel_name}.exe`
|
||||||
|
}
|
||||||
|
const cachePath = await tc.cacheFile(downloadPath, bazel_name, 'bazelisk', version)
|
||||||
|
core.debug(`Successfully cached bazelisk to ${cachePath}`)
|
||||||
|
|
||||||
|
return cachePath
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setupBazelrc() {
|
||||||
for (const bazelrcPath of config.paths.bazelrc) {
|
for (const bazelrcPath of config.paths.bazelrc) {
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
bazelrcPath,
|
bazelrcPath,
|
||||||
|
|
@ -37,7 +116,7 @@ async function setupBazelrc () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function restoreExternalCaches (cacheConfig) {
|
async function restoreExternalCaches(cacheConfig) {
|
||||||
if (!cacheConfig.enabled) {
|
if (!cacheConfig.enabled) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -54,33 +133,36 @@ async function restoreExternalCaches (cacheConfig) {
|
||||||
// Now restore all external caches defined in manifest
|
// Now restore all external caches defined in manifest
|
||||||
if (fs.existsSync(path)) {
|
if (fs.existsSync(path)) {
|
||||||
const manifest = fs.readFileSync(path, { encoding: 'utf8' })
|
const manifest = fs.readFileSync(path, { encoding: 'utf8' })
|
||||||
for (const name of manifest.split('\n').filter(s => s)) {
|
const restorePromises = manifest.split('\n').filter(s => s)
|
||||||
await restoreCache({
|
.map(name => {
|
||||||
enabled: true,
|
return restoreCache({
|
||||||
files: cacheConfig[name]?.files || cacheConfig.default.files,
|
enabled: cacheConfig[name]?.enabled ?? cacheConfig.default.enabled,
|
||||||
name: cacheConfig.default.name(name),
|
files: cacheConfig[name]?.files || cacheConfig.default.files,
|
||||||
paths: cacheConfig.default.paths(name)
|
name: cacheConfig.default.name(name),
|
||||||
})
|
paths: cacheConfig.default.paths(name)
|
||||||
}
|
});
|
||||||
|
});
|
||||||
|
await Promise.all(restorePromises);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function restoreCache (cacheConfig) {
|
async function restoreCache(cacheConfig) {
|
||||||
if (!cacheConfig.enabled) {
|
if (!cacheConfig.enabled) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const delay = Math.random() * 1000 // timeout <= 1 sec to reduce 429 errors
|
const delay = Math.random() * 1000 // timeout <= 1 sec to reduce 429 errors
|
||||||
await setTimeout(delay, async function () {
|
await setTimeout(delay)
|
||||||
core.startGroup(`Restore cache for ${cacheConfig.name}`)
|
|
||||||
|
|
||||||
|
core.startGroup(`Restore cache for ${cacheConfig.name}`)
|
||||||
|
try {
|
||||||
const hash = await glob.hashFiles(cacheConfig.files.join('\n'))
|
const hash = await glob.hashFiles(cacheConfig.files.join('\n'))
|
||||||
const name = cacheConfig.name
|
const name = cacheConfig.name
|
||||||
const paths = cacheConfig.paths
|
const paths = cacheConfig.paths
|
||||||
const restoreKey = `${config.baseCacheKey}-${name}-`
|
const restoreKey = `${config.baseCacheKey}-${name}-`
|
||||||
const key = `${restoreKey}${hash}`
|
const key = `${restoreKey}${hash}`
|
||||||
|
|
||||||
console.log(`Attempting to restore ${name} cache from ${key}`)
|
core.debug(`Attempting to restore ${name} cache from ${key}`)
|
||||||
|
|
||||||
const restoredKey = await cache.restoreCache(
|
const restoredKey = await cache.restoreCache(
|
||||||
paths, key, [restoreKey],
|
paths, key, [restoreKey],
|
||||||
|
|
@ -88,17 +170,19 @@ async function restoreCache (cacheConfig) {
|
||||||
)
|
)
|
||||||
|
|
||||||
if (restoredKey) {
|
if (restoredKey) {
|
||||||
console.log(`Successfully restored cache from ${restoredKey}`)
|
core.info(`Successfully restored cache from ${restoredKey}`)
|
||||||
|
|
||||||
if (restoredKey === key) {
|
if (restoredKey === key) {
|
||||||
core.saveState(`${name}-cache-hit`, 'true')
|
core.saveState(`${name}-cache-hit`, 'true')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log(`Failed to restore ${name} cache`)
|
core.info(`Failed to restore ${name} cache`)
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
core.warning(`Failed to restore ${name} cache with error: ${err}`)
|
||||||
|
} finally {
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
}())
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
|
|
||||||
1020
package-lock.json
generated
1020
package-lock.json
generated
File diff suppressed because it is too large
Load diff
17
package.json
17
package.json
|
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"name": "setup-bazel",
|
"name": "setup-bazel",
|
||||||
"version": "0.3.2",
|
"version": "0.18.0",
|
||||||
"description": "Install and configure Bazel for GitHub Actions",
|
"description": "Install and configure Bazel for GitHub Actions",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"engines" : {
|
"engines": {
|
||||||
"node" : "16.x"
|
"node": "24.x"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "ncc build index.js -s -o dist/main && ncc build post.js -s -o dist/post",
|
"build": "ncc build index.js -s -o dist/main && ncc build post.js -s -o dist/post",
|
||||||
|
|
@ -13,11 +13,12 @@
|
||||||
"author": "Alex Rodionov <p0deje@gmail.com>",
|
"author": "Alex Rodionov <p0deje@gmail.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^3.2.2",
|
"@actions/cache": "^6.0.0",
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^3.0.0",
|
||||||
"@actions/github": "^6.0.0",
|
"@actions/github": "^9.0.0",
|
||||||
"@actions/glob": "^0.4.0",
|
"@actions/glob": "^0.6.0",
|
||||||
"@vercel/ncc": "^0.36.0",
|
"@actions/tool-cache": "^4.0.0",
|
||||||
|
"@vercel/ncc": "^0.38.0",
|
||||||
"yaml": "^2.2.1"
|
"yaml": "^2.2.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
post.js
23
post.js
|
|
@ -5,19 +5,26 @@ const core = require('@actions/core')
|
||||||
const glob = require('@actions/glob')
|
const glob = require('@actions/glob')
|
||||||
const config = require('./config')
|
const config = require('./config')
|
||||||
const { getFolderSize } = require('./util')
|
const { getFolderSize } = require('./util')
|
||||||
|
const process = require('node:process');
|
||||||
|
|
||||||
async function run () {
|
async function run() {
|
||||||
await saveCaches()
|
await saveCaches()
|
||||||
|
process.exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveCaches () {
|
async function saveCaches() {
|
||||||
|
if (!config.cacheSave) {
|
||||||
|
core.info('Cache saving is disabled (cache-save: false)')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
await saveCache(config.bazeliskCache)
|
await saveCache(config.bazeliskCache)
|
||||||
await saveCache(config.diskCache)
|
await saveCache(config.diskCache)
|
||||||
await saveCache(config.repositoryCache)
|
await saveCache(config.repositoryCache)
|
||||||
await saveExternalCaches(config.externalCache)
|
await saveExternalCaches(config.externalCache)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveExternalCaches (cacheConfig) {
|
async function saveExternalCaches(cacheConfig) {
|
||||||
if (!cacheConfig.enabled) {
|
if (!cacheConfig.enabled) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -37,7 +44,7 @@ async function saveExternalCaches (cacheConfig) {
|
||||||
if (sizeMB >= cacheConfig.minSize) {
|
if (sizeMB >= cacheConfig.minSize) {
|
||||||
const name = path.basename(externalPath)
|
const name = path.basename(externalPath)
|
||||||
await saveCache({
|
await saveCache({
|
||||||
enabled: true,
|
enabled: cacheConfig[name]?.enabled ?? cacheConfig.default.enabled,
|
||||||
files: cacheConfig[name]?.files || cacheConfig.default.files,
|
files: cacheConfig[name]?.files || cacheConfig.default.files,
|
||||||
name: cacheConfig.default.name(name),
|
name: cacheConfig.default.name(name),
|
||||||
paths: cacheConfig.default.paths(name)
|
paths: cacheConfig.default.paths(name)
|
||||||
|
|
@ -58,7 +65,7 @@ async function saveExternalCaches (cacheConfig) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveCache (cacheConfig) {
|
async function saveCache(cacheConfig) {
|
||||||
if (!cacheConfig.enabled) {
|
if (!cacheConfig.enabled) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -74,12 +81,14 @@ async function saveCache (cacheConfig) {
|
||||||
const paths = cacheConfig.paths
|
const paths = cacheConfig.paths
|
||||||
const hash = await glob.hashFiles(
|
const hash = await glob.hashFiles(
|
||||||
cacheConfig.files.join('\n'),
|
cacheConfig.files.join('\n'),
|
||||||
|
undefined,
|
||||||
|
// We don't want to follow symlinks as it's extremely slow on macOS.
|
||||||
{ followSymbolicLinks: false }
|
{ followSymbolicLinks: false }
|
||||||
)
|
)
|
||||||
const key = `${config.baseCacheKey}-${cacheConfig.name}-${hash}`
|
const key = `${config.baseCacheKey}-${cacheConfig.name}-${hash}`
|
||||||
console.log(`Attempting to save ${paths} cache to ${key}`)
|
core.debug(`Attempting to save ${paths} cache to ${key}`)
|
||||||
await cache.saveCache(paths, key)
|
await cache.saveCache(paths, key)
|
||||||
console.log('Successfully saved cache')
|
core.info('Successfully saved cache')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.warning(error.stack)
|
core.warning(error.stack)
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
||||||
6
renovate.json
Normal file
6
renovate.json
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": [
|
||||||
|
"config:recommended"
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue