Skip to main content
Version: 5.9.x

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:

  1. When the --build_tests_only flag is passed to Bazel, then the test task will not build targets which aren't a dependency of any tests.
  2. 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:

.aspect/workflows/config.yaml
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:

.aspect/workflows/config.yaml
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:

.aspect/workflows/config.yaml
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.

.aspect/workflows/config.yaml
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:

.aspect/workflows/config.yaml
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:

.aspect/workflows/config.yaml
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.