-
Notifications
You must be signed in to change notification settings - Fork 194
feat: automated go fix PR on Go version bump
#4678
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
7767d9f
a6374a9
ebdf630
5db9b73
3f99150
9126898
d4a9722
3879147
1f91fd7
7a95d1d
3784dc5
fb5c7b9
571ebe7
eafb21f
b435f3b
d44eb07
8f40787
4b98a4c
6041e6a
3d5bb3d
33f87ce
cd3d504
890e8bb
cfcfad8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| name: go-fix | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| paths: | ||
tuxerrante marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - 'go.mod' | ||
| - 'pkg/api/go.mod' | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mociarain do we have the rights for these permissions?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They look correct to me but I'm sure what you are asking. Do you mean:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The second one, I know these could be an issue:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've granted "Allow GitHub Actions to create and approve pull requests" so hopefully this should be good now |
||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| go-fix: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0 | ||
| with: | ||
| egress-policy: audit | ||
|
|
||
| - name: Checkout | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| fetch-depth: 2 | ||
|
|
||
| - name: Check if Go version changed | ||
| id: go-version | ||
| run: | | ||
| ROOT_CURRENT=$(grep '^go ' go.mod | awk '{print $2}') | ||
| API_CURRENT=$(grep '^go ' pkg/api/go.mod | awk '{print $2}') | ||
tuxerrante marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo "current=$ROOT_CURRENT" >> "$GITHUB_OUTPUT" | ||
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | ||
| echo "run=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| ROOT_PREVIOUS=$(git show HEAD~1:go.mod | grep '^go ' | awk '{print $2}') | ||
| API_PREVIOUS=$(git show HEAD~1:pkg/api/go.mod | grep '^go ' | awk '{print $2}') | ||
| if [[ "$ROOT_CURRENT" != "$ROOT_PREVIOUS" ]] || [[ "$API_CURRENT" != "$API_PREVIOUS" ]]; then | ||
tuxerrante marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo "run=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "run=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
| fi | ||
|
|
||
| - name: Set up Golang | ||
| if: steps.go-version.outputs.run == 'true' | ||
| uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0 | ||
| with: | ||
| go-version-file: go.mod | ||
|
|
||
| - name: Run go fix | ||
| if: steps.go-version.outputs.run == 'true' | ||
| run: make go-fix | ||
|
|
||
| - name: Create Pull Request | ||
| if: steps.go-version.outputs.run == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| BRANCH="automated/go-fix-${{ steps.go-version.outputs.current }}" | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git checkout -b "$BRANCH" | ||
tuxerrante marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| git add -A | ||
| if git diff --staged --quiet; then | ||
| echo "No changes from go fix, skipping PR creation." | ||
| exit 0 | ||
| fi | ||
| git commit -m "run go fix for Go ${{ steps.go-version.outputs.current }}" | ||
tuxerrante marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| git push --force-with-lease origin "$BRANCH" | ||
tuxerrante marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| gh pr create \ | ||
| --title "go fix: apply Go ${{ steps.go-version.outputs.current }} fixes" \ | ||
| --body "This PR was automatically created to apply \`go fix\` changes after bumping Go to \`${{ steps.go-version.outputs.current }}\`. | ||
|
|
||
| \`go fix\` rewrites source code to use newer Go APIs and idioms." \ | ||
| --base "${{ github.event.repository.default_branch }}" \ | ||
| --head "$BRANCH" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| //go:build e2e | ||
| // +build e2e | ||
|
|
||
| package e2e | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| //go:build e2e | ||
| // +build e2e | ||
|
|
||
| package e2e | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This workflow can't be tested via normal CI because:
To actually test this, you'd need to either: