Skip to content

Commit

Permalink
Auto upgrade the Golang version (#12585)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
frouioui and mattlord authored Mar 23, 2023
1 parent 7c033f4 commit ae3589a
Show file tree
Hide file tree
Showing 4 changed files with 581 additions and 1 deletion.
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

0 comments on commit ae3589a

Please sign in to comment.