Skip to content

Commit 932a6a0

Browse files
committed
chore: add Aspect bazelrc presets and align ci yaml pattern (#80)
1 parent 9f59e6d commit 932a6a0

19 files changed

+153
-88
lines changed

.aspect/bazelrc/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
user.bazelrc

.aspect/bazelrc/BUILD.bazel

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,14 @@
22

33
load("@aspect_bazel_lib//lib:bazelrc_presets.bzl", "write_aspect_bazelrc_presets")
44

5-
write_aspect_bazelrc_presets(name = "update_aspect_bazelrc_presets")
5+
write_aspect_bazelrc_presets(
6+
name = "update_aspect_bazelrc_presets",
7+
presets = [
8+
"ci",
9+
"convenience",
10+
"correctness",
11+
"debug",
12+
"javascript",
13+
"performance",
14+
],
15+
)

.aspect/bazelrc/bazel5.bazelrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

.aspect/bazelrc/bazel7.bazelrc

Lines changed: 0 additions & 11 deletions
This file was deleted.

.aspect/bazelrc/bazel7.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.github/workflows/bazel7.bazelrc

.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Import Aspect bazelrc presets
2-
import %workspace%/.aspect/bazelrc/bazel7.bazelrc
2+
try-import %workspace%/.aspect/bazelrc/bazel7.bazelrc
33
import %workspace%/.aspect/bazelrc/convenience.bazelrc
44
import %workspace%/.aspect/bazelrc/correctness.bazelrc
55
import %workspace%/.aspect/bazelrc/debug.bazelrc

.github/workflows/BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
load("@aspect_bazel_lib//lib:bazelrc_presets.bzl", "write_aspect_bazelrc_presets")
2+
3+
write_aspect_bazelrc_presets(
4+
name = "update_aspect_bazelrc_presets",
5+
presets = [
6+
"bazel6",
7+
"bazel7",
8+
],
9+
)
File renamed without changes.

.github/workflows/bazel7.bazelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Speed up all builds by not checking if external repository files have been modified.
2+
# Docs: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java#L244
3+
build --noexperimental_check_external_repository_files
4+
fetch --noexperimental_check_external_repository_files
5+
query --noexperimental_check_external_repository_files
6+
7+
# Directories used by sandboxed non-worker execution may be reused to avoid unnecessary setup costs.
8+
# Save time on Sandbox creation and deletion when many of the same kind of action run during the
9+
# build.
10+
# Docs: https://bazel.build/reference/command-line-reference#flag--reuse_sandbox_directories
11+
build --reuse_sandbox_directories

.github/workflows/ci.bazelrc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
# This file contains Bazel settings to apply on CI only.
2-
# It is referenced with a --bazelrc option in the call to bazel in ci.yaml
1+
# Directories caches by GitHub actions
2+
common --disk_cache=~/.cache/bazel-disk-cache
3+
common --repository_cache=~/.cache/bazel-repository-cache
34

45
# Debug where options came from
56
build --announce_rc
6-
# This directory is configured in GitHub actions to be persisted between runs.
7-
build --disk_cache=~/.cache/bazel
8-
build --repository_cache=~/.cache/bazel-repo
9-
# Don't rely on test logs being easily accessible from the test runner,
10-
# though it makes the log noisier.
11-
test --test_output=errors
7+
128
# Allows tests to run bazelisk-in-bazel, since this is the cache folder used
139
test --test_env=XDG_CACHE_HOME

.github/workflows/ci.yaml

Lines changed: 81 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,81 +18,117 @@ concurrency:
1818
cancel-in-progress: ${{ github.ref_name != 'main' }}
1919

2020
jobs:
21-
# matrix-prep-* steps dynamically generate a bit of JSON depending on whether our action has
22-
# access to repository secrets. When running on a pull_request from a fork, the author is
23-
# untrusted so the secret will be absent. Insanely complex for how simple this requirement is...
24-
# inspired from
25-
# https://stackoverflow.com/questions/65384420/how-to-make-a-github-action-matrix-element-conditional
26-
27-
matrix-prep-bazelversion:
28-
# Prepares the 'bazelversion' axis of the test matrix
21+
# Prepares dynamic test matrix values
22+
matrix-prep:
2923
runs-on: ubuntu-latest
3024
steps:
3125
- uses: actions/checkout@v4
32-
- id: bazel_7
33-
run: echo "bazelversion=$(head -n 1 .bazelversion)" >> $GITHUB_OUTPUT
26+
- id: bazel-version
27+
name: Prepare 'bazel-version' matrix axis
28+
run: |
29+
v=$(head -n 1 .bazelversion)
30+
m=${v::1}
31+
a=(
32+
"major:$m, version:\"$v\""
33+
"major:6, version:\"6.5.0\""
34+
)
35+
printf -v j '{%s},' "${a[@]}"
36+
echo "res=[${j%,}]" | tee -a $GITHUB_OUTPUT
37+
- id: os
38+
name: Prepare 'os' matrix axis
39+
# Only run MacOS and Windows on main branch (not PRs) to minimize minutes (billed at 10X and 2X respectively)
40+
# https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes
41+
run: |
42+
a=( ubuntu )
43+
if [[ "${{ github.ref_name }}" == "main" ]] || [[ "${{ github.head_ref }}" == *"macos"* ]]; then
44+
a+=( macos )
45+
fi
46+
if [[ "${{ github.ref_name }}" == "main" ]] || [[ "${{ github.head_ref }}" == *"windows"* ]]; then
47+
a+=( windows )
48+
fi
49+
printf -v j '"%s",' "${a[@]}"
50+
echo "res=[${j%,}]" | tee -a $GITHUB_OUTPUT
3451
outputs:
35-
# Will look like ["<version from .bazelversion>", ...]
36-
bazelversions: ${{ toJSON(steps.*.outputs.bazelversion) }}
52+
bazel-version: ${{ steps.bazel-version.outputs.res }}
53+
os: ${{ steps.os.outputs.res }}
3754

3855
test:
39-
# The type of runner that the job will run on
40-
runs-on: ubuntu-latest
41-
56+
runs-on: ${{ matrix.os }}-latest
4257
needs:
43-
- matrix-prep-bazelversion
44-
45-
# Run bazel test in each workspace
58+
- matrix-prep
4659
strategy:
4760
fail-fast: false
4861
matrix:
49-
bazelversion: ${{ fromJSON(needs.matrix-prep-bazelversion.outputs.bazelversions) }}
62+
bazel-version: ${{ fromJSON(needs.matrix-prep.outputs.bazel-version) }}
5063
bzlmod: [1, 0]
64+
os: ${{ fromJSON(needs.matrix-prep.outputs.os) }}
5165
folder:
5266
- "."
5367
- "e2e/workspace"
68+
exclude:
69+
# Don't test MacOS and Windows against secondary bazel version to minimize minutes (billed at 10X and 2X respectively)
70+
# https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes
71+
- os: macos
72+
bazel-version:
73+
major: 6
74+
- os: windows
75+
bazel-version:
76+
major: 6
77+
# TODO: fix toolchain issue on Windows in e2e/workspace
78+
# //module_test:module_test (54772d7): No matching toolchains found for types @@aspect_rules_cypress//cypress:toolchain_type.
79+
- os: windows
80+
folder: e2e/workspace
81+
# Don't test with bzlmod on Bazel 6 since we're using use_repo_rule which was added in Bazel 7
82+
- bzlmod: 1
83+
bazel-version:
84+
major: 6
5485

55-
# Steps represent a sequence of tasks that will be executed as part of the job
5686
steps:
57-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
5887
- uses: actions/checkout@v4
5988

60-
# Cache build and external artifacts so that the next ci build is incremental.
61-
# Because github action caches cannot be updated after a build, we need to
62-
# store the contents of each build in a unique cache key, then fall back to loading
63-
# it on the next ci run. We use hashFiles(...) in the key and restore-keys- with
64-
# the prefix to load the most recent cache for the branch on a cache miss. You
65-
# should customize the contents of hashFiles to capture any bazel input sources,
66-
# although this doesn't need to be perfect. If none of the input sources change
67-
# then a cache hit will load an existing cache and bazel won't have to do any work.
68-
# In the case of a cache miss, you want the fallback cache to contain most of the
69-
# previously built artifacts to minimize build time. The more precise you are with
70-
# hashFiles sources the less work bazel will have to do.
7189
- name: Mount bazel caches
7290
uses: actions/cache@v3
7391
with:
7492
path: |
75-
"~/.cache/bazel"
76-
"~/.cache/bazel-repo"
77-
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }}
78-
restore-keys: bazel-cache-
93+
~/.cache/bazel-disk-cache
94+
~/.cache/bazel-repository-cache
95+
~/.cache/xdg-cache
96+
key: bazel-cache-${{ matrix.bazel-version.version }}-${{ matrix.bzlmod }}-${{ matrix.os }}-${{ matrix.folder }}-${{ hashFiles('.bazelrc', '.bazelversion', '.bazeliskrc', '**/BUILD', '**/BUILD.bazel', '**/*.bzl', 'WORKSPACE', 'WORKSPACE.bazel', 'WORKSPACE.bzlmod', 'MODULE.bazel') }}
97+
restore-keys: bazel-cache-${{ matrix.bazel-version.version }}-${{ matrix.bzlmod }}-${{ matrix.os }}-${{ matrix.folder }}-
7998

8099
- name: Configure Bazel version
81100
working-directory: ${{ matrix.folder }}
82-
# Overwrite the .bazelversion instead of using USE_BAZEL_VERSION so that Bazelisk
83-
# still bootstraps Aspect CLI from configuration in .bazeliskrc. Aspect CLI will
84-
# then use .bazelversion to determine which Bazel version to use
85-
run: echo "${{ matrix.bazelversion }}" > .bazelversion
101+
shell: bash
102+
run: |
103+
# Overwrite the .bazelversion instead of using USE_BAZEL_VERSION so that Bazelisk
104+
# still bootstraps Aspect CLI from configuration in .bazeliskrc. Aspect CLI will
105+
# then use .bazelversion to determine which Bazel version to use.
106+
echo "${{ matrix.bazel-version.version }}" > .bazelversion
107+
# Delete all the version specific bazelrc files that are used for local development
108+
# since the version we're testing against is dynamic. These are just symlinks and the
109+
# root .bazelrc brings these in with try-imports. In this CI workflows, we explicitly
110+
# bring in the version specific bazelrc file with --bazelrc when we invoke bazel.
111+
rm ${GITHUB_WORKSPACE//\\/\/}/.aspect/bazelrc/bazel*.bazelrc
112+
113+
# TODO: remove this block once we have Aspect CLI Windows releases
114+
- name: Don't use Aspect CLI on Windows
115+
if: matrix.os == 'windows'
116+
working-directory: ${{ matrix.folder }}
117+
shell: bash
118+
run: rm -f .bazeliskrc
86119

87120
- name: bazel test //...
88-
env:
89-
# Bazelisk will download bazel to here, ensure it is cached between runs.
90-
XDG_CACHE_HOME: ~/.cache/bazel-repo
91121
working-directory: ${{ matrix.folder }}
122+
shell: bash
92123
run: |
93124
bazel \
94-
--bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc \
95-
--bazelrc=.bazelrc \
125+
--bazelrc=${GITHUB_WORKSPACE//\\/\/}/.github/workflows/bazel${{ matrix.bazel-version.major }}.bazelrc \
126+
--bazelrc=${GITHUB_WORKSPACE//\\/\/}/.aspect/bazelrc/ci.bazelrc \
127+
--bazelrc=${GITHUB_WORKSPACE//\\/\/}/.github/workflows/ci.bazelrc \
96128
test \
129+
--test_tag_filters=-skip-on-bazel${{ matrix.bazel-version.major }} \
130+
--build_tag_filters=-skip-on-bazel${{ matrix.bazel-version.major }} \
97131
--enable_bzlmod=${{ matrix.bzlmod }} \
98132
//...
133+
env:
134+
XDG_CACHE_HOME: ~/.cache/xdg-cache # bazelisk will download bazel to here

.gitignore

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
bazel-*
22
.bazelrc.user
3+
node_modules/
4+
.pnpm-*
5+
36
.idea/
47
.ijwb/
5-
node_modules
8+
.vscode
9+
.DS_Store
610

7-
# Don't commit lockfile for now as it is unstable. Do allow for it to be
8-
# created, however, since it gives a performance boost for local development.
9-
# https://github.com/bazelbuild/bazel/issues/19026
10-
# https://github.com/bazelbuild/bazel/issues/19621
11-
# https://github.com/bazelbuild/bazel/issues/19971
12-
# https://github.com/bazelbuild/bazel/issues/20272
13-
# https://github.com/bazelbuild/bazel/issues/20369
11+
# Bazel's MODULE lockfile isn't ready to check in yet as of Bazel 7.1.
12+
# Do allow for it to be created, however, since it gives a performance boost for local development.
13+
# [Store resolved repository attributes in the Bzlmod lockfile](https://github.com/bazelbuild/bazel/issues/19026)
14+
# [MODULE.bazel.lock file contains user specific paths](https://github.com/bazelbuild/bazel/issues/19621)
15+
# [Consider skipping bazel_tools@_ from lockfile](https://github.com/bazelbuild/bazel/issues/19971)
16+
# [MODULE.bazel.lock file "reads through" already-locked package manager](https://github.com/bazelbuild/bazel/issues/20272)
17+
# [moduleFileHash in MODULE.bazel.lock causes frequent Git merge conflicts](https://github.com/bazelbuild/bazel/issues/20369)
1418
MODULE.bazel.lock

.npmrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on
2+
# projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what
3+
# rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules)
4+
hoist=false

docs/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ stardoc_with_diff_test(
1212
bzl_library_target = "@aspect_rules_cypress//cypress:repositories",
1313
)
1414

15-
update_docs(name = "update")
15+
update_docs(
16+
name = "update",
17+
tags = ["skip-on-bazel6"], # slight docs difference in Bazel 6
18+
)

e2e/workspace/.bazelrc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Import Aspect bazelrc presets
2-
import ../../.aspect/bazelrc/bazel7.bazelrc
3-
import ../../.aspect/bazelrc/convenience.bazelrc
4-
import ../../.aspect/bazelrc/correctness.bazelrc
5-
import ../../.aspect/bazelrc/debug.bazelrc
6-
import ../../.aspect/bazelrc/javascript.bazelrc
7-
import ../../.aspect/bazelrc/performance.bazelrc
2+
try-import %workspace%/../../.aspect/bazelrc/bazel7.bazelrc
3+
import %workspace%/../../.aspect/bazelrc/convenience.bazelrc
4+
import %workspace%/../../.aspect/bazelrc/correctness.bazelrc
5+
import %workspace%/../../.aspect/bazelrc/debug.bazelrc
6+
import %workspace%/../../.aspect/bazelrc/javascript.bazelrc
7+
import %workspace%/../../.aspect/bazelrc/performance.bazelrc
88

99
### YOUR PROJECT SPECIFIC OPTIONS GO HERE ###
1010

1111
# Load any settings & overrides specific to the current user from `.aspect/bazelrc/user.bazelrc`.
1212
# This file should appear in `.gitignore` so that settings are not shared with team members. This
1313
# should be last statement in this config so the user configuration is able to overwrite flags from
1414
# this file. See https://bazel.build/configure/best-practices#bazelrc-file.
15-
try-import ../../.aspect/bazelrc/user.bazelrc
15+
try-import %workspace%/../../.aspect/bazelrc/user.bazelrc

e2e/workspace/.bazelversion

Lines changed: 0 additions & 1 deletion
This file was deleted.

e2e/workspace/.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.bazelversion

e2e/workspace/.npmrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on
2+
# projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what
3+
# rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules)
4+
hoist=false
File renamed without changes.

e2e/workspace/MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ bazel_dep(name = "bazel_features", version = "1.9.0", dev_dependency = True)
1616
npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
1717
npm.npm_translate_lock(
1818
name = "npm",
19+
npmrc = "//:.npmrc",
1920
pnpm_lock = "//:pnpm-lock.yaml",
2021
verify_node_modules_ignored = "//:.bazelignore",
2122
)

e2e/workspace/WORKSPACE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")
4444

4545
npm_translate_lock(
4646
name = "npm",
47+
npmrc = "//:.npmrc",
4748
pnpm_lock = "//:pnpm-lock.yaml",
4849
verify_node_modules_ignored = "//:.bazelignore",
4950
)

0 commit comments

Comments
 (0)