Script for golang version update | Issue 16446#16488
Script for golang version update | Issue 16446#16488manojks1999 wants to merge 2 commits intoprometheus:mainfrom
Conversation
|
You need to sign your commit, as otherwise the DCO check fails. |
machine424
left a comment
There was a problem hiding this comment.
thanks for this.
Have some suggestions to simplify this.
scripts/update_go_version.sh
Outdated
| sed -i.bak -E "s/^go [0-9]+\.[0-9]+\.[0-9]+$/go ${CURRENT_VERSION}.0/" documentation/examples/remote_storage/go.mod | ||
|
|
||
| # Clean up backup files | ||
| find . -name "*.bak" -type f -delete |
There was a problem hiding this comment.
no need for backups, git should take care of that
scripts/update_go_version.sh
Outdated
| # | ||
| # Update Go version across the Prometheus project. | ||
| # Run from repository root. | ||
| set -e |
There was a problem hiding this comment.
nit: just set -euo pipefail as the others.
scripts/update_go_version.sh
Outdated
| set -e | ||
| set -u | ||
|
|
||
| if ! [[ "$0" =~ "scripts/update_go_version.sh" ]]; then |
There was a problem hiding this comment.
no need for this, the makefile target should/will be used.
scripts/update_go_version.sh
Outdated
| echo "Updating Go version from ${CURRENT_VERSION} to ${NEW_VERSION}" | ||
|
|
||
| # Update .promu.yml | ||
| sed -i.bak -E "s/^([[:space:]]*version:[[:space:]]*)[0-9]+\.[0-9]+/\1${NEW_VERSION}/" .promu.yml |
There was a problem hiding this comment.
we can forget about the spaces.
Also use CURRENT_VERSION instead of a regex
scripts/update_go_version.sh
Outdated
| sed -i.bak -E "s/^([[:space:]]*version:[[:space:]]*)[0-9]+\.[0-9]+/\1${NEW_VERSION}/" .promu.yml | ||
|
|
||
| # Update go.mod | ||
| sed -i.bak -E "s/^go [0-9]+\.[0-9]+\.[0-9]+$/go ${CURRENT_VERSION}.0/" go.mod |
There was a problem hiding this comment.
let's use go mod edit -go= for those.
Makefile
Outdated
|
|
||
| .PHONY: update-go-version | ||
| update-go-version: | ||
| @echo ">> updating Go version" |
There was a problem hiding this comment.
| @echo ">> updating Go version" | |
| @echo ">> updating Go minor version" |
Makefile
Outdated
| .PHONY: update-go-version | ||
| update-go-version: | ||
| @echo ">> updating Go version" | ||
| @read -p "Current Go version (e.g., 1.22): " current_version && \ |
There was a problem hiding this comment.
actually, we can even get the N-1 version from go.mod using something like go mod edit -json go.mod | jq -r .Go | cut -d '.' -f1,2 (assuming jq is available, no need to check for that)
so we can make the script take no argument, and have something like:
we can state that the script only handles minor bumps
# with the help of an llm
version=$(go mod edit -json go.mod | jq -r .Go)
# Extract major & minor
major=${version%%.*} # "1"
minor=${version#*.}; minor=${minor%%.*} # "23"
# Bump
new_minor=$(( minor + 1 )) # e.g. 24
# Rejoin
echo "${major}.${minor}"
There was a problem hiding this comment.
this will pick up version from go.mod file which we need to update to new version is we manually change the version to new version in go.mod file ?
There was a problem hiding this comment.
not sure I get the issue, could you provide an example?
scripts/update_go_version.sh
Outdated
| gsub(/image: quay.io\/prometheus\/golang-builder:[0-9]+\.[0-9]+(-base)/, "image: quay.io/prometheus/golang-builder:'"${CURRENT_VERSION}"'-base"); | ||
| } | ||
| } | ||
| {print}' .github/workflows/ci.yml > .github/workflows/ci.yml.new && mv .github/workflows/ci.yml.new .github/workflows/ci.yml |
There was a problem hiding this comment.
just change the files in-place
scripts/update_go_version.sh
Outdated
| # Clean up backup files | ||
| find . -name "*.bak" -type f -delete | ||
|
|
||
| echo "Go version updated successfully from ${CURRENT_VERSION} to ${NEW_VERSION}" |
scripts/update_go_version.sh
Outdated
|
|
||
|
|
||
| # Update golangci-lint.yml - replace any version with the new version | ||
| sed -i.bak "s/go-version: [0-9][0-9]*\.[0-9][0-9]*\.x/go-version: ${NEW_VERSION}.x/g" scripts/golangci-lint.yml |
There was a problem hiding this comment.
use exact match, no need for regex
| # Update remote_storage example go.mod | ||
| (cd documentation/examples/remote_storage && go mod edit -go=${CURRENT_VERSION}.0) | ||
|
|
||
| echo "Please review the changes and commit them." No newline at end of file |
There was a problem hiding this comment.
let's have an blank line at the end
|
|
||
| echo "Current version: ${CURRENT_VERSION}" | ||
| echo "New version: ${NEW_VERSION}" | ||
| echo "Updating Go version from ${CURRENT_VERSION} to ${NEW_VERSION}" |
There was a problem hiding this comment.
Let's remove this as redundant.
| # Get current Go version from go.mod and calculate next minor version | ||
| current_full_version=$(go mod edit -json go.mod | jq -r .Go) | ||
| # Extract major & minor | ||
| major=${current_full_version%%.*} # "1" | ||
| minor=${current_full_version#*.}; minor=${minor%%.*} # "23" |
There was a problem hiding this comment.
not: we can also, in one line do
IFS='.' read -r major minor _ <<< "$(go mod edit -json go.mod | jq -r .Go)"
| # Update GitHub workflow files | ||
| sed -i '' -E "s|(quay\.io/prometheus/golang-builder:)[0-9]+\.[0-9]+(-base)|\1${NEW_VERSION}\2|g" .github/workflows/ci.yml | ||
| sed -i '' -E "s/go-version: [0-9]+\.[0-9]+\.x/go-version: ${NEW_VERSION}.x/" .github/workflows/ci.yml | ||
| sed -i '' -E "/name: Go tests with previous Go version/,/steps:/ { s|(quay\.io/prometheus/golang-builder:)[0-9]+\.[0-9]+(-base)|\1${CURRENT_VERSION}\2|g; }" .github/workflows/ci.yml |
There was a problem hiding this comment.
no need to match on the whole quay\.io/prometheus/..., just golang-builder:...
| go mod edit -go=${CURRENT_VERSION}.0 | ||
|
|
||
| # Update GitHub workflow files | ||
| sed -i '' -E "s|(quay\.io/prometheus/golang-builder:)[0-9]+\.[0-9]+(-base)|\1${NEW_VERSION}\2|g" .github/workflows/ci.yml |
There was a problem hiding this comment.
we can do without the [0-9]+... given that we know the maj.min or the previous, current and new versions...
|
Thanks, don't hesitate to resolve conversations when done. |
Okay sure, will be working these changes |
|
@manojks1999 are you still planning to complete this? |
|
thanks for this. |
Fixes #16446