Skip to content

Commit 047dc20

Browse files
authored
Merge pull request #3515 from ntnn/improve-go-version-check
Maintain a minimum and a build go version
2 parents ef04e9f + 320ac3c commit 047dc20

File tree

5 files changed

+66
-17
lines changed

5 files changed

+66
-17
lines changed

docs/content/contributing/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Prerequisites
44

55
1. Clone the [kcp-dev/kcp](https://github.com/kcp-dev/kcp) repository.
6-
2. [Install Go](https://golang.org/doc/install) (currently 1.23.10).
6+
2. [Install Go](https://golang.org/doc/install) (at least 1.23).
77
3. Install [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl).
88

99
Please note that the go language version numbers in these files must exactly agree: go/go.mod file, kcp/Dockerfile, and in all the kcp/.github/workflows yaml files that specify go-version. In kcp/Dockerfile it is indicated by the "golang" attribute. In go.mod it is indicated by the "go" directive." In the .github/workflows yaml files it is indicated by "go-version".

docs/generators/cli-doc/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/kcp-dev/kcp/docs/generators/cli-doc
22

3-
go 1.23.7
3+
go 1.23.0
44

55
require (
66
github.com/kcp-dev/kcp v0.0.0-00010101000000-000000000000

docs/generators/cli-doc/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
6969
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
7070
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250512171935-ebb573a40077 h1:lDi9nZ75ypmRJwDFXUN70Cdu8+HxAjPU1kcnn+l4MvI=
7171
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250512171935-ebb573a40077/go.mod h1:jnMZxVnCuKlkIXc4J1Qtmy1Lyo171CDF/RQhNAo0tvA=
72-
github.com/kcp-dev/client-go v0.0.0-20250512170835-5457a0f4bd98 h1:A1Hc2zVGd9LRSQqlGGqfzin+4skWJVcsNXw2+MjU6z4=
73-
github.com/kcp-dev/client-go v0.0.0-20250512170835-5457a0f4bd98/go.mod h1:79pmlxmvE/hohqD/qvhKaaoXmNDF/uhKnnAO6Vf5hZk=
72+
github.com/kcp-dev/client-go v0.0.0-20250707095244-decc4df45adb h1:PTfc4FGjz1Dx+6epz92G4RJj3BYrqg0+XYTiGJQR1cc=
73+
github.com/kcp-dev/client-go v0.0.0-20250707095244-decc4df45adb/go.mod h1:iv3cC1ShwBGzFfNjB+6KWvZviWPe6+MbRlQ7SZoZPFc=
7474
github.com/kcp-dev/logicalcluster/v3 v3.0.5 h1:JbYakokb+5Uinz09oTXomSUJVQsqfxEvU4RyHUYxHOU=
7575
github.com/kcp-dev/logicalcluster/v3 v3.0.5/go.mod h1:EWBUBxdr49fUB1cLMO4nOdBWmYifLbP1LfoL20KkXYY=
7676
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
@@ -150,8 +150,8 @@ go.opentelemetry.io/otel v1.33.0 h1:/FerN9bax5LoK51X/sI0SVYrjSE0/yUL7DpxW4K3FWw=
150150
go.opentelemetry.io/otel v1.33.0/go.mod h1:SUUkR6csvUQl+yjReHu5uM3EtVV7MBm5FHKRlNx4I8I=
151151
go.opentelemetry.io/otel/trace v1.33.0 h1:cCJuF7LRjUFso9LPnEAHJDB2pqzp+hbO8eu1qqW2d/s=
152152
go.opentelemetry.io/otel/trace v1.33.0/go.mod h1:uIcdVUZMpTAmz0tI1z04GoVSezK37CbGV4fr1f2nBck=
153-
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
154-
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
153+
go.uber.org/goleak v1.3.1-0.20241121203838-4ff5fa6529ee h1:uOMbcH1Dmxv45VkkpZQYoerZFeDncWpjbN7ATiQOO7c=
154+
go.uber.org/goleak v1.3.1-0.20241121203838-4ff5fa6529ee/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
155155
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
156156
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
157157
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=

go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
module github.com/kcp-dev/kcp
22

3+
// Two Go versions are maintained - the minimum supported Go version as
4+
// noted in the go directive and the build version used in PROW and GHA
5+
// jobs and Docker builds as noted in the comment.
6+
// The script hack/verify-go-versions.sh checks that all version
7+
// references across the codebase are consistent with the versions
8+
// maintained here.
9+
// go-build-version 1.23.10
310
go 1.23.0
411

512
require (

hack/verify-go-versions.sh

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,62 @@
1717
set -e
1818
set -o pipefail
1919

20-
VERSION=$(grep "go 1." go.mod | sed 's/go //' | sed 's/.0$//')
20+
gomod_version() {
21+
awk '/^go / { print $2 }' "$1" | sed 's/.0$//'
22+
}
2123

22-
grep "FROM .* docker.io/golang:" Dockerfile | { ! grep -v "${VERSION}"; } || { echo "Wrong go version in Dockerfile, expected ${VERSION}"; exit 1; }
23-
grep -w "go-version:" .github/workflows/*.yaml | { ! grep -v "go-version: v${VERSION}"; } || { echo "Wrong go version in .github/workflows/*.yaml, expected ${VERSION}"; exit 1; }
24+
minimum_go_version="$(gomod_version go.mod)"
25+
build_go_version="$(awk '/go-build-version/ { print $3 }' go.mod)"
26+
errors=0
2427

25-
shopt -s dotglob
26-
# Note CONTRIBUTING.md isn't copied in the Dockerfile
27-
for f in docs/content/contributing/getting-started.md; do
28-
grep "golang.org/doc/install" "$f" | { ! grep -v "${VERSION}"; } || { echo "Wrong go version in $f; expected ${VERSION}"; exit 1; }
28+
echo "Verifying minimum Go version: $minimum_go_version"
29+
30+
for gomod in $(git ls-files '**/go.mod'); do
31+
if [[ "$(gomod_version $gomod)" != "$minimum_go_version" ]]; then
32+
echo " Wrong go version in $gomod, expected $minimum_go_version"
33+
errors=$((errors + 1))
34+
fi
35+
done
36+
37+
if ! grep "golang.org/doc/install" $(git ls-files 'docs/**/*.md') | grep -q "$minimum_go_version"; then
38+
echo " Wrong go version in docs/content/contributing/getting-started.md; expected $minimum_go_version"
39+
fi
40+
41+
echo "Verifying build Go version: $build_go_version"
42+
43+
for dockerfile in $(git ls-files Dockerfile '**/Dockerfile'); do
44+
for version in $(sed -nE -e '/^FROM .*golang:/ s#^.*:([1-9.-rc]+).*$#\1#p' "$dockerfile"); do
45+
if [[ "$version" != "$build_go_version" ]]; then
46+
echo " Wrong go version in $dockerfile, expected $build_go_version, found $version"
47+
errors=$((errors + 1))
48+
fi
49+
done
2950
done
3051

31-
# Check prow config
32-
grep "ghcr.io/kcp-dev/infra/build" ".prow.yaml" | { ! grep -v "${VERSION}"; } || { echo "Wrong go version in .prow.yaml; expected ${VERSION}"; exit 1; }
52+
for workflow in $(git ls-files '.github/workflows/*.yaml' '.github/workflows/*.yml'); do
53+
if grep -q 'go-version-file:' "$workflow"; then
54+
echo " Workflow $workflow uses go-version-file, should use go-version instead"
55+
errors=$((errors + 1))
56+
fi
3357

34-
if [ -z "${IGNORE_GO_VERSION}" ]; then
35-
go version | { ! grep -v go${VERSION}; } || { echo "Unexpected go version installed, expected ${VERSION}. Use IGNORE_GO_VERSION=1 to skip this check."; exit 1; }
58+
for version in $(sed -nE -e '/go-version:/ s#^.*v([1-9.-rc]+)$#\1#p' "$workflow"); do
59+
if [[ "$version" != "$build_go_version" ]]; then
60+
echo " Wrong go version in $workflow, expected v${build_go_version}, found v${version}"
61+
errors=$((errors + 1))
62+
fi
63+
done
64+
done
65+
66+
for prow_image_version in $(sed -nE -e '/kcp-dev\/infra/ s#^.*:([1-9.-rc]+)-[1-9]+.*$#\1#p' .prow.yaml); do
67+
if [[ "$prow_image_version" != "$build_go_version" ]]; then
68+
echo " Wrong go version in .prow.yaml, expected ${build_go_version}, found ${prow_image_version}"
69+
errors=$((errors + 1))
70+
fi
71+
done
72+
73+
if [[ "$CI" == true ]] && ! go version | grep -q "go${build_go_version}"; then
74+
echo " Wrong go version detected, expected ${build_go_version}"
75+
errors=$((errors + 1))
3676
fi
77+
78+
exit $errors

0 commit comments

Comments
 (0)