3
# Intended for use in CI: check git commits, barf if no tests added.
7
# Github label which allows overriding this check
8
OVERRIDE_LABEL="No New Tests"
10
# Docs-only changes are excused
11
if [[ "${CIRRUS_CHANGE_TITLE}" =~ CI:DOCS ]]; then
15
# HEAD should be good enough, but the CIRRUS envariable allows us to test
16
head=${CIRRUS_CHANGE_IN_REPO:-HEAD}
17
# Base of this PR. Here we absolutely rely on cirrus.
18
base=$(git merge-base ${DEST_BRANCH:-main} $head)
20
# This gives us a list of files touched in all commits, e.g.
23
# We look for Added or Modified (not Deleted!) files under 'test'.
24
# --no-renames ensures that renamed tests (#9420) show up as 'A'dded.
25
if git diff --name-status --no-renames $base $head | grep -E -q '^[AM]\s+(test/|.*_test\.go)'; then
29
# Nothing changed under test subdirectory.
31
# This is OK if the only files being touched are "safe" ones.
32
filtered_changes=$(git diff --name-only $base $head |
33
grep -F -vx .cirrus.yml |
34
grep -F -vx .pre-commit-config.yaml |
35
grep -F -vx .gitignore |
38
grep -F -vx podman.spec.rpkg |
39
grep -F -vx .golangci.yml |
40
grep -F -vx winmake.ps1 |
41
grep -E -v '/*Makefile$' |
42
grep -E -v '^[^/]+\.md$' |
43
grep -E -v '^.github' |
44
grep -E -v '^contrib/' |
48
grep -E -v '^vendor/' |
49
grep -E -v '^version/')
50
if [[ -z "$filtered_changes" ]]; then
54
# Nope. Only allow if the github 'no-tests-needed' label is set
55
if [[ -z "$CIRRUS_PR" ]]; then
56
echo "$ME: cannot query github: \$CIRRUS_PR is undefined" >&2
59
if [[ -z "$CIRRUS_REPO_CLONE_TOKEN" ]]; then
60
echo "$ME: cannot query github: \$CIRRUS_REPO_CLONE_TOKEN is undefined" >&2
66
repository(owner: \\\"containers\\\", name: \\\"podman\\\") {
67
pullRequest(number: $CIRRUS_PR) {
78
result=$(curl -s -H "Authorization: bearer $CIRRUS_REPO_CLONE_TOKEN" -H "Accept: application/vnd.github.antiope-preview+json" -H "Content-Type: application/json" -X POST --data @- https://api.github.com/graphql <<<"$query")
80
labels=$(jq -r '.data.repository.pullRequest.labels.nodes[].name' <<<"$result")
82
if grep -F -x -q "$OVERRIDE_LABEL" <<<"$labels"; then
83
# PR has the label set
88
$ME: PR does not include changes in the 'tests' directory
90
Please write a regression test for what you're fixing. Even if it
91
seems trivial or obvious, try to add a test that will prevent
94
If your change is minor, feel free to piggyback on already-written
95
tests, possibly just adding a small step to a similar existing test.
96
Every second counts in CI.
98
If your commit really, truly does not need tests, you can proceed
99
by asking a repo maintainer to set the '$OVERRIDE_LABEL' github label.
100
This will only be done when there's no reasonable alternative.