Skip to content

Commit 5186c60

Browse files
committed
Maintain a minimum and a build go version
Signed-off-by: Nelo-T. Wallus <[email protected]>
1 parent 67ae63a commit 5186c60

File tree

2 files changed

+60
-11
lines changed

2 files changed

+60
-11
lines changed

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 ! go version | grep -q "go${minimum_go_version}"; then
74+
echo " Wrong go version installed, expected ${minimum_go_version}"
75+
errors=$((errors + 1))
3676
fi
77+
78+
exit $errors

0 commit comments

Comments
 (0)