Compare commits
No commits in common. "main" and "0.5.0" have entirely different histories.
17 changed files with 102854 additions and 119702 deletions
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
|
@ -6,7 +6,7 @@ on:
|
|||
- main
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
group: ${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
|
|
@ -19,7 +19,7 @@ jobs:
|
|||
- ubuntu
|
||||
- windows
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ./
|
||||
- if: failure() && runner.debug == '1'
|
||||
uses: mxschmitt/action-tmate@v3
|
||||
|
|
|
|||
37
.github/workflows/release.yml
vendored
37
.github/workflows/release.yml
vendored
|
|
@ -1,37 +0,0 @@
|
|||
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 24.14.0
|
||||
nodejs 16.15.0
|
||||
|
|
|
|||
292
README.md
292
README.md
|
|
@ -3,19 +3,6 @@
|
|||
This action allows to properly configure Bazelisk and Bazel on all operating systems
|
||||
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
|
||||
|
||||
### `bazelisk-cache`
|
||||
|
|
@ -33,80 +20,12 @@ 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`
|
||||
|
||||
Extra contents to write to a user's [`bazelrc`][4] file.
|
||||
|
||||
You can use multiline YAML strings.
|
||||
|
||||
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`
|
||||
|
||||
Enable [`disk_cache`][2] and store it on GitHub based on contents of `BUILD` files.
|
||||
|
|
@ -115,175 +34,92 @@ You can also pass a string to use as a cache key to separate caches from differe
|
|||
|
||||
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`
|
||||
|
||||
Cache `external/` repositories based on contents of `MODULE.bazel` and `WORKSPACE` files.
|
||||
Cache `external/` repositories based on contents of a `WORKSPACE` file.
|
||||
Only repositories exceeding 10MB are being cached.
|
||||
Each repository is stored in a separate cache.
|
||||
|
||||
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.
|
||||
You can also pass a YAML 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.
|
||||
|
||||
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`
|
||||
|
||||
Enable [`repository_cache`][3] and store it on GitHub based on contents of `MODULE.bazel` and `WORKSPACE` files.
|
||||
|
||||
You can also pass a file (or list of files) which contents are used to calculate cache key.
|
||||
Enable [`repository_cache`][3] and store it on GitHub based on contents of a `WORKSPACE` file.
|
||||
|
||||
Default `false`.
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
## Examples
|
||||
|
||||
#### Store a single repository cache
|
||||
### Simple configuration
|
||||
|
||||
```yaml
|
||||
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||
with:
|
||||
repository-cache: true
|
||||
```
|
||||
```yaml
|
||||
- uses: p0deje/setup-bazel@0.4.0
|
||||
```
|
||||
|
||||
#### Store a repository cache from a custom location
|
||||
### Custom Bazelisk version
|
||||
|
||||
```yaml
|
||||
- uses: bazel-contrib/setup-bazel@0.18.0
|
||||
with:
|
||||
repository-cache: examples/gem/WORKSPACE
|
||||
```
|
||||
```yaml
|
||||
- uses: p0deje/setup-bazel@0.4.0
|
||||
with:
|
||||
bazelisk-version: 1.19.0
|
||||
```
|
||||
|
||||
#### 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>
|
||||
### Additional `.bazelrc` options
|
||||
|
||||
```yaml
|
||||
- uses: p0deje/setup-bazel@0.4.0
|
||||
with:
|
||||
bazelrc: |
|
||||
build --show_timestamps
|
||||
```
|
||||
|
||||
### Full caching enabled
|
||||
|
||||
```yaml
|
||||
- uses: p0deje/setup-bazel@0.4.0
|
||||
with:
|
||||
bazelisk-cache: true
|
||||
disk-cache: true
|
||||
external-cache: true
|
||||
repository-cache: true
|
||||
```
|
||||
|
||||
### Separate disk cache between workflows
|
||||
|
||||
```yaml
|
||||
- uses: p0deje/setup-bazel@0.4.0
|
||||
with:
|
||||
disk-cache: ${{ github.workflow }}}
|
||||
```
|
||||
|
||||
### Cache external repository based on different files
|
||||
|
||||
```yaml
|
||||
- uses: p0deje/setup-bazel@0.4.0
|
||||
with:
|
||||
external-cache: |
|
||||
manifest:
|
||||
npm: package-lock.json
|
||||
```
|
||||
|
||||
### Disable individual external repositories conditionally
|
||||
|
||||
```yaml
|
||||
- uses: p0deje/setup-bazel@0.4.0
|
||||
with:
|
||||
external-cache: |
|
||||
manifest:
|
||||
ruby: ${{ matrix.os == 'windows' && 'false' || '.ruby-version' }}
|
||||
```
|
||||
|
||||
## Migrating from [`bazelbuild/setup-bazelisk`][6]
|
||||
|
||||
You can simply replace `bazelbuild/setup-bazelisk` action with `bazel-contrib/setup-bazel`.
|
||||
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].
|
||||
|
||||
## Development
|
||||
|
||||
To build action, run the following command:
|
||||
|
||||
```sh
|
||||
$ npm install
|
||||
$ npm run build
|
||||
```
|
||||
|
||||
## Release
|
||||
|
||||
Use [Release][10] workflow to cut a new release.
|
||||
|
||||
|
||||
[1]: https://github.com/bazelbuild/bazelisk
|
||||
[2]: https://bazel.build/remote/caching#disk-cache
|
||||
|
|
@ -293,5 +129,3 @@ Use [Release][10] workflow to cut a new release.
|
|||
[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
|
||||
|
|
|
|||
23
action.yml
23
action.yml
|
|
@ -1,5 +1,5 @@
|
|||
name: Setup Bazel environment
|
||||
description: Setup a Bazel environment, including Bazelisk and fine-grained caching
|
||||
name: Setup Bazel
|
||||
description: Configure Bazel(isk) and its caches
|
||||
|
||||
inputs:
|
||||
bazelisk-cache:
|
||||
|
|
@ -13,10 +13,6 @@ inputs:
|
|||
description: Extra contents to write to user .bazelrc
|
||||
required: false
|
||||
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:
|
||||
description: Version of all caches
|
||||
required: false
|
||||
|
|
@ -26,23 +22,15 @@ inputs:
|
|||
required: false
|
||||
default: "false"
|
||||
external-cache:
|
||||
description: Cache external 10MB+ repositories based on MODULE.bazel/WORKSPACE
|
||||
description: Cache external 10MB+ repositories based on WORKSPACE
|
||||
required: false
|
||||
default: ""
|
||||
google-credentials:
|
||||
description: Google Cloud account key for remote cache
|
||||
required: false
|
||||
default: ""
|
||||
module-root:
|
||||
description: Bazel module root directory. Default is `.`
|
||||
required: 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
|
||||
description: Cache repositories based on WORKSPACE
|
||||
required: false
|
||||
default: "false"
|
||||
token:
|
||||
|
|
@ -51,7 +39,6 @@ inputs:
|
|||
default: ${{ github.token }}
|
||||
|
||||
runs:
|
||||
using: node20
|
||||
using: node16
|
||||
main: dist/main/index.js
|
||||
post: dist/post/index.js
|
||||
post-if: "!cancelled()"
|
||||
|
|
|
|||
73
config.js
73
config.js
|
|
@ -5,30 +5,16 @@ const core = require('@actions/core')
|
|||
const github = require('@actions/github')
|
||||
|
||||
const bazeliskVersion = core.getInput('bazelisk-version')
|
||||
const cacheSave = core.getBooleanInput('cache-save')
|
||||
const cacheVersion = core.getInput('cache-version')
|
||||
const moduleRoot = core.getInput('module-root')
|
||||
const externalCacheConfig = yaml.parse(core.getInput('external-cache'))
|
||||
|
||||
const homeDir = os.homedir()
|
||||
const arch = os.arch()
|
||||
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 bazelRepository = core.toPosixPath(`${homeDir}/.cache/bazel-repo`)
|
||||
let bazelOutputBase = `${homeDir}/.bazel`
|
||||
let bazelrcPaths = [core.toPosixPath(`${homeDir}/.bazelrc`)]
|
||||
let userCacheDir = `${homeDir}/.cache`
|
||||
|
||||
|
|
@ -37,8 +23,9 @@ switch (platform) {
|
|||
userCacheDir = `${homeDir}/Library/Caches`
|
||||
break
|
||||
case 'win32':
|
||||
bazelDisk = `${bazelOutputBase}-disk`
|
||||
bazelRepository = `${bazelOutputBase}-repo`
|
||||
bazelDisk = 'D:/_bazel-disk'
|
||||
bazelRepository = 'D:/_bazel-repo'
|
||||
bazelOutputBase = 'D:/_bazel'
|
||||
userCacheDir = `${homeDir}/AppData/Local`
|
||||
if (process.env.HOME) {
|
||||
bazelrcPaths.push(core.toPosixPath(`${process.env.HOME}/.bazelrc`))
|
||||
|
|
@ -46,48 +33,34 @@ switch (platform) {
|
|||
break
|
||||
}
|
||||
|
||||
const baseCacheKey = `setup-bazel-${cacheVersion}-${platform}-${arch}`
|
||||
const baseCacheKey = `setup-bazel-${cacheVersion}-${platform}`
|
||||
const bazelrc = core.getMultilineInput('bazelrc')
|
||||
|
||||
const diskCacheConfig = core.getInput('disk-cache')
|
||||
const diskCacheEnabled = diskCacheConfig !== 'false'
|
||||
let diskCacheName = 'disk'
|
||||
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}`)
|
||||
if (diskCacheName !== 'true') {
|
||||
diskCacheName = `${diskCacheName}-${diskCacheConfig}`
|
||||
}
|
||||
}
|
||||
|
||||
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`
|
||||
]
|
||||
const repositoryCacheEnabled = core.getBooleanInput('repository-cache')
|
||||
if (repositoryCacheEnabled) {
|
||||
bazelrc.push(`common --repository_cache=${bazelRepository}`)
|
||||
if (repositoryCacheConfig !== true) {
|
||||
repositoryCacheFiles = Array(repositoryCacheConfig).flat()
|
||||
}
|
||||
bazelrc.push(`build --repository_cache=${bazelRepository}`)
|
||||
}
|
||||
|
||||
const googleCredentials = core.getInput('google-credentials')
|
||||
const googleCredentialsSaved = (core.getState('google-credentials-path').length > 0)
|
||||
if (googleCredentials.length > 0 && !googleCredentialsSaved) {
|
||||
const tmpDir = core.toPosixPath(fs.mkdtempSync(process.env.RUNNER_TEMP))
|
||||
const tmpDir = core.toPosixPath(fs.mkdtempSync(os.tmpdir()))
|
||||
const googleCredentialsPath = `${tmpDir}/key.json`
|
||||
fs.writeFileSync(googleCredentialsPath, googleCredentials)
|
||||
bazelrc.push(`build --google_credentials=${googleCredentialsPath}`)
|
||||
core.saveState('google-credentials-path', googleCredentialsPath)
|
||||
}
|
||||
|
||||
const externalCacheConfig = yaml.parse(core.getInput('external-cache'))
|
||||
const bazelExternal = core.toPosixPath(`${bazelOutputBase}/external`)
|
||||
const externalCache = {}
|
||||
if (externalCacheConfig) {
|
||||
|
|
@ -100,10 +73,8 @@ if (externalCacheConfig) {
|
|||
externalCache.baseCacheKey = `${baseCacheKey}-external-`
|
||||
externalCache.manifest = {
|
||||
files: [
|
||||
`${moduleRoot}/MODULE.bazel`,
|
||||
`${moduleRoot}/WORKSPACE.bazel`,
|
||||
`${moduleRoot}/WORKSPACE.bzlmod`,
|
||||
`${moduleRoot}/WORKSPACE`
|
||||
'WORKSPACE.bazel',
|
||||
'WORKSPACE'
|
||||
],
|
||||
name: `external-${manifestName}-manifest`,
|
||||
path: `${os.tmpdir()}/external-cache-manifest.txt`
|
||||
|
|
@ -111,10 +82,8 @@ if (externalCacheConfig) {
|
|||
externalCache.default = {
|
||||
enabled: true,
|
||||
files: [
|
||||
`${moduleRoot}/MODULE.bazel`,
|
||||
`${moduleRoot}/WORKSPACE.bazel`,
|
||||
`${moduleRoot}/WORKSPACE.bzlmod`,
|
||||
`${moduleRoot}/WORKSPACE`
|
||||
'WORKSPACE.bazel',
|
||||
'WORKSPACE'
|
||||
],
|
||||
name: (name) => { return `external-${name}` },
|
||||
paths: (name) => {
|
||||
|
|
@ -133,15 +102,11 @@ if (externalCacheConfig) {
|
|||
}
|
||||
}
|
||||
|
||||
const token = core.getInput('token')
|
||||
core.exportVariable('BAZELISK_GITHUB_TOKEN', token)
|
||||
|
||||
module.exports = {
|
||||
baseCacheKey,
|
||||
cacheSave,
|
||||
bazeliskCache: {
|
||||
enabled: core.getBooleanInput('bazelisk-cache'),
|
||||
files: [`${moduleRoot}/.bazelversion`],
|
||||
files: ['.bazelversion'],
|
||||
name: 'bazelisk',
|
||||
paths: [core.toPosixPath(`${userCacheDir}/bazelisk`)]
|
||||
},
|
||||
|
|
@ -150,9 +115,8 @@ module.exports = {
|
|||
diskCache: {
|
||||
enabled: diskCacheEnabled,
|
||||
files: [
|
||||
...repositoryCacheFiles,
|
||||
`${moduleRoot}/**/BUILD.bazel`,
|
||||
`${moduleRoot}/**/BUILD`
|
||||
'**/BUILD.bazel',
|
||||
'**/BUILD'
|
||||
],
|
||||
name: diskCacheName,
|
||||
paths: [bazelDisk]
|
||||
|
|
@ -169,7 +133,10 @@ module.exports = {
|
|||
},
|
||||
repositoryCache: {
|
||||
enabled: repositoryCacheEnabled,
|
||||
files: repositoryCacheFiles,
|
||||
files: [
|
||||
'WORKSPACE.bazel',
|
||||
'WORKSPACE'
|
||||
],
|
||||
name: 'repository',
|
||||
paths: [bazelRepository]
|
||||
},
|
||||
|
|
|
|||
111116
dist/main/index.js
vendored
111116
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
108612
dist/post/index.js
vendored
108612
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
68
index.js
68
index.js
|
|
@ -17,8 +17,8 @@ async function run() {
|
|||
|
||||
async function setupBazel() {
|
||||
core.startGroup('Configure Bazel')
|
||||
core.info('Configuration:')
|
||||
core.info(JSON.stringify(config, null, 2))
|
||||
console.log('Configuration:')
|
||||
console.log(JSON.stringify(config, null, 2))
|
||||
|
||||
await setupBazelrc()
|
||||
core.endGroup()
|
||||
|
|
@ -36,19 +36,18 @@ async function setupBazelisk() {
|
|||
}
|
||||
|
||||
core.startGroup('Setup Bazelisk')
|
||||
let toolPath = tc.find('bazelisk', config.bazeliskVersion)
|
||||
const toolPath = tc.find('bazelisk', config.bazeliskVersion)
|
||||
if (toolPath) {
|
||||
core.debug(`Found in cache @ ${toolPath}`)
|
||||
console.log(`Found in cache @ ${toolPath}`)
|
||||
} else {
|
||||
toolPath = await downloadBazelisk()
|
||||
await downloadBazelisk()
|
||||
}
|
||||
core.addPath(toolPath)
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
async function downloadBazelisk() {
|
||||
const version = config.bazeliskVersion
|
||||
core.debug(`Attempting to download ${version}`)
|
||||
console.log(`Attempting to download ${version}`)
|
||||
|
||||
// Possible values are 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x' and 'x64'.
|
||||
// Bazelisk filenames use 'amd64' and 'arm64'.
|
||||
|
|
@ -69,10 +68,8 @@ async function downloadBazelisk() {
|
|||
filename = `${filename}.exe`
|
||||
}
|
||||
|
||||
const token = process.env.BAZELISK_GITHUB_TOKEN
|
||||
const octokit = github.getOctokit(token, {
|
||||
baseUrl: 'https://api.github.com'
|
||||
})
|
||||
const token = core.getInput('token')
|
||||
const octokit = github.getOctokit(token)
|
||||
const { data: releases } = await octokit.rest.repos.listReleases({
|
||||
owner: 'bazelbuild',
|
||||
repo: 'bazelisk'
|
||||
|
|
@ -91,19 +88,15 @@ async function downloadBazelisk() {
|
|||
}
|
||||
|
||||
const url = asset.browser_download_url
|
||||
core.debug(`Downloading from ${url}`)
|
||||
console.log(`Downloading from ${url}`)
|
||||
const downloadPath = await tc.downloadTool(url, undefined, `token ${token}`)
|
||||
|
||||
core.debug('Adding to the cache...');
|
||||
console.log('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}`)
|
||||
const cachePath = await tc.cacheFile(downloadPath, 'bazel', 'bazelisk', version)
|
||||
console.log(`Successfully cached bazelisk to ${cachePath}`)
|
||||
|
||||
return cachePath
|
||||
core.addPath(cachePath)
|
||||
}
|
||||
|
||||
async function setupBazelrc() {
|
||||
|
|
@ -133,16 +126,14 @@ async function restoreExternalCaches(cacheConfig) {
|
|||
// Now restore all external caches defined in manifest
|
||||
if (fs.existsSync(path)) {
|
||||
const manifest = fs.readFileSync(path, { encoding: 'utf8' })
|
||||
const restorePromises = manifest.split('\n').filter(s => s)
|
||||
.map(name => {
|
||||
return restoreCache({
|
||||
enabled: cacheConfig[name]?.enabled ?? cacheConfig.default.enabled,
|
||||
files: cacheConfig[name]?.files || cacheConfig.default.files,
|
||||
name: cacheConfig.default.name(name),
|
||||
paths: cacheConfig.default.paths(name)
|
||||
});
|
||||
});
|
||||
await Promise.all(restorePromises);
|
||||
for (const name of manifest.split('\n').filter(s => s)) {
|
||||
await restoreCache({
|
||||
enabled: cacheConfig[name]?.enabled ?? cacheConfig.default.enabled,
|
||||
files: cacheConfig[name]?.files || cacheConfig.default.files,
|
||||
name: cacheConfig.default.name(name),
|
||||
paths: cacheConfig.default.paths(name)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -152,17 +143,16 @@ async function restoreCache(cacheConfig) {
|
|||
}
|
||||
|
||||
const delay = Math.random() * 1000 // timeout <= 1 sec to reduce 429 errors
|
||||
await setTimeout(delay)
|
||||
await setTimeout(delay, async function () {
|
||||
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 name = cacheConfig.name
|
||||
const paths = cacheConfig.paths
|
||||
const restoreKey = `${config.baseCacheKey}-${name}-`
|
||||
const key = `${restoreKey}${hash}`
|
||||
|
||||
core.debug(`Attempting to restore ${name} cache from ${key}`)
|
||||
console.log(`Attempting to restore ${name} cache from ${key}`)
|
||||
|
||||
const restoredKey = await cache.restoreCache(
|
||||
paths, key, [restoreKey],
|
||||
|
|
@ -170,19 +160,17 @@ async function restoreCache(cacheConfig) {
|
|||
)
|
||||
|
||||
if (restoredKey) {
|
||||
core.info(`Successfully restored cache from ${restoredKey}`)
|
||||
console.log(`Successfully restored cache from ${restoredKey}`)
|
||||
|
||||
if (restoredKey === key) {
|
||||
core.saveState(`${name}-cache-hit`, 'true')
|
||||
}
|
||||
} else {
|
||||
core.info(`Failed to restore ${name} cache`)
|
||||
console.log(`Failed to restore ${name} cache`)
|
||||
}
|
||||
} catch (err) {
|
||||
core.warning(`Failed to restore ${name} cache with error: ${err}`)
|
||||
} finally {
|
||||
|
||||
core.endGroup()
|
||||
}
|
||||
}())
|
||||
}
|
||||
|
||||
run()
|
||||
|
|
|
|||
1024
package-lock.json
generated
1024
package-lock.json
generated
File diff suppressed because it is too large
Load diff
16
package.json
16
package.json
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"name": "setup-bazel",
|
||||
"version": "0.18.0",
|
||||
"version": "0.4.0",
|
||||
"description": "Install and configure Bazel for GitHub Actions",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": "24.x"
|
||||
"node": "16.x"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "ncc build index.js -s -o dist/main && ncc build post.js -s -o dist/post",
|
||||
|
|
@ -13,12 +13,12 @@
|
|||
"author": "Alex Rodionov <p0deje@gmail.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^6.0.0",
|
||||
"@actions/core": "^3.0.0",
|
||||
"@actions/github": "^9.0.0",
|
||||
"@actions/glob": "^0.6.0",
|
||||
"@actions/tool-cache": "^4.0.0",
|
||||
"@vercel/ncc": "^0.38.0",
|
||||
"@actions/cache": "^3.2.2",
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@actions/glob": "^0.4.0",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"@vercel/ncc": "^0.36.0",
|
||||
"yaml": "^2.2.1"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
post.js
13
post.js
|
|
@ -5,19 +5,12 @@ const core = require('@actions/core')
|
|||
const glob = require('@actions/glob')
|
||||
const config = require('./config')
|
||||
const { getFolderSize } = require('./util')
|
||||
const process = require('node:process');
|
||||
|
||||
async function run() {
|
||||
await saveCaches()
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
async function saveCaches() {
|
||||
if (!config.cacheSave) {
|
||||
core.info('Cache saving is disabled (cache-save: false)')
|
||||
return
|
||||
}
|
||||
|
||||
await saveCache(config.bazeliskCache)
|
||||
await saveCache(config.diskCache)
|
||||
await saveCache(config.repositoryCache)
|
||||
|
|
@ -81,14 +74,12 @@ async function saveCache(cacheConfig) {
|
|||
const paths = cacheConfig.paths
|
||||
const hash = await glob.hashFiles(
|
||||
cacheConfig.files.join('\n'),
|
||||
undefined,
|
||||
// We don't want to follow symlinks as it's extremely slow on macOS.
|
||||
{ followSymbolicLinks: false }
|
||||
)
|
||||
const key = `${config.baseCacheKey}-${cacheConfig.name}-${hash}`
|
||||
core.debug(`Attempting to save ${paths} cache to ${key}`)
|
||||
console.log(`Attempting to save ${paths} cache to ${key}`)
|
||||
await cache.saveCache(paths, key)
|
||||
core.info('Successfully saved cache')
|
||||
console.log('Successfully saved cache')
|
||||
} catch (error) {
|
||||
core.warning(error.stack)
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:recommended"
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue