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

Commit 5fe0537

Browse files
authored
Make Travis only build/run affected targets. (#32)
Many Travis builds that require compiling protos are taking a very long time; this will hopefully help somewhat.
1 parent d0ad57c commit 5fe0537

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,4 @@ before_install:
1010
- ./bazel-0.8.1-installer-linux-x86_64.sh --user
1111

1212
script:
13-
# We can't use --noshow_progress because Travis terminates the
14-
# build after 10 mins without output.
15-
- bazel build --experimental_ui_actions_shown=1 -k $(bazel query ... | grep -v :_)
16-
- bazel test --experimental_ui_actions_shown=1 -k $(bazel query "kind(test, //...) except attr('tags', 'noci', //...)" | grep -v :_)
13+
- ./ci.sh

ci.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#! /usr/bin/env bash
2+
#
3+
# Copyright 2018, OpenCensus Authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Build/run only targets affected by files changed in the commit range,
18+
# according to bazel query. Based on
19+
# https://github.com/bazelbuild/bazel/blob/master/scripts/ci/ci.sh
20+
21+
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.
25+
if [[ ! -z $(git diff --name-only ${TRAVIS_COMMIT_RANGE} \
26+
| grep "WORKSPACE\|.travis.yml" ) ]];
27+
then
28+
echo ".travis.yml or WORKSPACE affected; running all tests."
29+
files=("//...")
30+
else
31+
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
35+
done
36+
fi
37+
38+
# We can't use --noshow_progress on build/test commands because Travis
39+
# terminates the build after 10 mins without output.
40+
buildables=$(bazel query -k --noshow_progress \
41+
"kind(rule, rdeps(//..., set(${files[*]})))" \
42+
| grep -v :_)
43+
if [[ ! -z $buildables ]]; then
44+
echo "Building targets"
45+
echo "$buildables"
46+
bazel build --experimental_ui_actions_shown=1 -k $buildables
47+
fi
48+
49+
# Exclude tests tagged "noci". Tests marked "manual" are already excluded from
50+
# wildcard queries.
51+
tests=$(bazel query -k --noshow_progress \
52+
"kind(test, rdeps(//..., set(${files[*]}))) except attr('tags', 'noci', //...)" \
53+
| grep -v :_)
54+
if [[ ! -z $tests ]]; then
55+
echo "Running tests"
56+
echo "$tests"
57+
bazel test --experimental_ui_actions_shown=1 -k $tests
58+
fi

0 commit comments

Comments
 (0)