Skip to content

Commit 1388790

Browse files
authored
Merge pull request podman-container-tools#28843 from kolyshkin/should-include-tests
ci: fix validate-source checks vs stale labels
2 parents 3ab2580 + d05c113 commit 1388790

3 files changed

Lines changed: 46 additions & 11 deletions

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ jobs:
4646
validate-source:
4747
name: Validate source code changes
4848
runs-on: cncf-ubuntu-8-32-x86
49+
permissions:
50+
pull-requests: read # For hack/ci/pr-should-include-tests to query PR labels.
4951
env:
5052
# Base commit of this PR; used by the Makefile and the helper scripts to
5153
# compute the commit range (git merge-base $DEST_BRANCH HEAD).
@@ -126,8 +128,9 @@ jobs:
126128
run: make swagger
127129

128130
- name: Check that the PR includes tests
129-
# The 'No New Tests' label lets maintainers override this check.
130-
if: ${{ github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'No New Tests') }}
131+
env:
132+
# For hack/ci/pr-should-include-tests to query PR labels.
133+
GITHUB_TOKEN: ${{ github.token }}
131134
run: make tests-included
132135

133136
- name: Validate renovate config
@@ -154,9 +157,8 @@ jobs:
154157
# limit enforced by hack/ci/make-and-check-size.sh.
155158
if: ${{ github.event_name == 'pull_request' }}
156159
env:
157-
# The 'bloat_approved' label lets a repo admin override the binary
158-
# size growth check in hack/ci/make-and-check-size.sh.
159-
BLOAT_APPROVED: ${{ contains(github.event.pull_request.labels.*.name, 'bloat_approved') }}
160+
# For hack/ci/make-and-check-size.sh to query PR labels.
161+
GITHUB_TOKEN: ${{ github.token }}
160162
run: |
161163
# git rebase rewrites commits, so it needs a committer identity.
162164
git config user.name "CI"

hack/ci/make-and-check-size.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,21 @@ function bloat_approved() {
5353
# requiring a MAX_BIN_GROWTH=nnn statement in github comments.
5454
local actual_growth="$1"
5555

56-
# The validate-source GitHub Actions workflow sets BLOAT_APPROVED=true when
57-
# the PR carries the '$OVERRIDE_LABEL' label.
58-
[[ "$BLOAT_APPROVED" == "true" ]]
56+
local var
57+
for var in PR_NUMBER GITHUB_TOKEN GITHUB_REPOSITORY; do
58+
if [[ -z "${!var}" ]]; then
59+
echo "$ME: cannot query github: \$$var is undefined" >&2
60+
return 1
61+
fi
62+
done
63+
64+
labels=$(curl --fail -s \
65+
-H "Authorization: bearer $GITHUB_TOKEN" \
66+
-H "Accept: application/vnd.github+json" \
67+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/$PR_NUMBER" |
68+
jq -r '.labels[].name')
69+
70+
grep -F -x -q "$OVERRIDE_LABEL" <<< "$labels"
5971
}
6072

6173
# ACTUAL CODE BEGINS HERE

hack/ci/pr-should-include-tests

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,30 @@ if [[ -z "$filtered_changes" ]]; then
4646
exit 0
4747
fi
4848

49-
# This PR touches non-test files but adds no tests. Fail loudly.
50-
# The '$OVERRIDE_LABEL' label can be used to override this check; that is
51-
# handled by the CI workflow, not here.
49+
# This PR touches non-test files but adds no tests. Only allow it if the
50+
# '$OVERRIDE_LABEL' github label is set.
51+
if [[ -n "$PR_NUMBER" ]]; then
52+
for var in GITHUB_TOKEN GITHUB_REPOSITORY; do
53+
if [[ -z "${!var}" ]]; then
54+
echo "$ME: cannot query github: \$$var is undefined" >&2
55+
return 1
56+
fi
57+
done
58+
59+
labels=$(curl --fail -s \
60+
-H "Authorization: bearer $GITHUB_TOKEN" \
61+
-H "Accept: application/vnd.github+json" \
62+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/$PR_NUMBER" |
63+
jq -r '.labels[].name')
64+
65+
if grep -F -x -q "$OVERRIDE_LABEL" <<< "$labels"; then
66+
echo "$ME: \"$OVERRIDE_LABEL\" label found, ignoring test requirements"
67+
exit 0
68+
fi
69+
fi
70+
71+
# This PR touches non-test files but adds no tests, and
72+
# the '$OVERRIDE_LABEL' is not set. Fail loudly.
5273
cat <<EOF
5374
$ME: PR does not include changes in the 'tests' directory
5475

0 commit comments

Comments
 (0)