Compare commits
100 commits
p0deje/int
...
main
| 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 |
21 changed files with 116805 additions and 182683 deletions
45
.github/workflows/ci.yml
vendored
45
.github/workflows/ci.yml
vendored
|
|
@ -13,52 +13,13 @@ jobs:
|
||||||
setup-bazel:
|
setup-bazel:
|
||||||
runs-on: ${{ matrix.os }}-latest
|
runs-on: ${{ matrix.os }}-latest
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
matrix:
|
||||||
os:
|
os:
|
||||||
- macos
|
- macos
|
||||||
- ubuntu
|
- ubuntu
|
||||||
- windows
|
- windows
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout example
|
- uses: actions/checkout@v6
|
||||||
uses: actions/checkout@v4
|
- uses: ./
|
||||||
with:
|
- if: failure() && runner.debug == '1'
|
||||||
repository: bazelbuild/examples
|
|
||||||
sparse-checkout: frontend
|
|
||||||
sparse-checkout-cone-mode: false
|
|
||||||
|
|
||||||
- name: Checkout setup-bazel
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
path: setup-bazel
|
|
||||||
|
|
||||||
- name: Prepare environment (POSIX)
|
|
||||||
if: matrix.os != 'windows'
|
|
||||||
run: |
|
|
||||||
rm $(which bazel)
|
|
||||||
shopt -s dotglob
|
|
||||||
mv frontend/* .
|
|
||||||
rmdir frontend
|
|
||||||
|
|
||||||
- name: Prepare environment (Windows)
|
|
||||||
if: matrix.os == 'windows'
|
|
||||||
run: |
|
|
||||||
Remove-Item -Path (Get-Command bazel.exe).Source
|
|
||||||
Get-ChildItem -Path frontend -Recurse -File | Move-Item -Destination .
|
|
||||||
Remove-Item -Path frontend -Recurse -Force
|
|
||||||
|
|
||||||
- name: Setup Bazel
|
|
||||||
uses: ./setup-bazel/
|
|
||||||
with:
|
|
||||||
bazelisk-cache: true
|
|
||||||
bazelisk-version: 1.x
|
|
||||||
bazelrc: test --test_output=errors
|
|
||||||
remote-cache: true
|
|
||||||
repository-cache: true
|
|
||||||
|
|
||||||
- run: bazel build ...
|
|
||||||
- run: bazel test ...
|
|
||||||
|
|
||||||
- name: Start SSH session
|
|
||||||
if: failure() && runner.debug == '1'
|
|
||||||
uses: mxschmitt/action-tmate@v3
|
uses: mxschmitt/action-tmate@v3
|
||||||
|
|
|
||||||
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
|
|
@ -15,8 +15,8 @@ jobs:
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v6
|
||||||
with:
|
with:
|
||||||
cache: npm
|
cache: npm
|
||||||
node-version-file: package.json
|
node-version-file: package.json
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
nodejs 20.14.0
|
nodejs 24.14.0
|
||||||
|
|
|
||||||
92
README.md
92
README.md
|
|
@ -6,7 +6,7 @@ and provides an advanced fine-grained caching to improve workflows performance.
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: bazel-contrib/setup-bazel@0.8.4
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
with:
|
with:
|
||||||
# Avoid downloading Bazel every time.
|
# Avoid downloading Bazel every time.
|
||||||
bazelisk-cache: true
|
bazelisk-cache: true
|
||||||
|
|
@ -39,7 +39,7 @@ Default `""`.
|
||||||
#### Install Bazelisk 1.x
|
#### Install Bazelisk 1.x
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: bazel-contrib/setup-bazel@0.8.4
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
with:
|
with:
|
||||||
bazelisk-version: 1.x
|
bazelisk-version: 1.x
|
||||||
```
|
```
|
||||||
|
|
@ -47,7 +47,7 @@ Default `""`.
|
||||||
#### Install exact Bazelisk version
|
#### Install exact Bazelisk version
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: bazel-contrib/setup-bazel@0.8.4
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
with:
|
with:
|
||||||
bazelisk-version: 1.19.0
|
bazelisk-version: 1.19.0
|
||||||
```
|
```
|
||||||
|
|
@ -67,7 +67,7 @@ Default `""`.
|
||||||
#### Enable Bzlmod
|
#### Enable Bzlmod
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: bazel-contrib/setup-bazel@0.8.4
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
with:
|
with:
|
||||||
bazelrc: common --enable_bzlmod
|
bazelrc: common --enable_bzlmod
|
||||||
```
|
```
|
||||||
|
|
@ -75,7 +75,7 @@ Default `""`.
|
||||||
#### Add colors and timestamps
|
#### Add colors and timestamps
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: bazel-contrib/setup-bazel@0.8.4
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
with:
|
with:
|
||||||
bazelrc: |
|
bazelrc: |
|
||||||
build --color=yes
|
build --color=yes
|
||||||
|
|
@ -83,6 +83,30 @@ Default `""`.
|
||||||
```
|
```
|
||||||
</details>
|
</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.
|
||||||
|
|
@ -97,7 +121,7 @@ Default `false`.
|
||||||
#### Share a single disk cache
|
#### Share a single disk cache
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: bazel-contrib/setup-bazel@0.8.4
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
with:
|
with:
|
||||||
disk-cache: true
|
disk-cache: true
|
||||||
```
|
```
|
||||||
|
|
@ -105,9 +129,9 @@ Default `false`.
|
||||||
#### Separate disk caches between workflows
|
#### Separate disk caches between workflows
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: bazel-contrib/setup-bazel@0.8.4
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
with:
|
with:
|
||||||
disk-cache: ${{ github.workflow }}}
|
disk-cache: ${{ github.workflow }}
|
||||||
```
|
```
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|
@ -129,7 +153,7 @@ Default `false`.
|
||||||
#### Enable external repositories caches
|
#### Enable external repositories caches
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: bazel-contrib/setup-bazel@0.8.4
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
with:
|
with:
|
||||||
external-cache: true
|
external-cache: true
|
||||||
```
|
```
|
||||||
|
|
@ -137,7 +161,7 @@ Default `false`.
|
||||||
#### Cache NPM repositories based on `package-lock.json` contents
|
#### Cache NPM repositories based on `package-lock.json` contents
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: bazel-contrib/setup-bazel@0.8.4
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
with:
|
with:
|
||||||
external-cache: |
|
external-cache: |
|
||||||
manifest:
|
manifest:
|
||||||
|
|
@ -147,7 +171,7 @@ Default `false`.
|
||||||
#### Do not cache Ruby on Windows
|
#### Do not cache Ruby on Windows
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: bazel-contrib/setup-bazel@0.8.4
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
with:
|
with:
|
||||||
external-cache: |
|
external-cache: |
|
||||||
manifest:
|
manifest:
|
||||||
|
|
@ -167,12 +191,42 @@ Default `""`.
|
||||||
#### Authenticate via key
|
#### Authenticate via key
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: bazel-contrib/setup-bazel@0.8.4
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
with:
|
with:
|
||||||
google-credentials: ${{ secrets.GOOGLE_CLOUD_KEY }}
|
google-credentials: ${{ secrets.GOOGLE_CLOUD_KEY }}
|
||||||
```
|
```
|
||||||
</details>
|
</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`
|
||||||
|
|
||||||
|
|
@ -188,7 +242,7 @@ Default `false`.
|
||||||
#### Store a single repository cache
|
#### Store a single repository cache
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: bazel-contrib/setup-bazel@0.8.4
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
with:
|
with:
|
||||||
repository-cache: true
|
repository-cache: true
|
||||||
```
|
```
|
||||||
|
|
@ -196,10 +250,19 @@ Default `false`.
|
||||||
#### Store a repository cache from a custom location
|
#### Store a repository cache from a custom location
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: bazel-contrib/setup-bazel@0.8.4
|
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||||
with:
|
with:
|
||||||
repository-cache: examples/gem/WORKSPACE
|
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>
|
</details>
|
||||||
|
|
||||||
## Migrating from [`bazelbuild/setup-bazelisk`][6]
|
## Migrating from [`bazelbuild/setup-bazelisk`][6]
|
||||||
|
|
@ -213,6 +276,7 @@ However, if you used a `bazel-version` input before, you will need to remove it
|
||||||
To build action, run the following command:
|
To build action, run the following command:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
$ npm install
|
||||||
$ npm run build
|
$ npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
15
action.yml
15
action.yml
|
|
@ -13,6 +13,10 @@ inputs:
|
||||||
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
|
||||||
|
|
@ -29,10 +33,14 @@ inputs:
|
||||||
description: Google Cloud account key for remote cache
|
description: Google Cloud account key for remote cache
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ""
|
||||||
remote-cache:
|
module-root:
|
||||||
description: Use built-in remote cache server
|
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:
|
repository-cache:
|
||||||
description: Cache repositories based on MODULE.bazel/WORKSPACE
|
description: Cache repositories based on MODULE.bazel/WORKSPACE
|
||||||
required: false
|
required: false
|
||||||
|
|
@ -46,3 +54,4 @@ runs:
|
||||||
using: node20
|
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()"
|
||||||
|
|
|
||||||
89
config.js
89
config.js
|
|
@ -5,16 +5,30 @@ const core = require('@actions/core')
|
||||||
const github = require('@actions/github')
|
const github = require('@actions/github')
|
||||||
|
|
||||||
const bazeliskVersion = core.getInput('bazelisk-version')
|
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 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`
|
||||||
|
|
||||||
|
|
@ -23,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`))
|
||||||
|
|
@ -33,40 +46,33 @@ 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 remoteCacheLogPath = core.toPosixPath(`${os.tmpdir()}/remote-cache-server.log`)
|
const repositoryCacheConfig = yaml.parse(core.getInput('repository-cache'))
|
||||||
const remoteCacheServerUrl = 'http://localhost:9889/cache'
|
const repositoryCacheEnabled = repositoryCacheConfig !== false
|
||||||
const remoteCacheEnabled = core.getBooleanInput('remote-cache')
|
|
||||||
if (remoteCacheEnabled) {
|
|
||||||
bazelrc.push(`build --remote_cache=${remoteCacheServerUrl}`)
|
|
||||||
if (diskCacheEnabled) {
|
|
||||||
core.error('Disk cache and remote cache cannot be enabled at the same time')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const repositoryCacheConfig = core.getInput('repository-cache')
|
|
||||||
const repositoryCacheEnabled = repositoryCacheConfig !== 'false'
|
|
||||||
let repositoryCacheFiles = [
|
let repositoryCacheFiles = [
|
||||||
'MODULE.bazel',
|
`${moduleRoot}/MODULE.bazel`,
|
||||||
'WORKSPACE.bazel',
|
`${moduleRoot}/WORKSPACE.bazel`,
|
||||||
'WORKSPACE.bzlmod',
|
`${moduleRoot}/WORKSPACE.bzlmod`,
|
||||||
'WORKSPACE'
|
`${moduleRoot}/WORKSPACE`
|
||||||
]
|
]
|
||||||
if (repositoryCacheEnabled) {
|
if (repositoryCacheEnabled) {
|
||||||
bazelrc.push(`build --repository_cache=${bazelRepository}`)
|
bazelrc.push(`common --repository_cache=${bazelRepository}`)
|
||||||
if (repositoryCacheConfig !== 'true') {
|
if (repositoryCacheConfig !== true) {
|
||||||
repositoryCacheFiles = Array(repositoryCacheConfig).flat()
|
repositoryCacheFiles = Array(repositoryCacheConfig).flat()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -74,13 +80,14 @@ if (repositoryCacheEnabled) {
|
||||||
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) {
|
||||||
|
|
@ -93,10 +100,10 @@ if (externalCacheConfig) {
|
||||||
externalCache.baseCacheKey = `${baseCacheKey}-external-`
|
externalCache.baseCacheKey = `${baseCacheKey}-external-`
|
||||||
externalCache.manifest = {
|
externalCache.manifest = {
|
||||||
files: [
|
files: [
|
||||||
'MODULE.bazel',
|
`${moduleRoot}/MODULE.bazel`,
|
||||||
'WORKSPACE.bazel',
|
`${moduleRoot}/WORKSPACE.bazel`,
|
||||||
'WORKSPACE.bzlmod',
|
`${moduleRoot}/WORKSPACE.bzlmod`,
|
||||||
'WORKSPACE'
|
`${moduleRoot}/WORKSPACE`
|
||||||
],
|
],
|
||||||
name: `external-${manifestName}-manifest`,
|
name: `external-${manifestName}-manifest`,
|
||||||
path: `${os.tmpdir()}/external-cache-manifest.txt`
|
path: `${os.tmpdir()}/external-cache-manifest.txt`
|
||||||
|
|
@ -104,10 +111,10 @@ if (externalCacheConfig) {
|
||||||
externalCache.default = {
|
externalCache.default = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
files: [
|
files: [
|
||||||
'MODULE.bazel',
|
`${moduleRoot}/MODULE.bazel`,
|
||||||
'WORKSPACE.bazel',
|
`${moduleRoot}/WORKSPACE.bazel`,
|
||||||
'WORKSPACE.bzlmod',
|
`${moduleRoot}/WORKSPACE.bzlmod`,
|
||||||
'WORKSPACE'
|
`${moduleRoot}/WORKSPACE`
|
||||||
],
|
],
|
||||||
name: (name) => { return `external-${name}` },
|
name: (name) => { return `external-${name}` },
|
||||||
paths: (name) => {
|
paths: (name) => {
|
||||||
|
|
@ -126,11 +133,15 @@ if (externalCacheConfig) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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`)]
|
||||||
},
|
},
|
||||||
|
|
@ -139,8 +150,9 @@ module.exports = {
|
||||||
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]
|
||||||
|
|
@ -161,9 +173,4 @@ module.exports = {
|
||||||
name: 'repository',
|
name: 'repository',
|
||||||
paths: [bazelRepository]
|
paths: [bazelRepository]
|
||||||
},
|
},
|
||||||
remoteCache: {
|
|
||||||
enabled: remoteCacheEnabled,
|
|
||||||
logPath: remoteCacheLogPath,
|
|
||||||
url: remoteCacheServerUrl,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
109277
dist/main/index.js
vendored
109277
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
50
dist/main/remote-cache-server.js
vendored
50
dist/main/remote-cache-server.js
vendored
|
|
@ -1,50 +0,0 @@
|
||||||
const http = require('http')
|
|
||||||
const cache = require('@actions/cache')
|
|
||||||
const fs = require('fs')
|
|
||||||
|
|
||||||
// https://bazel.build/remote/caching#http-caching
|
|
||||||
const server = http.createServer(async (req, res) => {
|
|
||||||
const { method, url } = req
|
|
||||||
const [, , cacheType, sha] = url.split('/')
|
|
||||||
const filePath = `/tmp/cache-${cacheType}-${sha}`
|
|
||||||
|
|
||||||
if (method === 'GET') {
|
|
||||||
try {
|
|
||||||
const cacheId = await cache.restoreCache([filePath], sha)
|
|
||||||
if (!cacheId) {
|
|
||||||
console.log(`Cache miss for ${sha}`)
|
|
||||||
res.writeHead(404)
|
|
||||||
return res.end('Cache miss')
|
|
||||||
}
|
|
||||||
const data = fs.readFileSync(filePath)
|
|
||||||
res.writeHead(200, { 'Content-Type': 'application/octet-stream' })
|
|
||||||
res.end(data)
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error retrieving cache for ${sha}: ${error}`)
|
|
||||||
res.writeHead(500)
|
|
||||||
res.end('Internal Server Error')
|
|
||||||
}
|
|
||||||
} else if (method === 'PUT') {
|
|
||||||
const data = []
|
|
||||||
req.on('data', chunk => data.push(chunk))
|
|
||||||
req.on('end', async () => {
|
|
||||||
try {
|
|
||||||
fs.writeFileSync(filePath, Buffer.concat(data))
|
|
||||||
await cache.saveCache([filePath], sha)
|
|
||||||
console.log(`Cache saved for ${sha}`)
|
|
||||||
res.writeHead(201)
|
|
||||||
res.end('Cache saved')
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error saving cache for ${sha}: ${error}`)
|
|
||||||
res.writeHead(500)
|
|
||||||
res.end('Internal Server Error')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
res.writeHead(405)
|
|
||||||
res.end('Method Not Allowed')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const PORT = process.env.PORT || 8080
|
|
||||||
server.listen(PORT, () => console.log(`Server listening on port ${PORT}`))
|
|
||||||
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
106772
dist/post/index.js
vendored
106772
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
81946
dist/remote-cache-server/index.js
vendored
81946
dist/remote-cache-server/index.js
vendored
File diff suppressed because one or more lines are too long
1
dist/remote-cache-server/index.js.map
vendored
1
dist/remote-cache-server/index.js.map
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
78
index.js
78
index.js
|
|
@ -6,8 +6,6 @@ const github = require('@actions/github')
|
||||||
const glob = require('@actions/glob')
|
const glob = require('@actions/glob')
|
||||||
const tc = require('@actions/tool-cache')
|
const tc = require('@actions/tool-cache')
|
||||||
const config = require('./config')
|
const config = require('./config')
|
||||||
const { spawn } = require('child_process')
|
|
||||||
const path = require('path')
|
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -30,7 +28,6 @@ async function setupBazel() {
|
||||||
await restoreCache(config.diskCache)
|
await restoreCache(config.diskCache)
|
||||||
await restoreCache(config.repositoryCache)
|
await restoreCache(config.repositoryCache)
|
||||||
await restoreExternalCaches(config.externalCache)
|
await restoreExternalCaches(config.externalCache)
|
||||||
await startRemoteCacheServer()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setupBazelisk() {
|
async function setupBazelisk() {
|
||||||
|
|
@ -41,7 +38,7 @@ async function setupBazelisk() {
|
||||||
core.startGroup('Setup Bazelisk')
|
core.startGroup('Setup Bazelisk')
|
||||||
let toolPath = tc.find('bazelisk', config.bazeliskVersion)
|
let toolPath = tc.find('bazelisk', config.bazeliskVersion)
|
||||||
if (toolPath) {
|
if (toolPath) {
|
||||||
core.info(`Found in cache @ ${toolPath}`)
|
core.debug(`Found in cache @ ${toolPath}`)
|
||||||
} else {
|
} else {
|
||||||
toolPath = await downloadBazelisk()
|
toolPath = await downloadBazelisk()
|
||||||
}
|
}
|
||||||
|
|
@ -72,8 +69,10 @@ async function downloadBazelisk() {
|
||||||
filename = `${filename}.exe`
|
filename = `${filename}.exe`
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = core.getInput('token')
|
const token = process.env.BAZELISK_GITHUB_TOKEN
|
||||||
const octokit = github.getOctokit(token)
|
const octokit = github.getOctokit(token, {
|
||||||
|
baseUrl: 'https://api.github.com'
|
||||||
|
})
|
||||||
const { data: releases } = await octokit.rest.repos.listReleases({
|
const { data: releases } = await octokit.rest.repos.listReleases({
|
||||||
owner: 'bazelbuild',
|
owner: 'bazelbuild',
|
||||||
repo: 'bazelisk'
|
repo: 'bazelisk'
|
||||||
|
|
@ -92,21 +91,17 @@ async function downloadBazelisk() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = asset.browser_download_url
|
const url = asset.browser_download_url
|
||||||
core.info(`Downloading from ${url}`)
|
core.debug(`Downloading from ${url}`)
|
||||||
const downloadPath = await tc.downloadTool(url, undefined, `token ${token}`)
|
const downloadPath = await tc.downloadTool(url, undefined, `token ${token}`)
|
||||||
|
|
||||||
core.debug('Adding to the cache...')
|
core.debug('Adding to the cache...');
|
||||||
fs.chmodSync(downloadPath, '755')
|
fs.chmodSync(downloadPath, '755');
|
||||||
|
let bazel_name = "bazel";
|
||||||
let bazelBinName = 'bazel'
|
|
||||||
let bazeliskBinName = 'bazelisk'
|
|
||||||
if (platform == 'windows') {
|
if (platform == 'windows') {
|
||||||
bazelBinName = `${bazelBinName}.exe`
|
bazel_name = `${bazel_name}.exe`
|
||||||
bazeliskBinName = `${bazelBinName}.exe`
|
|
||||||
}
|
}
|
||||||
|
const cachePath = await tc.cacheFile(downloadPath, bazel_name, 'bazelisk', version)
|
||||||
const cachePath = await tc.cacheFile(downloadPath, bazelBinName, bazeliskBinName, version)
|
core.debug(`Successfully cached bazelisk to ${cachePath}`)
|
||||||
core.info(`Successfully cached bazelisk to ${cachePath}`)
|
|
||||||
|
|
||||||
return cachePath
|
return cachePath
|
||||||
}
|
}
|
||||||
|
|
@ -138,14 +133,16 @@ 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: cacheConfig[name]?.enabled ?? cacheConfig.default.enabled,
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,9 +152,10 @@ async function restoreCache(cacheConfig) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -180,31 +178,11 @@ async function restoreCache(cacheConfig) {
|
||||||
} else {
|
} else {
|
||||||
core.info(`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()
|
||||||
}())
|
|
||||||
}
|
|
||||||
|
|
||||||
async function startRemoteCacheServer() {
|
|
||||||
if (!config.remoteCache.enabled) {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
core.startGroup("Start remote cache server")
|
|
||||||
core.info(`Remote cache server log file path: ${config.remoteCache.logPath}`)
|
|
||||||
|
|
||||||
const log = fs.openSync(config.remoteCache.logPath, 'a')
|
|
||||||
const remoteCacheServer = path.join(__dirname, '..', 'remote-cache-server', 'index.js')
|
|
||||||
const serverProcess = spawn(process.execPath, [remoteCacheServer], {
|
|
||||||
detached: true,
|
|
||||||
stdio: ['ignore', log, log]
|
|
||||||
})
|
|
||||||
|
|
||||||
core.info(`Started remote cache server with PID: ${serverProcess.pid}`)
|
|
||||||
core.saveState('remote-cache-server-pid', serverProcess.pid.toString())
|
|
||||||
|
|
||||||
serverProcess.unref()
|
|
||||||
core.endGroup()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
|
|
||||||
1009
package-lock.json
generated
1009
package-lock.json
generated
File diff suppressed because it is too large
Load diff
16
package.json
16
package.json
|
|
@ -1,23 +1,23 @@
|
||||||
{
|
{
|
||||||
"name": "setup-bazel",
|
"name": "setup-bazel",
|
||||||
"version": "0.8.4",
|
"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": "20.x"
|
"node": "24.x"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "ncc build index.js -s -o dist/main && ncc build post.js -s -o dist/post && ncc build remote-cache-server.js -s -o dist/remote-cache-server",
|
"build": "ncc build index.js -s -o dist/main && ncc build post.js -s -o dist/post",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"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",
|
||||||
"@actions/tool-cache": "^2.0.1",
|
"@actions/tool-cache": "^4.0.0",
|
||||||
"@vercel/ncc": "^0.38.0",
|
"@vercel/ncc": "^0.38.0",
|
||||||
"yaml": "^2.2.1"
|
"yaml": "^2.2.1"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
post.js
32
post.js
|
|
@ -5,37 +5,19 @@ 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 stopRemoteCacheServer()
|
|
||||||
await saveCaches()
|
await saveCaches()
|
||||||
}
|
process.exit(0)
|
||||||
|
|
||||||
async function stopRemoteCacheServer() {
|
|
||||||
if (!config.remoteCache.enabled) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
core.startGroup("Stop remote cache server")
|
|
||||||
const pid = core.getState('remote-cache-server-pid')
|
|
||||||
if (pid) {
|
|
||||||
try {
|
|
||||||
process.kill(pid, 'SIGTERM')
|
|
||||||
core.info(`Stopped remote cache server with PID: ${pid}`)
|
|
||||||
} catch (error) {
|
|
||||||
core.error(`Failed to stop remote cache server with PID: ${pid}. Error: ${error}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const logPath = config.remoteCache.logPath
|
|
||||||
if (fs.existsSync(logPath)) {
|
|
||||||
const logContent = fs.readFileSync(logPath, 'utf8')
|
|
||||||
core.debug(`Remote cache server log:\n${logContent}`)
|
|
||||||
}
|
|
||||||
core.endGroup()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
const http = require('http')
|
|
||||||
const cache = require('@actions/cache')
|
|
||||||
const fs = require('fs')
|
|
||||||
|
|
||||||
// https://bazel.build/remote/caching#http-caching
|
|
||||||
const server = http.createServer(async (req, res) => {
|
|
||||||
const { method, url } = req
|
|
||||||
const [, , cacheType, sha] = url.split('/')
|
|
||||||
const cacheKey = `setup-bazel-1-remote-cache-${sha}`
|
|
||||||
const filePath = `/tmp/cache-${cacheType}-${sha}`
|
|
||||||
|
|
||||||
if (method === 'GET') {
|
|
||||||
try {
|
|
||||||
const cacheId = await cache.restoreCache([filePath], cacheKey)
|
|
||||||
if (!cacheId) {
|
|
||||||
console.log(`Cache miss for ${cacheKey}`)
|
|
||||||
res.writeHead(404)
|
|
||||||
return res.end('Cache miss')
|
|
||||||
}
|
|
||||||
const data = fs.readFileSync(filePath)
|
|
||||||
res.writeHead(200, { 'Content-Type': 'application/octet-stream' })
|
|
||||||
res.end(data)
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error retrieving cache for ${cacheKey}: ${error}`)
|
|
||||||
res.writeHead(500)
|
|
||||||
res.end('Internal Server Error')
|
|
||||||
}
|
|
||||||
} else if (method === 'PUT') {
|
|
||||||
const data = []
|
|
||||||
req.on('data', chunk => data.push(chunk))
|
|
||||||
req.on('end', async () => {
|
|
||||||
try {
|
|
||||||
fs.writeFileSync(filePath, Buffer.concat(data))
|
|
||||||
await cache.saveCache([filePath], cacheKey)
|
|
||||||
console.log(`Cache saved for ${cacheKey}`)
|
|
||||||
res.writeHead(201)
|
|
||||||
res.end('Cache saved')
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error saving cache for ${cacheKey}: ${error}`)
|
|
||||||
res.writeHead(500)
|
|
||||||
res.end('Internal Server Error')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
res.writeHead(405)
|
|
||||||
res.end('Method Not Allowed')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const PORT = process.env.PORT || 9889
|
|
||||||
server.listen(PORT, () => console.log(`Server listening on port ${PORT}`))
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue