mirror of
https://github.com/prometheus/prometheus.git
synced 2026-02-18 18:25:24 -05:00
Merge pull request #18061 from prometheus/superq/enforce_go_mod_version
Add CI check for Go version support
This commit is contained in:
commit
a78d7c35f5
1 changed files with 37 additions and 0 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue