From fb8eb7d710f8bf4f12fface4fb61ca9a8b21df61 Mon Sep 17 00:00:00 2001 From: Harish Shan <140232061+perhapsmaple@users.noreply.github.com> Date: Mon, 4 Sep 2023 18:57:59 -0400 Subject: [PATCH] Implement N-1 support policy for Go versions (#4655) ## Which problem is this PR solving? Resolves #4653 ## Description of the changes - Current files tracked are go.mod, all yml files in ./github/workflows/ and ./docker/Makefile. If there are any more build scripts to track, I would be happy to update the PR. - Added scripts/check-go-version.sh to verify that all our build scripts are using the same Go version N, but go.mod is N-1 and fail if not, with an error message and the source files along with their respective versions. - Added scripts/update-go-version.sh to update those scripts to latest version, to make these upgrades easier in the future. Also bumps go.mod to version N-1. - Updated README explaining the support policy. ## How was this change tested? - I have tested the changes locally by modifying go versions ![Screenshot_20230813_120937](https://github.com/jaegertracing/jaeger/assets/140232061/bb4d9e18-22b5-4fcc-9c2b-d374bec0bc4a) ![Screenshot_20230813_121021](https://github.com/jaegertracing/jaeger/assets/140232061/602074bc-7285-48ee-97bf-ea5f0e21a586) ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: Harish Shan <140232061+perhapsmaple@users.noreply.github.com> Signed-off-by: Yuri Shkuro Co-authored-by: Yuri Shkuro Co-authored-by: Yuri Shkuro --- Makefile | 2 + README.md | 10 ++++ scripts/check-go-version.sh | 91 +++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100755 scripts/check-go-version.sh diff --git a/Makefile b/Makefile index 91e447c0ed1..f05f63263f3 100644 --- a/Makefile +++ b/Makefile @@ -166,6 +166,8 @@ lint: @[ ! -s "$(FMT_LOG)" -a ! -s "$(IMPORT_LOG)" ] || (echo "License check or import ordering failures, run 'make fmt'" | cat - $(FMT_LOG) $(IMPORT_LOG) && false) ./scripts/check-semconv-version.sh + ./scripts/check-go-version.sh + .PHONY: build-examples build-examples: $(GOBUILD) -o ./examples/hotrod/hotrod-$(GOOS)-$(GOARCH) ./examples/hotrod/main.go diff --git a/README.md b/README.md index 5d0bcdb598d..7be564944f4 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,16 @@ For example, consider a scenario where v1.28.0 is released on 01-Jun-2021 contai This flag will remain in a deprecated state until the later of 01-Sep-2021 or v1.30.0 where it _can_ be removed on or after either of those events. It may remain deprecated for longer than the aforementioned grace period. +## Go Version Compatibility Guarantees + +The Jaeger project attempts to track the currently supported versions of Go, as [defined by the Go team](https://go.dev/doc/devel/release#policy). +Removing support for an unsupported Go version is not considered a breaking change. + +Starting with the release of Go 1.21, support for Go versions will be updated as follows: + +1. Soon after the release of a new Go minor version `N`, updates will be made to the build and tests steps to accommodate the latest Go minor version. +2. Soon after the release of a new Go minor version `N`, support for Go version `N-2` will be removed and version `N-1` will become the minimum required version. + ## Related Repositories ### Documentation diff --git a/scripts/check-go-version.sh b/scripts/check-go-version.sh new file mode 100755 index 00000000000..625081a2da4 --- /dev/null +++ b/scripts/check-go-version.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +version_regex='[0-9]\.[0-9][0-9]' +update=false +verbose=false + +while getopts "uvd" opt; do + case $opt in + u) update=true ;; + v) verbose=true ;; + x) set -x ;; + *) echo "Usage: $0 [-u] [-v] [-d]" >&2 + exit 1 + ;; + esac +done + +# Fetch latest go release version +go_latest_version=$(curl -s https://go.dev/dl/?mode=json | jq -r '.[0].version' | awk -F'.' '{gsub("go", ""); print $1"."$2}') +go_previous_version="${go_latest_version%.*}.$((10#${go_latest_version#*.} - 1))" + +files_to_update=0 + +function update() { + local file=$1 + local pattern=$2 + local current=$3 + local target=$4 + + newfile=$(mktemp) + old_IFS=$IFS + IFS='' + while read -r line; do + match=$(echo $line | grep -e "$pattern") + if [[ "$match" != "" ]]; then + line=$(echo "$line" | sed "s/${current}/${target}/g") + fi + echo $line >> $newfile + done < $file + IFS=$old_IFS + + if [ $verbose = true ]; then + diff $file $newfile + fi + + mv $newfile $file +} + +function check() { + local file=$1 + local pattern=$2 + local target=$3 + + go_version=$(grep -e "$pattern" $file | head -1 | sed "s/^.*\($version_regex\).*$/\1/") + + if [ "$go_version" = "$target" ]; then + mismatch='' + else + mismatch='*** needs update ***' + files_to_update=$((files_to_update+1)) + fi + + if [[ $update = true && "$mismatch" != "" ]]; then + update "$file" "$pattern" "$go_version" "$target" + mismatch="*** => $target ***" + fi + + printf "%-50s Go version: %s %s\n" "$file" "$go_version" "$mismatch" +} + +check go.mod "^go\s\+$version_regex" $go_previous_version + +check docker/Makefile "^.*golang:$version_regex" $go_latest_version + +gha_workflows=$(grep -rl go-version .github) +for gha_workflow in ${gha_workflows[@]}; do + check $gha_workflow "^\s*go-version:\s\+$version_regex" $go_latest_version +done + +check .golangci.yml "go:\s\+\"$version_regex\"" $go_previous_version + +if [ $files_to_update -eq 0 ]; then + echo "All files are up to date." +else + if [[ $update = true ]]; then + echo "$files_to_update file(s) updated." + else + echo "$files_to_update file(s) must be updated. Rerun this script with -u argument." + exit 1 + fi +fi