@@ -28,25 +28,13 @@ source module ci/lib/io.sh
2828io::log " Using bazelisk version"
2929bazelisk version
3030
31- io::log " Prefetching bazel deps..."
32- # Bazel downloads all the dependencies of a project, as well as a number of
33- # development tools during startup. In automated builds these downloads fail
34- # from time to time due to transient network problems. Running `bazel fetch` at
35- # the beginning of the build prevents such transient failures from flaking the
36- # build.
37- TIMEFORMAT=" ==> 🕑 prefetching done in %R seconds"
38- time {
39- " ci/retry-command.sh" 3 120 bazel fetch ...
40- }
41- echo >&2
42-
4331# Outputs a list of args that should be given to all bazel invocations. To read
4432# this into an array use `mapfile -t my_array < <(bazel::common_args)`
4533function bazel::common_args() {
4634 function should_cache_test_results() {
4735 # Disables test caching on ci and daily builds to surface flaky tests.
4836 # Enables test caching on other builds to avoid surfacing unrelated flakes.
49- case " ${TRIGGER_TYPE} " in
37+ case " ${TRIGGER_TYPE:- } " in
5038 ci | daily)
5139 echo no
5240 ;;
@@ -73,3 +61,27 @@ function bazel::common_args() {
7361 fi
7462 printf " %s\n" " ${args[@]} "
7563}
64+
65+ # Bazel downloads all the dependencies of a project, as well as a number of
66+ # development tools during startup. In automated builds these downloads fail
67+ # from time to time due to transient network problems. Running `bazel fetch` at
68+ # the beginning of the build prevents such transient failures from flaking the
69+ # build.
70+ function bazel::prefetch() {
71+ local args
72+ mapfile -t args < <( bazel::common_args)
73+ if [[ " ${GOOGLE_CLOUD_CPP_CI_BAZEL_USE_WORKSPACE:- } " == " true" ]]; then
74+ args+=(
75+ " --noenable_bzlmod"
76+ " --enable_workspace"
77+ )
78+ fi
79+ " ci/retry-command.sh" 3 120 bazel fetch " ${args[@]} " ...
80+ }
81+
82+ io::log " Prefetching bazel deps..."
83+ TIMEFORMAT=" ==> 🕑 prefetching done in %R seconds"
84+ time {
85+ bazel::prefetch
86+ }
87+ echo >&2
0 commit comments