Add module-root option for changing module location within the repository (#69)

This commit is contained in:
Caleb Zulawski 2025-02-21 10:17:33 -05:00 committed by GitHub
parent 98248079ae
commit e0e802d0ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 82 additions and 5809 deletions

View file

@ -173,6 +173,14 @@ Default `""`.
``` ```
</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` ### `output-base`
Change Bazel output base directory. Change Bazel output base directory.

View file

@ -29,6 +29,10 @@ inputs:
description: Google Cloud account key for remote cache description: Google Cloud account key for remote cache
required: false required: false
default: "" default: ""
module-root:
description: Bazel module root directory. Default is `.`
required: false
default: "."
output-base: output-base:
description: Bazel output base directory. Default is $HOME/.cache/bazel (POSIX) or D:/_bazel (Windows) description: Bazel output base directory. Default is $HOME/.cache/bazel (POSIX) or D:/_bazel (Windows)
required: false required: false

View file

@ -7,6 +7,7 @@ const github = require('@actions/github')
const bazeliskVersion = core.getInput('bazelisk-version') const bazeliskVersion = core.getInput('bazelisk-version')
const cacheVersion = core.getInput('cache-version') const cacheVersion = core.getInput('cache-version')
const externalCacheConfig = yaml.parse(core.getInput('external-cache')) 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()
@ -56,10 +57,10 @@ if (diskCacheEnabled) {
const repositoryCacheConfig = core.getInput('repository-cache') const repositoryCacheConfig = core.getInput('repository-cache')
const repositoryCacheEnabled = repositoryCacheConfig !== 'false' 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(`common --repository_cache=${bazelRepository}`) bazelrc.push(`common --repository_cache=${bazelRepository}`)
@ -90,10 +91,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`
@ -101,10 +102,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) => {
@ -130,7 +131,7 @@ module.exports = {
baseCacheKey, baseCacheKey,
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`)]
}, },
@ -140,8 +141,8 @@ module.exports = {
enabled: diskCacheEnabled, enabled: diskCacheEnabled,
files: [ files: [
...repositoryCacheFiles, ...repositoryCacheFiles,
'**/BUILD.bazel', `${moduleRoot}/**/BUILD.bazel`,
'**/BUILD' `${moduleRoot}/**/BUILD`
], ],
name: diskCacheName, name: diskCacheName,
paths: [bazelDisk] paths: [bazelDisk]

2922
dist/main/index.js vendored

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

2922
dist/post/index.js vendored

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long