Skip to content

Commit bfceb4c

Browse files
committed
add --fix
1 parent 759a03e commit bfceb4c

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

scripts/check_go_version.sh

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
fix=0
5+
args="$(getopt -o "" -l fix -- "$@")"
6+
eval set -- "$args"
7+
while true; do
8+
case "$1" in
9+
--fix)
10+
fix=1
11+
shift
12+
;;
13+
--)
14+
shift
15+
break
16+
;;
17+
*)
18+
error "Unrecognized option: $1"
19+
;;
20+
esac
21+
done
22+
423
MOD_VERSION=$(go mod edit -json | jq -r .Go)
524
echo "go.mod version: $MOD_VERSION"
625
STATUS=0
726

8-
for wf in .github/workflows/*.yml; do
27+
if [[ $fix -eq 1 ]]; then
28+
for wf in .github/workflows/*.{yml,yaml}; do
29+
sed -i "s/go-version:.*/go-version: \"${MOD_VERSION}\"/g" "${wf}"
30+
done
31+
exit $STATUS
32+
fi
33+
34+
for wf in .github/workflows/*.{yml,yaml}; do
935
WF_VERSIONS=$(yq -r '.jobs[].steps[] | select(.with["go-version"]) | .with["go-version"]' -o=tsv "$wf" | grep -v '^---$' || true)
1036
if [[ -z "$WF_VERSIONS" ]]; then
1137
continue
@@ -21,4 +47,8 @@ for wf in .github/workflows/*.yml; do
2147
done
2248
done
2349

50+
if [[ $STATUS -eq 1 ]]; then
51+
echo "Re-run this script with --fix to automatically update workflows to match go.mod"
52+
fi
53+
2454
exit $STATUS

0 commit comments

Comments
 (0)