Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto upgrade the Golang version #12585

Merged
merged 35 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
47478c3
initial addition of the go_upgrade tool to detect and bump the golang…
frouioui Mar 8, 2023
69b49cd
update go.mod automatically
frouioui Mar 8, 2023
67ecb1e
fix isSameMajor version issue
frouioui Mar 8, 2023
48605c9
update the bootstrap version automatically
frouioui Mar 8, 2023
5cfb9b0
update the bootstrap docker image changelog
frouioui Mar 8, 2023
3653826
uncomment code
frouioui Mar 8, 2023
89ec9ad
addition of workflow
frouioui Mar 8, 2023
49986d4
addition of base to create-pull-request
frouioui Mar 8, 2023
fea3561
test create PR alternative
frouioui Mar 9, 2023
fc03b1d
add flags and getter methods
frouioui Mar 9, 2023
b5b6bea
better PR message
frouioui Mar 9, 2023
f2366ff
fix no-workflow-update flag and better PR body msg
frouioui Mar 9, 2023
cbebdc3
fix PR title, branch and body format
frouioui Mar 9, 2023
1857ee3
test matrix and pwd path
frouioui Mar 9, 2023
6bcbee5
enhanced matrix
frouioui Mar 9, 2023
4c04517
update_workflows option
frouioui Mar 9, 2023
3687edd
update workflows independently
frouioui Mar 9, 2023
ec20bb5
test without matrix
frouioui Mar 9, 2023
32315a8
Add docs to go_upgrade and re-add matrix to the workflow
frouioui Mar 9, 2023
7263e6a
Merge remote-tracking branch 'origin/main' into auto-upgrade-go-version
frouioui Mar 9, 2023
8d3ed02
support major version upgrade
frouioui Mar 14, 2023
a1f71bf
do not update bootstrap version if they are the same
frouioui Mar 14, 2023
0da9846
migrate to cobra instead of pflags
frouioui Mar 14, 2023
f7287cb
remove redundant comment
frouioui Mar 14, 2023
223e72d
safety net around replaceGoVersionInCodebase to avoid unrequired upgrade
frouioui Mar 14, 2023
9603619
Remove double negation in workflowUpdate flag
frouioui Mar 14, 2023
49b4d32
Use regexp instead of mere string comparison
frouioui Mar 14, 2023
77bd2a7
Proper regexp for every string comparison
frouioui Mar 15, 2023
e341a1f
use better regex
frouioui Mar 15, 2023
89243a7
remove useless flag and improve the auto-PR body description
frouioui Mar 15, 2023
c9579a4
add note in the tool usage to run the tool at the root of the repo
frouioui Mar 15, 2023
bf35983
add comment in .github/workflows/update_golang_version.yml
frouioui Mar 17, 2023
c6f56d3
Apply @mattlord code suggestion
frouioui Mar 20, 2023
a5a4327
replace usages of old filename
frouioui Mar 22, 2023
0a0e9fa
Apply suggestions from code review
frouioui Mar 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/update_golang_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Update Golang Version

on:
schedule:
- cron: "0 0 * * *" # Runs every day at midnight UTC
workflow_dispatch:

jobs:
update_golang_version:
strategy:
matrix:
branch: [ main, release-16.0, release-15.0, release-14.0 ]
name: Update Golang Version
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.20.2

- name: Check out code
uses: actions/checkout@v3
with:
ref: ${{ matrix.branch }}

- name: Detect new version and update codebase
id: detect-and-update
run: |
old_go_version=$(go run ./go/tools/go-upgrade/go-upgrade.go get go-version)
echo "old-go-version=${old_go_version}" >> $GITHUB_OUTPUT

if [ ${{ matrix.branch }} == "main" ]; then
go run ./go/tools/go-upgrade/go-upgrade.go upgrade --workflow-update=false --main --allow-major-upgrade
else
go run ./go/tools/go-upgrade/go-upgrade.go upgrade --workflow-update=false
fi

output=$(git status -s)
if [ -z "${output}" ]; then
exit 0
fi
echo "create-pr=true" >> $GITHUB_OUTPUT

go_version=$(go run ./go/tools/go-upgrade/go-upgrade.go get go-version)
bootstrap_version=$(go run ./go/tools/go-upgrade/go-upgrade.go get bootstrap-version)
echo "go-version=${go_version}" >> $GITHUB_OUTPUT
echo "bootstrap-version=${bootstrap_version}" >> $GITHUB_OUTPUT

- name: Create Pull Request
if: steps.detect-and-update.outputs.create-pr == 'true'
uses: peter-evans/create-pull-request@v4
with:
branch: "upgrade-go-to-${{steps.detect-and-update.outputs.go-version}}-on-${{ matrix.branch }}"
commit-message: "bump go version to go${{steps.detect-and-update.outputs.go-version}}"
signoff: true
delete-branch: true
title: "[${{ matrix.branch }}] Upgrade the Golang version to `go${{steps.detect-and-update.outputs.go-version}}`"
body: |
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}}`.

> Do not trust the bot blindly. A thorough code review must be done to ensure all the files have been correctly modified.

There are a few manual steps remaining:
- [ ] Make sure you update the Golang version used in the previous and next release branches for the Upgrade/Downgrade tests.
- [ ] Build and Push the bootstrap images to Docker Hub, the bot cannot handle that.
- [ ] Update the `./.github/workflows/*.yml` files with the newer Golang version, the bot cannot handle that due to permissions.
- 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}}`
base: ${{ matrix.branch }}
labels: |
Skip CI
go
Benchmark me
Component: General
Type: CI/Build
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ require (

require (
github.com/bndr/gotabulate v1.1.2
github.com/hashicorp/go-version v1.6.0
github.com/kr/pretty v0.3.1
github.com/kr/text v0.2.0
github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,9 @@ github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
Expand Down
Loading