From d8e9ed3246c66f486a6df63a38077839235494ef Mon Sep 17 00:00:00 2001 From: SuperQ Date: Wed, 11 Feb 2026 13:36:27 +0100 Subject: [PATCH] Add CI check for Go version support Fail Go mod check if the `go` directive in `go.mod` is newer than the currently supported Go versions. Signed-off-by: SuperQ --- scripts/check-go-mod-version.sh | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/scripts/check-go-mod-version.sh b/scripts/check-go-mod-version.sh index 96317de2e6..6020ce0a8d 100755 --- a/scripts/check-go-mod-version.sh +++ b/scripts/check-go-mod-version.sh @@ -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)