github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/contrib/cirrus/pr-should-include-tests (about) 1 #!/bin/bash 2 # 3 # Intended for use in CI: check git commits, barf if no tests added. 4 # 5 6 # Docs-only changes are excused 7 if [[ "${CIRRUS_CHANGE_TITLE}" =~ CI:DOCS ]]; then 8 exit 0 9 fi 10 11 # So are PRs where 'NO NEW TESTS NEEDED' appears in the Github message 12 if [[ "${CIRRUS_CHANGE_MESSAGE}" =~ NO.NEW.TESTS.NEEDED ]]; then 13 exit 0 14 fi 15 16 # HEAD should be good enough, but the CIRRUS envariable allows us to test 17 head=${CIRRUS_CHANGE_IN_REPO:-HEAD} 18 # Base of this PR. Here we absolutely rely on cirrus. 19 base=$(git merge-base ${DEST_BRANCH:-main} $head) 20 21 # This gives us a list of files touched in all commits, e.g. 22 # A foo.c 23 # M bar.c 24 # We look for Added or Modified (not Deleted!) files under 'test'. 25 # --no-renames ensures that renamed tests (#9420) show up as 'A'dded. 26 if git diff --name-status --no-renames $base $head | egrep -q '^[AM]\s+(test/|.*_test\.go)'; then 27 exit 0 28 fi 29 30 # Nothing changed under test subdirectory. 31 # 32 # This is OK if the only files being touched are "safe" ones. 33 filtered_changes=$(git diff --name-only $base $head | 34 fgrep -vx .cirrus.yml | 35 fgrep -vx .pre-commit-config.yaml | 36 fgrep -vx .gitignore | 37 fgrep -vx go.mod | 38 fgrep -vx go.sum | 39 fgrep -vx podman.spec.rpkg | 40 fgrep -vx .golangci.yml | 41 egrep -v '/*Makefile$' | 42 egrep -v '^[^/]+\.md$' | 43 egrep -v '^.github' | 44 egrep -v '^contrib/' | 45 egrep -v '^docs/' | 46 egrep -v '^hack/' | 47 egrep -v '^nix/' | 48 egrep -v '^vendor/' | 49 egrep -v '^version/') 50 if [[ -z "$filtered_changes" ]]; then 51 exit 0 52 fi 53 54 # One last chance: perhaps the developer included the magic '[NO NEW TESTS NEEDED]' 55 # string in an amended commit. 56 if git log --format=%B ${base}..${head} | fgrep '[NO NEW TESTS NEEDED]'; then 57 exit 0 58 fi 59 60 cat <<EOF 61 $(basename $0): PR does not include changes in the 'tests' directory 62 63 Please write a regression test for what you're fixing. Even if it 64 seems trivial or obvious, try to add a test that will prevent 65 regressions. 66 67 If your change is minor, feel free to piggyback on already-written 68 tests, possibly just adding a small step to a similar existing test. 69 Every second counts in CI. 70 71 If your commit really, truly does not need tests, you can proceed 72 by adding '[NO NEW TESTS NEEDED]' to the body of your commit message. 73 Please think carefully before doing so. 74 EOF 75 76 exit 1