Skip to content

Commit c77baf0

Browse files
authored
chore: add Aspect bazelrc presets and align ci patterns (#607)
1 parent deb93a6 commit c77baf0

40 files changed

+468
-148
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"Aspect bazelrc presets; see https://docs.aspect.build/guides/bazelrc"
2+
3+
load("@aspect_bazel_lib//lib:bazelrc_presets.bzl", "write_aspect_bazelrc_presets")
4+
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/bazel7.bazelrc

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

.aspect/bazelrc/ci.bazelrc

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# We recommend enforcing a policy that keeps your CI from being slowed down
2+
# by individual test targets that should be optimized
3+
# or split up into multiple test targets with sharding or manually.
4+
# Set this flag to exclude targets that have their timeout set to eternal (>15m) from running on CI.
5+
# Docs: https://bazel.build/docs/user-manual#test-timeout-filters
6+
test --test_timeout_filters=-eternal
7+
8+
# Set this flag to enable re-tries of failed tests on CI.
9+
# When any test target fails, try one or more times. This applies regardless of whether the "flaky"
10+
# tag appears on the target definition.
11+
# This is a tradeoff: legitimately failing tests will take longer to report,
12+
# but we can paper over flaky tests that pass most of the time.
13+
# The alternative is to mark every flaky test with the `flaky = True` attribute, but this requires
14+
# the buildcop to make frequent code edits.
15+
# Not recommended for local builds so that the flakiness is observed during development and thus
16+
# is more likely to get fixed.
17+
# Note that when passing after the first attempt, Bazel will give a special "FLAKY" status.
18+
# Docs: https://bazel.build/docs/user-manual#flaky-test-attempts
19+
test --flaky_test_attempts=2
20+
21+
# Announce all announces command options read from the bazelrc file(s) when starting up at the
22+
# beginning of each Bazel invocation. This is very useful on CI to be able to inspect what Bazel rc
23+
# settings are being applied on each run.
24+
# Docs: https://bazel.build/docs/user-manual#announce-rc
25+
build --announce_rc
26+
27+
# Add a timestamp to each message generated by Bazel specifying the time at which the message was
28+
# displayed.
29+
# Docs: https://bazel.build/docs/user-manual#show-timestamps
30+
build --show_timestamps
31+
32+
# Only show progress every 60 seconds on CI.
33+
# We want to find a compromise between printing often enough to show that the build isn't stuck,
34+
# but not so often that we produce a long log file that requires a lot of scrolling.
35+
# https://bazel.build/reference/command-line-reference#flag--show_progress_rate_limit
36+
build --show_progress_rate_limit=60
37+
38+
# Use cursor controls in screen output.
39+
# Docs: https://bazel.build/docs/user-manual#curses
40+
build --curses=yes
41+
42+
# Use colors to highlight output on the screen. Set to `no` if your CI does not display colors.
43+
# Docs: https://bazel.build/docs/user-manual#color
44+
build --color=yes
45+
46+
# The terminal width in columns. Configure this to override the default value based on what your CI system renders.
47+
# Docs: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/runtime/UiOptions.java#L151
48+
build --terminal_columns=143
49+
50+
######################################
51+
# Generic remote cache configuration #
52+
######################################
53+
54+
# Only download remote outputs of top level targets to the local machine.
55+
# Docs: https://bazel.build/reference/command-line-reference#flag--remote_download_toplevel
56+
build --remote_download_toplevel
57+
58+
# The maximum amount of time to wait for remote execution and cache calls.
59+
# https://bazel.build/reference/command-line-reference#flag--remote_timeout
60+
build --remote_timeout=3600
61+
62+
# Upload locally executed action results to the remote cache.
63+
# Docs: https://bazel.build/reference/command-line-reference#flag--remote_upload_local_results
64+
build --remote_upload_local_results
65+
66+
# Fall back to standalone local execution strategy if remote execution fails. If the grpc remote
67+
# cache connection fails, it will fail the build, add this so it falls back to the local cache.
68+
# Docs: https://bazel.build/reference/command-line-reference#flag--remote_local_fallback
69+
build --remote_local_fallback
70+
71+
# Fixes builds hanging on CI that get the TCP connection closed without sending RST packets.
72+
# Docs: https://bazel.build/reference/command-line-reference#flag--grpc_keepalive_time
73+
build --grpc_keepalive_time=30s
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Attempt to build & test every target whose prerequisites were successfully built.
2+
# Docs: https://bazel.build/docs/user-manual#keep-going
3+
build --keep_going
4+
5+
# Output test errors to stderr so users don't have to `cat` or open test failure log files when test
6+
# fail. This makes the log noiser in exchange for reducing the time-to-feedback on test failures for
7+
# users.
8+
# Docs: https://bazel.build/docs/user-manual#test-output
9+
test --test_output=errors
10+
11+
# Show the output files created by builds that requested more than one target. This helps users
12+
# locate the build outputs in more cases
13+
# Docs: https://bazel.build/docs/user-manual#show-result
14+
build --show_result=20
15+
16+
# Bazel picks up host-OS-specific config lines from bazelrc files. For example, if the host OS is
17+
# Linux and you run bazel build, Bazel picks up lines starting with build:linux. Supported OS
18+
# identifiers are `linux`, `macos`, `windows`, `freebsd`, and `openbsd`. Enabling this flag is
19+
# equivalent to using `--config=linux` on Linux, `--config=windows` on Windows, etc.
20+
# Docs: https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config
21+
common --enable_platform_specific_config
22+
23+
# Output a heap dump if an OOM is thrown during a Bazel invocation
24+
# (including OOMs due to `--experimental_oom_more_eagerly_threshold`).
25+
# The dump will be written to `<output_base>/<invocation_id>.heapdump.hprof`.
26+
# You may need to configure CI to capture this artifact and upload for later use.
27+
# Docs: https://bazel.build/reference/command-line-reference#flag--heap_dump_on_oom
28+
common --heap_dump_on_oom
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Do not upload locally executed action results to the remote cache.
2+
# This should be the default for local builds so local builds cannot poison the remote cache.
3+
# It should be flipped to `--remote_upload_local_results` on CI
4+
# by using `--bazelrc=.aspect/bazelrc/ci.bazelrc`.
5+
# Docs: https://bazel.build/reference/command-line-reference#flag--remote_upload_local_results
6+
build --noremote_upload_local_results
7+
8+
# Don't allow network access for build actions in the sandbox.
9+
# Ensures that you don't accidentally make non-hermetic actions/tests which depend on remote
10+
# services.
11+
# Developers should tag targets with `tags=["requires-network"]` to opt-out of the enforcement.
12+
# Docs: https://bazel.build/reference/command-line-reference#flag--sandbox_default_allow_network
13+
build --sandbox_default_allow_network=false
14+
15+
# Warn if a test's timeout is significantly longer than the test's actual execution time.
16+
# Bazel's default for test_timeout is medium (5 min), but most tests should instead be short (1 min).
17+
# While a test's timeout should be set such that it is not flaky, a test that has a highly
18+
# over-generous timeout can hide real problems that crop up unexpectedly.
19+
# For instance, a test that normally executes in a minute or two should not have a timeout of
20+
# ETERNAL or LONG as these are much, much too generous.
21+
# Docs: https://bazel.build/docs/user-manual#test-verbose-timeout-warnings
22+
test --test_verbose_timeout_warnings
23+
24+
# Allow the Bazel server to check directory sources for changes. Ensures that the Bazel server
25+
# notices when a directory changes, if you have a directory listed in the srcs of some target.
26+
# Recommended when using
27+
# [copy_directory](https://github.com/aspect-build/bazel-lib/blob/main/docs/copy_directory.md) and
28+
# [rules_js](https://github.com/aspect-build/rules_js) since npm package are source directories
29+
# inputs to copy_directory actions.
30+
# Docs: https://bazel.build/reference/command-line-reference#flag--host_jvm_args
31+
startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1
32+
33+
# Allow exclusive tests to run in the sandbox. Fixes a bug where Bazel doesn't enable sandboxing for
34+
# tests with `tags=["exclusive"]`.
35+
# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_exclusive_test_sandboxed
36+
test --incompatible_exclusive_test_sandboxed
37+
38+
# Use a static value for `PATH` and does not inherit `LD_LIBRARY_PATH`. Doesn't let environment
39+
# variables like `PATH` sneak into the build, which can cause massive cache misses when they change.
40+
# Use `--action_env=ENV_VARIABLE` if you want to inherit specific environment variables from the
41+
# client, but note that doing so can prevent cross-user caching if a shared cache is used.
42+
# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_strict_action_env
43+
build --incompatible_strict_action_env
44+
45+
# Propagate tags from a target declaration to the actions' execution requirements.
46+
# Ensures that tags applied in your BUILD file, like `tags=["no-remote"]`
47+
# get propagated to actions created by the rule.
48+
# Without this option, you rely on rules authors to manually check the tags you passed
49+
# and apply relevant ones to the actions they create.
50+
# See https://github.com/bazelbuild/bazel/issues/8830 for details.
51+
# Docs: https://bazel.build/reference/command-line-reference#flag--experimental_allow_tags_propagation
52+
build --experimental_allow_tags_propagation
53+
fetch --experimental_allow_tags_propagation
54+
query --experimental_allow_tags_propagation
55+
56+
# Do not automatically create `__init__.py` files in the runfiles of Python targets. Fixes the wrong
57+
# default that comes from Google's internal monorepo by using `__init__.py` to delimit a Python
58+
# package. Precisely, when a `py_binary` or `py_test` target has `legacy_create_init` set to `auto (the
59+
# default), it is treated as false if and only if this flag is set. See
60+
# https://github.com/bazelbuild/bazel/issues/10076.
61+
# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_default_to_explicit_init_py
62+
build --incompatible_default_to_explicit_init_py
63+
64+
# Set default value of `allow_empty` to `False` in `glob()`. This prevents a common mistake when
65+
# attempting to use `glob()` to match files in a subdirectory that is opaque to the current package
66+
# because it contains a BUILD file. See https://github.com/bazelbuild/bazel/issues/8195.
67+
# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_disallow_empty_glob
68+
common --incompatible_disallow_empty_glob
69+
70+
# Always download coverage files for tests from the remote cache. By default, coverage files are not
71+
# downloaded on test result cahce hits when --remote_download_minimal is enabled, making it impossible
72+
# to generate a full coverage report.
73+
# Docs: https://bazel.build/reference/command-line-reference#flag--experimental_fetch_all_coverage_outputs
74+
# detching remote cache results
75+
test --experimental_fetch_all_coverage_outputs

.aspect/bazelrc/debug.bazelrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
############################################################
2+
# Use `bazel test --config=debug` to enable these settings #
3+
############################################################
4+
5+
# Stream stdout/stderr output from each test in real-time.
6+
# Docs: https://bazel.build/docs/user-manual#test-output
7+
test:debug --test_output=streamed
8+
9+
# Run one test at a time.
10+
# Docs: https://bazel.build/reference/command-line-reference#flag--test_strategy
11+
test:debug --test_strategy=exclusive
12+
13+
# Prevent long running tests from timing out.
14+
# Docs: https://bazel.build/docs/user-manual#test-timeout
15+
test:debug --test_timeout=9999
16+
17+
# Always run tests even if they have cached results.
18+
# Docs: https://bazel.build/docs/user-manual#cache-test-results
19+
test:debug --nocache_test_results

.aspect/bazelrc/javascript.bazelrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Aspect recommended Bazel flags when using Aspect's JavaScript rules: https://github.com/aspect-build/rules_js
2+
# Docs for Node.js flags: https://nodejs.org/en/docs/guides/debugging-getting-started/#command-line-options
3+
4+
# Support for debugging Node.js tests. Use bazel run with `--config=debug` to turn on the NodeJS
5+
# inspector agent. The node process will break before user code starts and wait for the debugger to
6+
# connect. Pass the --inspect-brk option to all tests which enables the node inspector agent. See
7+
# https://nodejs.org/de/docs/guides/debugging-getting-started/#command-line-options for more
8+
# details.
9+
# Docs: https://nodejs.org/en/docs/guides/debugging-getting-started/#command-line-options
10+
run:debug -- --node_options=--inspect-brk
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Don't apply `--noremote_upload_local_results` and `--noremote_accept_cached` to the disk cache.
2+
# If you have both `--noremote_upload_local_results` and `--disk_cache`, then this fixes a bug where
3+
# Bazel doesn't write to the local disk cache as it treats as a remote cache.
4+
# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_remote_results_ignore_disk
5+
build --incompatible_remote_results_ignore_disk
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+
# No longer experimental in Bazel 6: https://github.com/bazelbuild/bazel/commit/c1a95501a5611878e5cc43a3cc531f2b9e47835b
11+
# Docs: https://bazel.build/reference/command-line-reference#flag--reuse_sandbox_directories
12+
build --experimental_reuse_sandbox_directories
13+
14+
# Do not build runfiles symlink forests for external repositories under
15+
# `.runfiles/wsname/external/repo` (in addition to `.runfiles/repo`). This reduces runfiles &
16+
# sandbox creation times & prevents accidentally depending on this feature which may flip to off by
17+
# default in the future. Note, some rules may fail under this flag, please file issues with the rule
18+
# author.
19+
# Docs: https://bazel.build/reference/command-line-reference#flag--legacy_external_runfiles
20+
build --nolegacy_external_runfiles

.aspect/workflows/bazelrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# build without the bytes
2-
test --remote_download_minimal
3-
test --nobuild_runfile_links
2+
common --remote_download_outputs=minimal
3+
common --nobuild_runfile_links
44

55
# Allows tests to run bazelisk-in-bazel, since this is the cache folder used
6-
test --test_env=XDG_CACHE_HOME
6+
common --test_env=XDG_CACHE_HOME

0 commit comments

Comments
 (0)