File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bash
2
2
set -euo pipefail
3
3
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
+
4
23
MOD_VERSION=$( go mod edit -json | jq -r .Go)
5
24
echo " go.mod version: $MOD_VERSION "
6
25
STATUS=0
7
26
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
9
35
WF_VERSIONS=$( yq -r ' .jobs[].steps[] | select(.with["go-version"]) | .with["go-version"]' -o=tsv " $wf " | grep -v ' ^---$' || true)
10
36
if [[ -z " $WF_VERSIONS " ]]; then
11
37
continue
@@ -21,4 +47,8 @@ for wf in .github/workflows/*.yml; do
21
47
done
22
48
done
23
49
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
+
24
54
exit $STATUS
You can’t perform that action at this time.
0 commit comments