Skip to content

Script for golang version update | Issue 16446#16488

Closed
manojks1999 wants to merge 2 commits intoprometheus:mainfrom
manojks1999:golang_version_update_script
Closed

Script for golang version update | Issue 16446#16488
manojks1999 wants to merge 2 commits intoprometheus:mainfrom
manojks1999:golang_version_update_script

Conversation

@manojks1999
Copy link

Fixes #16446

@aknuds1
Copy link
Contributor

aknuds1 commented Apr 27, 2025

You need to sign your commit, as otherwise the DCO check fails.

Copy link
Member

@machine424 machine424 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this.
Have some suggestions to simplify this.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for backups, git should take care of that

#
# Update Go version across the Prometheus project.
# Run from repository root.
set -e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just set -euo pipefail as the others.

set -e
set -u

if ! [[ "$0" =~ "scripts/update_go_version.sh" ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for this, the makefile target should/will be used.

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
Copy link
Member

@machine424 machine424 Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can forget about the spaces.
Also use CURRENT_VERSION instead of a regex

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use go mod edit -go= for those.

Makefile Outdated

.PHONY: update-go-version
update-go-version:
@echo ">> updating Go version"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@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 && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}" 

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I get the issue, could you provide an example?

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just change the files in-place

# Clean up backup files
find . -name "*.bak" -type f -delete

echo "Go version updated successfully from ${CURRENT_VERSION} to ${NEW_VERSION}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for this one



# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use exact match, no need for regex

@aknuds1 aknuds1 requested a review from machine424 May 26, 2025 15:25
Copy link
Member

@machine424 machine424 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some last suggestions.

# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this as redundant.

Comment on lines +7 to +11
# 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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do without the [0-9]+... given that we know the maj.min or the previous, current and new versions...

@machine424
Copy link
Member

Thanks, don't hesitate to resolve conversations when done.

@manojks1999
Copy link
Author

Thanks, don't hesitate to resolve conversations when done.

Okay sure, will be working these changes

@beorn7
Copy link
Member

beorn7 commented Jul 9, 2025

@manojks1999 are you still planning to complete this?

@machine424
Copy link
Member

thanks for this.
taking over in #17090

@machine424 machine424 closed this Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

automate Go version updates

4 participants