Skip to content

Commit 945e2e8

Browse files
committed
BUILD/MINOR: ci: build and check everything with Go 1.27
The format job runs `go fix`, whose rewrites differ between Go releases, so an image floating on the latest release could fail a tree that was formatted locally. Instead of pinning only that job, move the whole project to one toolchain: go.mod requires 1.27, every GitLab job uses the 1.27 image through a single GO_VERSION variable (the e2e job no longer overrides it), and every GitHub job reads the version from go.mod. Print the diff when the tidy and format checks fail so the cause is visible in the log, and apply the rewrite the 1.27 toolchain produces.
1 parent 71ac7bb commit 945e2e8

8 files changed

Lines changed: 34 additions & 14 deletions

File tree

.github/workflows/ci.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ jobs:
4040
- name: tidy
4141
run: go mod tidy
4242
- name: changes
43-
run: test -z "$(git diff 2> /dev/null)" || exit "Go modules not tidied, issue \`go mod tidy\` and commit the result"
43+
run: |
44+
if ! git diff --quiet; then
45+
echo "Go modules not tidied, issue \`go mod tidy\` and commit the result" >&2
46+
git diff
47+
exit 1
48+
fi
4449
format:
4550
name: gofumpt
4651
runs-on: ubuntu-latest
@@ -51,6 +56,7 @@ jobs:
5156
uses: actions/setup-go@v7
5257
with:
5358
go-version-file: 'go.mod'
59+
check-latest: true
5460
- name: Allow Go toolchain downloads
5561
run: echo "GOTOOLCHAIN=auto" >> "$GITHUB_ENV"
5662
- name: Install Task
@@ -61,7 +67,12 @@ jobs:
6167
- name: format
6268
run: task format
6369
- name: changes
64-
run: test -z "$(git diff 2> /dev/null)" || exit "Go code not formatted, issue \`task format\` and commit the result"
70+
run: |
71+
if ! git diff --quiet; then
72+
echo "Go code not formatted, issue \`task format\` and commit the result" >&2
73+
git diff
74+
exit 1
75+
fi
6576
lint:
6677
name: lint
6778
needs: ["tidy", "format"]

.gitlab-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ stages:
1717
- build
1818
variables:
1919
HAPROXY_REGISTRY_GO: "registry.haproxy.com/gophers"
20+
# One toolchain for every job, matching go.mod: `go fix` output differs between releases.
21+
GO_VERSION: "1.27"
2022
JUNIT_FILE: "junit-report.xml"
2123
GOTESTSUM_JUNITFILE: "junit-report.xml"
2224

.gitlab/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ build:
33
needs: []
44
extends: .all-pipelines
55
image:
6-
name: $HAPROXY_REGISTRY_GO/golang:latest-alpine
6+
name: $HAPROXY_REGISTRY_GO/golang:$GO_VERSION-alpine
77
entrypoint: [""]
88
tags:
99
- go

.gitlab/lint.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ tidy:
33
needs: []
44
extends: .all-pipelines
55
image:
6-
name: $HAPROXY_REGISTRY_GO/golang:latest-alpine
6+
name: $HAPROXY_REGISTRY_GO/golang:$GO_VERSION-alpine
77
entrypoint: [""]
88
tags:
99
- go
1010
before_script:
1111
- go version
1212
script:
1313
- go mod tidy
14-
- test -z "$(git diff 2> /dev/null)" || exit 'Go modules not tidied, issue \`go mod tidy\` and commit the result'
14+
- |
15+
if ! git diff --quiet; then
16+
echo 'Go modules not tidied, issue `go mod tidy` and commit the result' >&2
17+
exit 1
18+
fi
1519
after_script:
1620
- |
1721
if [ "$CI_JOB_STATUS" == "success" ]; then
@@ -30,15 +34,19 @@ format:
3034
needs: []
3135
extends: .all-pipelines
3236
image:
33-
name: $HAPROXY_REGISTRY_GO/golang:latest-alpine
37+
name: $HAPROXY_REGISTRY_GO/golang:$GO_VERSION-alpine
3438
entrypoint: [""]
3539
tags:
3640
- go
3741
before_script:
3842
- go version
3943
script:
4044
- task format
41-
- test -z "$(git diff 2> /dev/null)" || exit 'Go code not formatted, issue \`task format\` and commit the result'
45+
- |
46+
if ! git diff --quiet; then
47+
echo 'Go code not formatted, issue `task format` and commit the result' >&2
48+
exit 1
49+
fi
4250
after_script:
4351
- |
4452
if [ "$CI_JOB_STATUS" == "success" ]; then
@@ -58,7 +66,7 @@ lint:
5866
needs: []
5967
extends: .all-pipelines
6068
image:
61-
name: $HAPROXY_REGISTRY_GO/golang:latest-alpine
69+
name: $HAPROXY_REGISTRY_GO/golang:$GO_VERSION-alpine
6270
entrypoint: [""]
6371
tags:
6472
- go

.gitlab/security.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ license:
33
needs: ["tidy"]
44
extends: .all-pipelines
55
image:
6-
name: $HAPROXY_REGISTRY_GO/golang:latest-alpine
6+
name: $HAPROXY_REGISTRY_GO/golang:$GO_VERSION-alpine
77
entrypoint: [""]
88
tags:
99
- go
@@ -27,7 +27,7 @@ govulncheck:
2727
needs: []
2828
extends: .all-pipelines
2929
image:
30-
name: $HAPROXY_REGISTRY_GO/golang:latest-alpine
30+
name: $HAPROXY_REGISTRY_GO/golang:$GO_VERSION-alpine
3131
entrypoint: [""]
3232
tags:
3333
- go

.gitlab/test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ test-e2e:
1616
variables:
1717
DOCKER_HOST: tcp://docker:2375
1818
DOCKER_DRIVER: overlay2
19-
GO_VERSION: "1.26"
2019
DOCKER_VERSION: "29.1"
2120
# dind resolves `docker run -v` paths on its own filesystem; only /builds
2221
# is shared with the job container, so bind-mounted test dirs must live
@@ -40,7 +39,7 @@ test:
4039
needs: []
4140
extends: .all-pipelines
4241
image:
43-
name: $HAPROXY_REGISTRY_GO/golang:latest-alpine
42+
name: $HAPROXY_REGISTRY_GO/golang:$GO_VERSION-alpine
4443
entrypoint: [""]
4544
tags:
4645
- go

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/haproxytech/gopherd
22

3-
go 1.26
3+
go 1.27

service/user_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func TestStrictGroupsNeedsAnExplicitGroup(t *testing.T) {
316316
}
317317
// Append atomically: write the new content to a sibling and rename over.
318318
updated := append(append([]byte{}, original...),
319-
[]byte(fmt.Sprintf("%s:x:%d:root\n", extraName, extraGID))...)
319+
fmt.Appendf(nil, "%s:x:%d:root\n", extraName, extraGID)...)
320320
tmp := groupFile + ".gopherd-test"
321321
if err := os.WriteFile(tmp, updated, 0o644); err != nil {
322322
t.Skipf("cannot stage %s: %v", tmp, err)

0 commit comments

Comments
 (0)