podman

Форк
0
/
pr-should-include-tests 
103 строки · 3.5 Кб
1
#!/bin/bash
2
#
3
# Intended for use in CI: check git commits, barf if no tests added.
4
#
5
ME=$(basename $0)
6

7
# Github label which allows overriding this check
8
OVERRIDE_LABEL="No New Tests"
9

10
# Docs-only changes are excused
11
if [[ "${CIRRUS_CHANGE_TITLE}" =~ CI:DOCS ]]; then
12
    exit 0
13
fi
14

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

20
# This gives us a list of files touched in all commits, e.g.
21
#    A    foo.c
22
#    M    bar.c
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
26
    exit 0
27
fi
28

29
# Nothing changed under test subdirectory.
30
#
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              |
36
                       grep -F -vx go.mod                  |
37
                       grep -F -vx go.sum                  |
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/'             |
45
                       grep -E -v  '^docs/'                |
46
                       grep -E -v  '^hack/'                |
47
                       grep -E -v  '^nix/'                 |
48
                       grep -E -v  '^vendor/'              |
49
                       grep -E -v  '^version/')
50
if [[ -z "$filtered_changes" ]]; then
51
    exit 0
52
fi
53

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
57
    exit 1
58
fi
59
if [[ -z "$CIRRUS_REPO_CLONE_TOKEN" ]]; then
60
    echo "$ME: cannot query github: \$CIRRUS_REPO_CLONE_TOKEN is undefined" >&2
61
    exit 1
62
fi
63

64
query="{
65
  \"query\": \"query {
66
  repository(owner: \\\"containers\\\", name: \\\"podman\\\") {
67
    pullRequest(number: $CIRRUS_PR) {
68
      labels(first: 100) {
69
        nodes {
70
          name
71
        }
72
      }
73
    }
74
  }
75
}\"
76
}"
77

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")
79

80
labels=$(jq -r '.data.repository.pullRequest.labels.nodes[].name' <<<"$result")
81

82
if grep -F -x -q "$OVERRIDE_LABEL" <<<"$labels"; then
83
    # PR has the label set
84
    exit 0
85
fi
86

87
cat <<EOF
88
$ME: PR does not include changes in the 'tests' directory
89

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
92
regressions.
93

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

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.
101
EOF
102

103
exit 1
104

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.