Merge pull request #18061 from prometheus/superq/enforce_go_mod_version

Add CI check for Go version support
This commit is contained in:
Julien 2026-02-11 15:55:11 +01:00 committed by GitHub
commit a78d7c35f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,41 @@
#!/usr/bin/env bash
#
# Description: Validate `go` directive in various Go mod files.
set -u -o pipefail
echo "Checking version support"
version_url='https://go.dev/dl/?mode=json'
get_supported_version() {
curl -s -f "${version_url}" \
| jq -r '.[].version' \
| sed 's/^go//' \
| cut -f2 -d'.' \
| sort -V \
| head -n1
}
get_current_version() {
awk '$1 == "go" {print $2}' go.mod \
| cut -f2 -d'.'
}
supported_version="$(get_supported_version)"
if [[ "${supported_version}" -le 0 ]]; then
echo "Error getting supported version from '${version_url}'"
exit 1
fi
current_version="$(get_current_version)"
if [[ "${current_version}" -le 0 ]]; then
echo "Error getting current version from go.mod"
exit 1
fi
if [[ "${current_version}" -gt "${supported_version}" ]] ; then
echo "Go mod version (1.${current_version}) is newer than upstream supported version (1.${supported_version})"
exit 1
fi
readarray -t mod_files < <(git ls-files go.mod go.work '*/go.mod' || find . -type f -name go.mod -or -name go.work)