Skip to content

Commit 163dede

Browse files
committed
Allow override of go-verdiff result via label
Rather than disabling the go-verdiff CI to allow it to pass when there is a legitimate golang version change, use a label to override the test results. The label is `(override-go-verdiff)`. Signed-off-by: Todd Short <[email protected]>
1 parent bf9ffe8 commit 163dede

File tree

2 files changed

+72
-12
lines changed

2 files changed

+72
-12
lines changed

.github/workflows/go-verdiff.yaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ on:
33
pull_request:
44
branches:
55
- master
6-
push:
7-
workflow_dispatch:
8-
merge_group:
96
jobs:
107
go-verdiff:
118
runs-on: ubuntu-latest
129
steps:
13-
- uses: actions/checkout@v4
14-
with:
15-
fetch-depth: 0
16-
- name: Check golang version
17-
run: hack/tools/check-go-version.sh "${{ github.event.pull_request.base.sha }}"
10+
- uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 0
13+
- name: Check golang version
14+
run: |
15+
export LABELS="$(gh api repos/$OWNER/$REPO/pulls/$PR --jq '.labels.[].name')"
16+
hack/tools/check-go-version.sh -b "${{ github.event.pull_request.base.sha }}"
17+
shell: bash
18+
env:
19+
GH_TOKEN: ${{ github.token }}
20+
OWNER: ${{ github.repository_owner }}
21+
REPO: ${{ github.event.repository.name }}
22+
PR: ${{ github.event.pull_request.number }}

hack/tools/check-go-version.sh

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,40 @@
1717
# this implementation in the future.
1818
###########################################
1919

20+
U_FLAG='false'
21+
B_FLAG=''
2022

21-
BASE_REF=${1:-main}
22-
GO_VER=$(sed -En 's/^go (.*)$/\1/p' "go.mod")
23+
usage() {
24+
cat <<EOF
25+
Usage:
26+
$0 [-b <git-ref>] [-h] [-u]
27+
28+
Reports on golang mod file version updates, returns an error when a go.mod
29+
file exceeds the root go.mod file (used as a threshold).
30+
31+
Options:
32+
-b <git-ref> git reference (branch or SHA) to use as a baseline.
33+
Defaults to 'main'.
34+
-h Help (this text).
35+
-u Error on any update, even below the threshold.
36+
EOF
37+
}
38+
39+
while getopts 'b:hu' f; do
40+
case "${f}" in
41+
b) B_FLAG="${OPTARG}" ;;
42+
h) usage
43+
exit 0 ;;
44+
u) U_FLAG='true' ;;
45+
*) echo "Unknown flag ${f}"
46+
usage
47+
exit 1 ;;
48+
esac
49+
done
50+
51+
BASE_REF=${B_FLAG:-main}
52+
ROOT_GO_MOD="./go.mod"
53+
GO_VER=$(sed -En 's/^go (.*)$/\1/p' "${ROOT_GO_MOD}")
2354
OLDIFS="${IFS}"
2455
IFS='.' MAX_VER=(${GO_VER})
2556
IFS="${OLDIFS}"
@@ -32,6 +63,7 @@ fi
3263
GO_MAJOR=${MAX_VER[0]}
3364
GO_MINOR=${MAX_VER[1]}
3465
GO_PATCH=${MAX_VER[2]}
66+
OVERRIDE_LABEL="override-go-verdiff"
3567

3668
RETCODE=0
3769

@@ -90,9 +122,32 @@ for f in $(find . -name "*.mod"); do
90122
continue
91123
fi
92124
if [ "${new}" != "${old}" ]; then
93-
echo "${f}: ${v}: Updated golang version from ${old}"
94-
RETCODE=1
125+
# We NEED to report on changes in the root go.mod, regardless of the U_FLAG
126+
if [ "${f}" == "${ROOT_GO_MOD}" ]; then
127+
echo "${f}: ${v}: Updated ROOT golang version from ${old}"
128+
RETCODE=1
129+
continue
130+
fi
131+
if ${U_FLAG}; then
132+
echo "${f}: ${v}: Updated golang version from ${old}"
133+
RETCODE=1
134+
fi
135+
fi
136+
done
137+
138+
for l in ${LABELS}; do
139+
if [ "$l" == "${OVERRIDE_LABEL}" ]; then
140+
if [ ${RETCODE} -eq 1 ]; then
141+
echo ""
142+
echo "Found ${OVERRIDE_LABEL} label, overriding failed results."
143+
RETCODE=0
144+
fi
95145
fi
96146
done
97147

148+
if [ ${RETCODE} -eq 1 ]; then
149+
echo ""
150+
echo "This test result may be overridden by applying the (${OVERRIDE_LABEL}) label to this PR and re-running the CI job."
151+
fi
152+
98153
exit ${RETCODE}

0 commit comments

Comments
 (0)