mirror of
https://github.com/prometheus/prometheus.git
synced 2026-10-28 10:44:59 +08:00
The test_go_oldest job pinned the golang-builder image tag by hand, which had to be bumped on every Go release and was enforced by scripts/check-go-mod-version.sh. Compute the oldest supported Go version from https://go.dev/dl/?mode=json instead, and feed it to the job as a single-row matrix, like list_lts_releases already does for LTS releases. This also keeps CI green on the next Go minor release. With the version pinned in the tree, upstream releasing a new minor makes the check fail on every PR that is not on top of main, and each one has to be rebased on the bump commit. Reading the version at runtime means every PR picks up the new N-1 version on its own. Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
50 lines
1.2 KiB
Bash
Executable File
50 lines
1.2 KiB
Bash
Executable File
#!/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)
|
|
|
|
echo "Checking files ${mod_files[@]}"
|
|
|
|
matches=$(awk '$1 == "go" {print $2}' "${mod_files[@]}" | sort -u | wc -l)
|
|
|
|
if [[ "${matches}" -ne 1 ]]; then
|
|
echo 'Not all go.mod/go.work files have matching go versions'
|
|
exit 1
|
|
fi
|