Skip to content

Commit b4763ae

Browse files
authored
Allow override of go-verdiff result via label (#1964)
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 <tshort@redhat.com>
1 parent d873ec1 commit b4763ae

File tree

2 files changed

+69
-5
lines changed

2 files changed

+69
-5
lines changed

.github/workflows/go-verdiff.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,12 @@ jobs:
1111
with:
1212
fetch-depth: 0
1313
- name: Check golang version
14-
run: hack/tools/check-go-version.sh "${{ github.event.pull_request.base.sha }}"
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: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
11
#!/bin/bash
22

3-
BASE_REF=${1:-main}
4-
GO_VER=$(sed -En 's/^go (.*)$/\1/p' "go.mod")
3+
U_FLAG='false'
4+
B_FLAG=''
5+
6+
usage() {
7+
cat <<EOF
8+
Usage:
9+
$0 [-b <git-ref>] [-h] [-u]
10+
11+
Reports on golang mod file version updates, returns an error when a go.mod
12+
file exceeds the root go.mod file (used as a threshold).
13+
14+
Options:
15+
-b <git-ref> git reference (branch or SHA) to use as a baseline.
16+
Defaults to 'main'.
17+
-h Help (this text).
18+
-u Error on any update, even below the threshold.
19+
EOF
20+
}
21+
22+
while getopts 'b:hu' f; do
23+
case "${f}" in
24+
b) B_FLAG="${OPTARG}" ;;
25+
h) usage
26+
exit 0 ;;
27+
u) U_FLAG='true' ;;
28+
*) echo "Unknown flag ${f}"
29+
usage
30+
exit 1 ;;
31+
esac
32+
done
33+
34+
BASE_REF=${B_FLAG:-main}
35+
ROOT_GO_MOD="./go.mod"
36+
GO_VER=$(sed -En 's/^go (.*)$/\1/p' "${ROOT_GO_MOD}")
537
OLDIFS="${IFS}"
638
IFS='.' MAX_VER=(${GO_VER})
739
IFS="${OLDIFS}"
@@ -14,6 +46,7 @@ fi
1446
GO_MAJOR=${MAX_VER[0]}
1547
GO_MINOR=${MAX_VER[1]}
1648
GO_PATCH=${MAX_VER[2]}
49+
OVERRIDE_LABEL="override-go-verdiff"
1750

1851
RETCODE=0
1952

@@ -72,9 +105,32 @@ for f in $(find . -name "*.mod"); do
72105
continue
73106
fi
74107
if [ "${new}" != "${old}" ]; then
75-
echo "${f}: ${v}: Updated golang version from ${old}"
76-
RETCODE=1
108+
# We NEED to report on changes in the root go.mod, regardless of the U_FLAG
109+
if [ "${f}" == "${ROOT_GO_MOD}" ]; then
110+
echo "${f}: ${v}: Updated ROOT golang version from ${old}"
111+
RETCODE=1
112+
continue
113+
fi
114+
if ${U_FLAG}; then
115+
echo "${f}: ${v}: Updated golang version from ${old}"
116+
RETCODE=1
117+
fi
118+
fi
119+
done
120+
121+
for l in ${LABELS}; do
122+
if [ "$l" == "${OVERRIDE_LABEL}" ]; then
123+
if [ ${RETCODE} -eq 1 ]; then
124+
echo ""
125+
echo "Found ${OVERRIDE_LABEL} label, overriding failed results."
126+
RETCODE=0
127+
fi
77128
fi
78129
done
79130

131+
if [ ${RETCODE} -eq 1 ]; then
132+
echo ""
133+
echo "This test result may be overridden by applying the (${OVERRIDE_LABEL}) label to this PR and re-running the CI job."
134+
fi
135+
80136
exit ${RETCODE}

0 commit comments

Comments
 (0)