|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
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}") |
5 | 37 | OLDIFS="${IFS}"
|
6 | 38 | IFS='.' MAX_VER=(${GO_VER})
|
7 | 39 | IFS="${OLDIFS}"
|
|
14 | 46 | GO_MAJOR=${MAX_VER[0]}
|
15 | 47 | GO_MINOR=${MAX_VER[1]}
|
16 | 48 | GO_PATCH=${MAX_VER[2]}
|
| 49 | +OVERRIDE_LABEL="override-go-verdiff" |
17 | 50 |
|
18 | 51 | RETCODE=0
|
19 | 52 |
|
@@ -72,9 +105,32 @@ for f in $(find . -name "*.mod"); do
|
72 | 105 | continue
|
73 | 106 | fi
|
74 | 107 | 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 |
77 | 128 | fi
|
78 | 129 | done
|
79 | 130 |
|
| 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 | + |
80 | 136 | exit ${RETCODE}
|
0 commit comments