Build & Test
Building
A build
task runs bazel build
.
By default, the test
task will also build all build-able targets,
so a typical configuration file does not use the build
task.
There are a few cases where a build
task can be useful:
- When the
--build_tests_only
flag is passed to Bazel, then thetest
task will not build targets which aren't a dependency of any tests. - Some test targets may be known to be broken. A
build
task can be used to only build the tests, but not run them.
A simple configuration looks like:
tasks:
- build:
This builds all targets in the workspace, e.g. bazel build //...
.
Specific targets may be selected with the targets
attribute,
which is a list of patterns:
tasks:
- build:
targets:
# All targets in project A
- //projectA/...
# But excluding this subpackage
- -//projectA/excluded:all
Testing
The test
task runs bazel test
.
The simplest configuration:
tasks:
- test:
This will run all tests in the workspace, e.g. bazel test //...
.
As for build
, specific targets may be selected with the targets
attribute.
tasks:
- test:
targets:
# All targets in project A
- //projectA/...
# But excluding this subpackage
- -//projectA/excluded:all
Setting flags for the test
task is the same as for build
, see
Specifying flags.
Enabling coverage
Workflows doesn't run bazel coverage
due to some historical bugs with invalidating the analysis cache.
Instead, we run bazel test
with some flags that have equivalent behavior.
Enabling coverage just requires adding a line to the configuration:
tasks:
- test:
coverage:
Specifying flags
We recommend that flags typically be checked into a .bazelrc
file.
Workflows looks for a .aspect/workflows/bazelrc
file, and if it exists then Workflows will pass
--bazelrc=.aspect/workflows/bazelrc
to every invocation of Bazel.
Flags can also be placed in the configuration file. They may go at the top-level and also under a task:
bazel:
flags:
# Allow any actions to see the value of $HOME
- --action_env=HOME
tasks:
- test:
bazel:
flags:
# Allow tests to fetch private container images from Docker Hub
- --test_env=DOCKER_USERNAME
- --test_env=DOCKER_PASSWORD
API Doc
The exhaustive list of attributes for the build
task are found at
build, and for the test
task at
test.