aboutsummaryrefslogtreecommitdiff
path: root/contrib/cirrus
diff options
context:
space:
mode:
authorEd Santiago <santiago@redhat.com>2022-04-20 13:30:31 -0600
committerEd Santiago <santiago@redhat.com>2022-04-21 11:02:57 -0600
commit55a5bd8a00577a91fb381364bcfc61e50a8e505a (patch)
tree2b0d6d1d2f4329662b8c9dc8da32e3344c774c1b /contrib/cirrus
parentcb09c26c6519c2fff8be7285d585672a9066f2da (diff)
downloadpodman-55a5bd8a00577a91fb381364bcfc61e50a8e505a.tar.gz
podman-55a5bd8a00577a91fb381364bcfc61e50a8e505a.tar.bz2
podman-55a5bd8a00577a91fb381364bcfc61e50a8e505a.zip
Optimization: skip tests in some circumstances
A common pattern is to submit PRs that update only tests or docs. When the only changes are to test/e2e, there is no point in running test/system or test/upgrade or test/buildah-bud. Likewise, reciprocally, and similarly for a bunch of other tests (alt, cross, apiv2, ...) And when the only changes are under docs/ , there is no point in running any of the above. Exception: if $CIRRUS_<mumble> are undefined (e.g., cron), never skip Signed-off-by: Ed Santiago <santiago@redhat.com>
Diffstat (limited to 'contrib/cirrus')
-rwxr-xr-xcontrib/cirrus/pr-should-include-tests3
-rwxr-xr-xcontrib/cirrus/runner.sh67
2 files changed, 68 insertions, 2 deletions
diff --git a/contrib/cirrus/pr-should-include-tests b/contrib/cirrus/pr-should-include-tests
index 8103df41d..0d39047a6 100755
--- a/contrib/cirrus/pr-should-include-tests
+++ b/contrib/cirrus/pr-should-include-tests
@@ -30,8 +30,7 @@ fi
# Nothing changed under test subdirectory.
#
# This is OK if the only files being touched are "safe" ones.
-filtered_changes=$(git diff --name-status $base $head |
- awk '{print $2}' |
+filtered_changes=$(git diff --name-only $base $head |
fgrep -vx .cirrus.yml |
fgrep -vx .gitignore |
fgrep -vx Makefile |
diff --git a/contrib/cirrus/runner.sh b/contrib/cirrus/runner.sh
index f33c6af29..8f956d7f5 100755
--- a/contrib/cirrus/runner.sh
+++ b/contrib/cirrus/runner.sh
@@ -46,6 +46,8 @@ function _run_validate() {
}
function _run_unit() {
+ _bail_if_test_can_be_skipped test/goecho test/version
+
# shellcheck disable=SC2154
if [[ "$PODBIN_NAME" != "podman" ]]; then
# shellcheck disable=SC2154
@@ -55,31 +57,45 @@ function _run_unit() {
}
function _run_apiv2() {
+ _bail_if_test_can_be_skipped test/apiv2
+
source .venv/requests/bin/activate
make localapiv2 |& logformatter
}
function _run_compose() {
+ _bail_if_test_can_be_skipped test/compose
+
./test/compose/test-compose |& logformatter
}
function _run_compose_v2() {
+ _bail_if_test_can_be_skipped test/compose
+
./test/compose/test-compose |& logformatter
}
function _run_int() {
+ _bail_if_test_can_be_skipped test/e2e
+
dotest integration
}
function _run_sys() {
+ _bail_if_test_can_be_skipped test/system
+
dotest system
}
function _run_upgrade_test() {
+ _bail_if_test_can_be_skipped test/upgrade
+
bats test/upgrade |& logformatter
}
function _run_bud() {
+ _bail_if_test_can_be_skipped test/buildah-bud
+
./test/buildah-bud/run-buildah-bud-tests |& logformatter
}
@@ -217,6 +233,9 @@ function _run_build() {
}
function _run_altbuild() {
+ # We can skip all these steps for test-only PRs, but not doc-only ones
+ _bail_if_test_can_be_skipped docs
+
local -a arches
local arch
req_env_vars ALT_NAME
@@ -345,6 +364,54 @@ dotest() {
|& logformatter
}
+# Optimization: will exit if the only PR diffs are under docs/ or tests/
+# with the exception of any given arguments. E.g., don't run e2e or upgrade
+# or bud tests if the only PR changes are in test/system.
+function _bail_if_test_can_be_skipped() {
+ local head base diffs
+
+ # Cirrus sets these for PRs but not cron. In cron, we never want to skip.
+ for v in CIRRUS_CHANGE_IN_REPO DEST_BRANCH; do
+ if [[ -z "${!v}" ]]; then
+ msg "[ _cannot do selective skip: \$$v is undefined ]"
+ return 0
+ fi
+ done
+ # And if this one *is* defined, it means we're not in PR-land; don't skip.
+ if [[ -n "$CIRRUS_TAG" ]]; then
+ msg "[ _cannot do selective skip: \$CIRRUS_TAG is defined ]"
+ return 0
+ fi
+
+ head=$CIRRUS_CHANGE_IN_REPO
+ base=$(git merge-base $DEST_BRANCH $head)
+ diffs=$(git diff --name-only $base $head)
+
+ # If PR touches any files in an argument directory, we cannot skip
+ for subdir in "$@"; do
+ if egrep -q "^$subdir/" <<<"$diffs"; then
+ return 0
+ fi
+ done
+
+ # PR does not touch any files under our input directories. Now see
+ # if the PR touches files outside of the following directories, by
+ # filtering these out from the diff results.
+ for subdir in docs test; do
+ # || true needed because we're running with set -e
+ diffs=$(egrep -v "^$subdir/" <<<"$diffs" || true)
+ done
+
+ # If we still have diffs, they indicate files outside of docs & test.
+ # It is not safe to skip.
+ if [[ -n "$diffs" ]]; then
+ return 0
+ fi
+
+ msg "SKIPPING: This is a doc- and/or test-only PR with no changes under $*"
+ exit 0
+}
+
# Nearly every task in .cirrus.yml makes use of this shell script
# wrapped by /usr/bin/time to collect runtime statistics. Because the
# --output option is used to log stats to a file, every child-process