Skip to content

Commit b632186

Browse files
frouiouimattlord
andauthored
[release-15.0] Auto upgrade the Golang version (vitessio#12585) (vitessio#12708)
* Auto upgrade the Golang version (vitessio#12585) * initial addition of the go_upgrade tool to detect and bump the golang version Signed-off-by: Florent Poinsard <[email protected]> * update go.mod automatically Signed-off-by: Florent Poinsard <[email protected]> * fix isSameMajor version issue Signed-off-by: Florent Poinsard <[email protected]> * update the bootstrap version automatically Signed-off-by: Florent Poinsard <[email protected]> * update the bootstrap docker image changelog Signed-off-by: Florent Poinsard <[email protected]> * uncomment code Signed-off-by: Florent Poinsard <[email protected]> * addition of workflow Signed-off-by: Florent Poinsard <[email protected]> * addition of base to create-pull-request Signed-off-by: Florent Poinsard <[email protected]> * test create PR alternative Signed-off-by: Florent Poinsard <[email protected]> * add flags and getter methods Signed-off-by: Florent Poinsard <[email protected]> * better PR message Signed-off-by: Florent Poinsard <[email protected]> * fix no-workflow-update flag and better PR body msg Signed-off-by: Florent Poinsard <[email protected]> * fix PR title, branch and body format Signed-off-by: Florent Poinsard <[email protected]> * test matrix and pwd path Signed-off-by: Florent Poinsard <[email protected]> * enhanced matrix Signed-off-by: Florent Poinsard <[email protected]> * update_workflows option Signed-off-by: Florent Poinsard <[email protected]> * update workflows independently Signed-off-by: Florent Poinsard <[email protected]> * test without matrix Signed-off-by: Florent Poinsard <[email protected]> * Add docs to go_upgrade and re-add matrix to the workflow Signed-off-by: Florent Poinsard <[email protected]> * support major version upgrade Signed-off-by: Florent Poinsard <[email protected]> * do not update bootstrap version if they are the same Signed-off-by: Florent Poinsard <[email protected]> * migrate to cobra instead of pflags Signed-off-by: Florent Poinsard <[email protected]> * remove redundant comment Signed-off-by: Florent Poinsard <[email protected]> * safety net around replaceGoVersionInCodebase to avoid unrequired upgrade Signed-off-by: Florent Poinsard <[email protected]> * Remove double negation in workflowUpdate flag Signed-off-by: Florent Poinsard <[email protected]> * Use regexp instead of mere string comparison Signed-off-by: Florent Poinsard <[email protected]> * Proper regexp for every string comparison Signed-off-by: Florent Poinsard <[email protected]> * use better regex Signed-off-by: Florent Poinsard <[email protected]> * remove useless flag and improve the auto-PR body description Signed-off-by: Florent Poinsard <[email protected]> * add note in the tool usage to run the tool at the root of the repo Signed-off-by: Florent Poinsard <[email protected]> * add comment in .github/workflows/update_golang_version.yml Signed-off-by: Florent Poinsard <[email protected]> * Apply @mattlord code suggestion Signed-off-by: Florent Poinsard <[email protected]> * replace usages of old filename Signed-off-by: Florent Poinsard <[email protected]> * Apply suggestions from code review Co-authored-by: Matt Lord <[email protected]> Signed-off-by: Florent Poinsard <[email protected]> --------- Signed-off-by: Florent Poinsard <[email protected]> Signed-off-by: Florent Poinsard <[email protected]> Co-authored-by: Matt Lord <[email protected]> * Fix regexp Signed-off-by: Florent Poinsard <[email protected]> * remove the use of DateOnly Signed-off-by: Florent Poinsard <[email protected]> --------- Signed-off-by: Florent Poinsard <[email protected]> Signed-off-by: Florent Poinsard <[email protected]> Co-authored-by: Matt Lord <[email protected]>
1 parent 32a374b commit b632186

File tree

4 files changed

+581
-0
lines changed

4 files changed

+581
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Update Golang Version
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *" # Runs every day at midnight UTC
6+
workflow_dispatch:
7+
8+
jobs:
9+
update_golang_version:
10+
strategy:
11+
matrix:
12+
branch: [ main, release-16.0, release-15.0, release-14.0 ]
13+
name: Update Golang Version
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Set up Go
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: 1.20.2
20+
21+
- name: Check out code
22+
uses: actions/checkout@v3
23+
with:
24+
ref: ${{ matrix.branch }}
25+
26+
- name: Detect new version and update codebase
27+
id: detect-and-update
28+
run: |
29+
old_go_version=$(go run ./go/tools/go-upgrade/go-upgrade.go get go-version)
30+
echo "old-go-version=${old_go_version}" >> $GITHUB_OUTPUT
31+
32+
if [ ${{ matrix.branch }} == "main" ]; then
33+
go run ./go/tools/go-upgrade/go-upgrade.go upgrade --workflow-update=false --main --allow-major-upgrade
34+
else
35+
go run ./go/tools/go-upgrade/go-upgrade.go upgrade --workflow-update=false
36+
fi
37+
38+
output=$(git status -s)
39+
if [ -z "${output}" ]; then
40+
exit 0
41+
fi
42+
echo "create-pr=true" >> $GITHUB_OUTPUT
43+
44+
go_version=$(go run ./go/tools/go-upgrade/go-upgrade.go get go-version)
45+
bootstrap_version=$(go run ./go/tools/go-upgrade/go-upgrade.go get bootstrap-version)
46+
echo "go-version=${go_version}" >> $GITHUB_OUTPUT
47+
echo "bootstrap-version=${bootstrap_version}" >> $GITHUB_OUTPUT
48+
49+
- name: Create Pull Request
50+
if: steps.detect-and-update.outputs.create-pr == 'true'
51+
uses: peter-evans/create-pull-request@v4
52+
with:
53+
branch: "upgrade-go-to-${{steps.detect-and-update.outputs.go-version}}-on-${{ matrix.branch }}"
54+
commit-message: "bump go version to go${{steps.detect-and-update.outputs.go-version}}"
55+
signoff: true
56+
delete-branch: true
57+
title: "[${{ matrix.branch }}] Upgrade the Golang version to `go${{steps.detect-and-update.outputs.go-version}}`"
58+
body: |
59+
This Pull Request bumps the Golang version to `go${{steps.detect-and-update.outputs.go-version}}` and the bootstrap version to `${{steps.detect-and-update.outputs.bootstrap-version}}`.
60+
61+
> Do not trust the bot blindly. A thorough code review must be done to ensure all the files have been correctly modified.
62+
63+
There are a few manual steps remaining:
64+
- [ ] Make sure you update the Golang version used in the previous and next release branches for the Upgrade/Downgrade tests.
65+
- [ ] Build and Push the bootstrap images to Docker Hub, the bot cannot handle that.
66+
- [ ] Update the `./.github/workflows/*.yml` files with the newer Golang version, the bot cannot handle that due to permissions.
67+
- To accomplish this, run the following: `go run ./go/tools/go-upgrade/go-upgrade.go upgrade workflows --go-to=${{steps.detect-and-update.outputs.go-version}}`
68+
base: ${{ matrix.branch }}
69+
labels: |
70+
Skip CI
71+
go
72+
Benchmark me
73+
Component: General
74+
Type: CI/Build

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ require (
117117

118118
require (
119119
github.com/bndr/gotabulate v1.1.2
120+
github.com/hashicorp/go-version v1.6.0
120121
modernc.org/sqlite v1.20.3
121122
)
122123

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b
426426
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
427427
github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE=
428428
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
429+
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
430+
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
429431
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
430432
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
431433
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=

0 commit comments

Comments
 (0)