Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit bee9be2

Browse files
author
Ian Sturdy
authored
Fix tools/ci.sh (#52)
Two issues: - Modifications to BUILD files were not rerunning targets under that BUILD file due to counter-intuitive behavior in bazel query. - The script's return value only depended on the final test, so errors in binary rules or library rules not depended on by any test were suppressed.
1 parent cf3ae79 commit bee9be2

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

tools/ci.sh

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,33 @@
1919
# https://github.com/bazelbuild/bazel/blob/master/scripts/ci/ci.sh
2020

2121
files=()
22-
# If WORKSPACE or .travis.yml is touched, almost anything may be affected.
23-
# Otherwise, top-level files are irrelevant to the build and we exclude them to
24-
# suppress query errors.
22+
# If WORKSPACE or the Travis config is touched, almost anything may be affected.
2523
if [[ ! -z $(git diff --name-only ${TRAVIS_COMMIT_RANGE} \
26-
| grep "WORKSPACE\|.travis.yml" ) ]];
24+
| grep "WORKSPACE\|.travis.yml\|tools/ci.sh" ) ]];
2725
then
28-
echo ".travis.yml or WORKSPACE affected; running all tests."
26+
echo "Travis config or WORKSPACE affected; running all tests."
2927
files=("//...")
3028
else
3129
echo "Affected files:"
32-
for file in $(git diff --name-only ${TRAVIS_COMMIT_RANGE} | grep / ); do
33-
mapfile -O ${#files[@]} -t files <<< "$(bazel query $file)"
34-
bazel query $file
30+
for file in $(git diff --name-only ${TRAVIS_COMMIT_RANGE}); do
31+
# We need to replace :BUILD with :all because bazel does not consider
32+
# targets to be dependencies of their BUILD files. Query errors mean
33+
# that the file is not tracked by bazel (e.g. documentation, tools)
34+
# and can be ignored.
35+
mapfile -O ${#files[@]} -t files <<< \
36+
"$(bazel query $file 2>/dev/null| sed s/:BUILD/:all/)"
37+
bazel query $file 2>/dev/null
3538
done
3639
fi
3740
41+
if [[ -z "${files[*]}" ]]; then
42+
echo "No buildable files affected."
43+
exit 0
44+
fi
45+
46+
exit_code=0
47+
trap "exit_code=1" ERR
48+
3849
# We can't use --noshow_progress on build/test commands because Travis
3950
# terminates the build after 10 mins without output.
4051
buildables=$(bazel query -k --noshow_progress \
@@ -58,3 +69,5 @@ if [[ ! -z $tests ]]; then
5869
echo "$tests"
5970
bazel test --experimental_ui_actions_shown=1 -k $tests
6071
fi
72+
73+
exit $exit_code

0 commit comments

Comments
 (0)