|
| 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