Skip to content

Commit 99a0145

Browse files
committed
Only run affected tests in the GitHub workflow.
Also: - Correctly detect unset environment variables - Ignore another non-nightly-but-safe TF package.
1 parent 3984abc commit 99a0145

File tree

5 files changed

+52
-19
lines changed

5 files changed

+52
-19
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ by adding a commit, rebasing etc.
3939

4040
We test against TensorFlow nightly on Python 3.7. We shard our tests
4141
across several build jobs (identified by the `SHARD` environment variable).
42-
Lints are also done in a separate job.
42+
Lints are also done in a separate job. The scripts will attempt to only run the
43+
tests affected by your change, so don't be alarmed by relatively few tests
44+
running if you've changed a rarely used file.
4345

4446
All pull-requests will need to pass the automated lint and unit-tests before
4547
being merged. As the tests can take a bit of time, see the following sections
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2022 The TensorFlow Probability Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ============================================================================
16+
17+
set -v # print commands as they are executed
18+
set -e # fail and exit on any command erroring
19+
20+
if [ $GITHUB_BASE_REF ]; then
21+
# git fetch origin ${GITHUB_BASE_REF} --depth=1
22+
git diff \
23+
--name-only \
24+
--diff-filter=AM origin/${GITHUB_BASE_REF} \
25+
| { grep '^tensorflow_probability.*\.py$' || true; }
26+
fi

testing/install_test_dependencies.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ else
8383
fi
8484

8585
has_tensorflow_packages() {
86-
python -m pip list | grep -v tensorflow-metadata | grep tensorflow &> /dev/null
86+
python -m pip list \
87+
| grep -v tensorflow-metadata \
88+
| grep -v tensorflow-io-gcs-filesystem | grep tensorflow &> /dev/null
8789
}
8890

8991
has_tf_nightly_cpu_package() {

testing/run_github_lints.sh

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,14 @@
1717
set -v # print commands as they are executed
1818
set -e # fail and exit on any command erroring
1919

20-
get_changed_py_files() {
21-
if [ $GITHUB_BASE_REF ]; then
22-
git fetch origin ${GITHUB_BASE_REF} --depth=1
23-
git diff \
24-
--name-only \
25-
--diff-filter=AM origin/${GITHUB_BASE_REF} \
26-
| { grep '^tensorflow_probability.*\.py$' || true; }
27-
fi
28-
}
20+
DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
2921

3022
python -m pip install --upgrade 'pip>=19.2'
3123
python -m pip install --upgrade setuptools
3224
python -m pip install --quiet pylint
3325

3426
# Run lints on added/changed python files.
35-
changed_py_files=$(get_changed_py_files)
27+
changed_py_files=$(${DIR}/get_github_changed_py_files.sh)
3628
if [[ -n "${changed_py_files}" ]]; then
3729
echo "Running pylint on ${changed_py_files}"
3830
pylint -j2 --rcfile=testing/pylintrc ${changed_py_files}

testing/run_github_tests.sh

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ set -u # fail and exit on any undefined variable reference
2424
DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
2525

2626
# Make sure the environment variables are set.
27-
if [ -z "${SHARD}" ]; then
27+
if [ -z "${SHARD+x}" ]; then
2828
echo "SHARD is unset."
2929
exit -1
3030
fi
3131

32-
if [ -z "${NUM_SHARDS}" ]; then
32+
if [ -z "${NUM_SHARDS+x}" ]; then
3333
echo "NUM_SHARDS is unset."
3434
exit -1
3535
fi
@@ -59,16 +59,27 @@ install_python_packages() {
5959
which bazel || install_bazel
6060
install_python_packages
6161

62-
# You can alter this test_target to some smaller subset of TFP tests in case
63-
# you need to reproduce something on the CI workers.
64-
test_target="//tensorflow_probability/..."
65-
test_tags_to_skip="(gpu|requires-gpu-nvidia|notap|no-oss-ci|tfp_jax|tf2-broken|tf2-kokoro-broken)"
62+
changed_py_files="$(${DIR}/get_github_changed_py_files.sh | \
63+
sed -r 's#(.*)/([^/]+).py#//\1:\2.py#')"
64+
65+
if [[ -n "${changed_py_files}" ]]; then
66+
test_targets=$(bazel query --universe_scope=//tensorflow_probability/... \
67+
"tests(allrdeps(set(${changed_py_files})))")
68+
else
69+
# For pushes, test all targets.
70+
test_targets=$(bazel query 'tests(//tensorflow_probability/...)')
71+
fi
72+
73+
test_targets=$(echo "${test_targets}" | tr -s '\n' ' ')
74+
test_targets="$(echo "${test_targets}" | sed -r 's#(.*) #\1#')"
75+
test_tags_to_skip="(gpu|requires-gpu-nvidia|notap|no-oss-ci|tfp_jax|\
76+
tfp_numpy|tf2-broken|tf2-kokoro-broken)"
6677

6778
# Given a test size (small, medium, large), a number of shards and a shard ID,
6879
# query and print a list of tests of the given size to run in the given shard.
6980
query_and_shard_tests_by_size() {
7081
size=$1
71-
bazel_query="attr(size, ${size}, tests(${test_target})) \
82+
bazel_query="attr(size, ${size}, set(${test_targets})) \
7283
except \
7384
attr(tags, \"${test_tags_to_skip}\", \
7485
tests(//tensorflow_probability/...))"

0 commit comments

Comments
 (0)