|
17 | 17 | # this implementation in the future.
|
18 | 18 | ###########################################
|
19 | 19 |
|
| 20 | +U_FLAG='false' |
| 21 | +B_FLAG='' |
20 | 22 |
|
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}") |
23 | 54 | OLDIFS="${IFS}"
|
24 | 55 | IFS='.' MAX_VER=(${GO_VER})
|
25 | 56 | IFS="${OLDIFS}"
|
|
32 | 63 | GO_MAJOR=${MAX_VER[0]}
|
33 | 64 | GO_MINOR=${MAX_VER[1]}
|
34 | 65 | GO_PATCH=${MAX_VER[2]}
|
| 66 | +OVERRIDE_LABEL="override-go-verdiff" |
35 | 67 |
|
36 | 68 | RETCODE=0
|
37 | 69 |
|
@@ -90,9 +122,32 @@ for f in $(find . -name "*.mod"); do
|
90 | 122 | continue
|
91 | 123 | fi
|
92 | 124 | 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 |
95 | 145 | fi
|
96 | 146 | done
|
97 | 147 |
|
| 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 | + |
98 | 153 | exit ${RETCODE}
|
0 commit comments