Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac2b839

Browse files
authored
ci: fix go version to that defined in go.mod (#438)
Our version of Go we reference in our .github/** doesn't match that in go.mod. To fix this, I've updated the version of Go and added a check to ensure they're all in sync.
1 parent 8c9d011 commit ac2b839

File tree

3 files changed

+67
-17
lines changed

3 files changed

+67
-17
lines changed

.github/workflows/release.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ jobs:
1919
name: Run Integration Tests
2020
runs-on: ubuntu-latest
2121
steps:
22+
- name: Check out code into the Go module directory
23+
uses: actions/checkout@v5
24+
25+
- name: Check Go Versions
26+
run: ./scripts/check_go_version.sh
27+
2228
- name: Set up Go
2329
uses: actions/setup-go@v5
2430
with:
25-
go-version: "1.22"
31+
go-version: "1.24.2"
2632
id: go
2733

28-
- name: Check out code into the Go module directory
29-
uses: actions/checkout@v5
30-
3134
- name: Get dependencies
3235
run: |
3336
go mod download
@@ -74,13 +77,16 @@ jobs:
7477
- name: Checkout
7578
uses: actions/checkout@v5
7679

80+
- name: Check Go Versions
81+
run: ./scripts/check_go_version.sh
82+
7783
- name: Unshallow
7884
run: git fetch --prune --unshallow
7985

8086
- name: Set up Go
8187
uses: actions/setup-go@v5
8288
with:
83-
go-version: '1.22'
89+
go-version: "1.24.2"
8490

8591
- name: Import GPG key
8692
id: import_gpg

.github/workflows/test.yml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ jobs:
1919
runs-on: ubuntu-latest
2020
timeout-minutes: 5
2121
steps:
22+
- name: Check out code into the Go module directory
23+
uses: actions/checkout@v5
24+
25+
- name: Check Go Versions
26+
run: ./scripts/check_go_version.sh
27+
2228
- name: Set up Go
2329
uses: actions/setup-go@v5
2430
with:
25-
go-version: "1.22"
31+
go-version: "1.24.2"
2632
id: go
2733

28-
- name: Check out code into the Go module directory
29-
uses: actions/checkout@v5
30-
3134
- name: Get dependencies
3235
run: |
3336
go mod download
@@ -92,20 +95,23 @@ jobs:
9295
- "1.10.*"
9396
- "1.11.*"
9497
steps:
98+
- name: Check out code into the Go module directory
99+
uses: actions/checkout@v5
100+
101+
- name: Check Go Versions
102+
run: ./scripts/check_go_version.sh
103+
95104
- name: Set up Go
96105
uses: actions/setup-go@v5
97106
with:
98-
go-version: "1.22"
107+
go-version: "1.24.2"
99108
id: go
100109

101110
- uses: hashicorp/setup-terraform@v3
102111
with:
103112
terraform_version: ${{ matrix.terraform }}
104113
terraform_wrapper: false
105114

106-
- name: Check out code into the Go module directory
107-
uses: actions/checkout@v5
108-
109115
- name: Get dependencies
110116
run: |
111117
go mod download
@@ -122,20 +128,23 @@ jobs:
122128
runs-on: ubuntu-latest
123129
timeout-minutes: 5
124130
steps:
131+
- name: Check out code into the Go module directory
132+
uses: actions/checkout@v5
133+
134+
- name: Check Go Versions
135+
run: ./scripts/check_go_version.sh
136+
125137
- name: Set up Go
126138
uses: actions/setup-go@v5
127139
with:
128-
go-version: "1.22"
140+
go-version: "1.24.2"
129141
id: go
130142

131143
- uses: hashicorp/setup-terraform@v3
132144
with:
133145
terraform_version: "latest"
134146
terraform_wrapper: false
135147

136-
- name: Check out code into the Go module directory
137-
uses: actions/checkout@v5
138-
139148
- name: Get dependencies
140149
run: |
141150
go mod download

scripts/check_go_version.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
MOD_VERSION=$(go mod edit -json | jq -r .Go)
5+
echo "go.mod version: $MOD_VERSION"
6+
STATUS=0
7+
8+
if [[ " $* " == *" --fix "* ]]; then
9+
for wf in .github/workflows/*.{yml,yaml}; do
10+
sed -i "s/go-version:.*/go-version: \"${MOD_VERSION}\"/g" "${wf}"
11+
done
12+
exit 0
13+
fi
14+
15+
for wf in .github/workflows/*.{yml,yaml}; do
16+
WF_VERSIONS=$(yq -r '.jobs[].steps[] | select(.with["go-version"]) | .with["go-version"]' -o=tsv "$wf" | grep -v '^---$' || true)
17+
if [[ -z "$WF_VERSIONS" ]]; then
18+
continue
19+
fi
20+
21+
UNIQUE_WF_VERSIONS=$(sort -u <<<"$WF_VERSIONS")
22+
for ver in $UNIQUE_WF_VERSIONS; do
23+
if [[ $ver != "$MOD_VERSION" ]]; then
24+
STATUS=1
25+
echo "$wf: go.mod=$MOD_VERSION but workflow uses $(tr '\n' ' ' <<<"$UNIQUE_WF_VERSIONS")"
26+
continue
27+
fi
28+
done
29+
done
30+
31+
if [[ $STATUS -eq 1 ]]; then
32+
echo "Re-run this script with --fix to automatically update workflows to match go.mod"
33+
fi
34+
35+
exit $STATUS

0 commit comments

Comments
 (0)