Skip to content

feat: automated go fix PR on Go version bump#4678

Open
Copilot wants to merge 24 commits intomasterfrom
copilot/automate-go-fix-commands
Open

feat: automated go fix PR on Go version bump#4678
Copilot wants to merge 24 commits intomasterfrom
copilot/automate-go-fix-commands

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 11, 2026

Tracking Jira: ARO-25807

Adds a workflow to automatically open a PR running go fix on both Go modules (github.com/Azure/ARO-RP and github.com/Azure/ARO-RP/pkg/api) whenever the Go version directive in go.mod is bumped on master.

Changes

  • Makefilego-fix target: Runs go fix ./... on both modules, consistent with the existing fmt and lint-go-fix targets:

    .PHONY: go-fix
    go-fix: ## Run go fix on both Go modules
        go fix ./...
        cd pkg/api/ && go fix ./...
  • .github/workflows/go-fix.yml:

    • Triggers on push to master with paths: ['go.mod'], plus workflow_dispatch for manual runs
    • Guards execution: compares the go directive between HEAD and HEAD~1 to skip unrelated go.mod changes
    • Runs make go-fix, then opens a PR using the GitHub CLI (gh pr create) on branch automated/go-fix-<version> — no third-party actions required
    • Uses --force-with-lease on push and skips PR creation gracefully if go fix produces no changes
    • Requires contents: write + pull-requests: write permissions
  • test/e2e/{aks,aro,e2e_test}.go: Applied go fix to the current codebase — removes the redundant pre-Go 1.17 // +build constraint lines (superseded by //go:build).


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Mar 11, 2026

Hi @copilot. Thanks for your PR.

I'm waiting for a Azure member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Co-authored-by: tuxerrante <8364469+tuxerrante@users.noreply.github.com>
Copilot AI changed the title [WIP] Add automated go fix command for module updates feat: automated go fix PR on Go version bump Mar 11, 2026
@tuxerrante
Copy link
Copy Markdown
Collaborator

Co-authored-by: tuxerrante <8364469+tuxerrante@users.noreply.github.com>
Copilot AI requested a review from tuxerrante March 16, 2026 14:25
@tuxerrante
Copy link
Copy Markdown
Collaborator

tuxerrante commented Mar 16, 2026

Code review

Found 1 issue:

  1. The workflow only monitors the root go.mod for Go version changes, but the project has two independent Go modules with separate go.mod files (CLAUDE.md marks "Two Go Modules" as critical). If pkg/api/go.mod is bumped independently -- which is a real scenario since the two modules currently have different Go versions (root: 1.25.3, pkg/api: 1.24.0) -- the workflow will not trigger. Both the paths filter and the version detection logic need to account for pkg/api/go.mod.

branches:
- master
paths:
- 'go.mod'
workflow_dispatch:
permissions:
contents: write

The project has two Go modules with independent go.mod files.
The workflow now triggers on changes to both go.mod and
pkg/api/go.mod, and checks version changes in both.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tuxerrante tuxerrante marked this pull request as ready for review March 16, 2026 14:58
Copilot AI review requested due to automatic review settings March 16, 2026 14:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds automation to run go fix after Go version directive bumps and open a follow-up PR, while also applying the current go fix-driven build tag cleanup in existing e2e files.

Changes:

  • Adds a make go-fix target to run go fix ./... in both the root module and pkg/api.
  • Introduces a GitHub Actions workflow to detect go directive changes in go.mod / pkg/api/go.mod, run make go-fix, and open a PR with the results.
  • Applies go fix output to e2e tests by removing legacy // +build constraints (keeping //go:build).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
Makefile Adds go-fix target to run go fix across both Go modules.
.github/workflows/go-fix.yml New workflow to detect Go version bumps and automatically open a PR with go fix results.
test/e2e/e2e_test.go Removes redundant legacy build tag line per go fix.
test/e2e/aro.go Removes redundant legacy build tag line per go fix.
test/e2e/aks.go Removes redundant legacy build tag line per go fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

tuxerrante and others added 2 commits March 16, 2026 16:10
incorporating both module versions in the branch name

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- Add concurrency group to prevent parallel workflow conflicts
- Use higher of the two module Go versions for setup-go
- Include both module versions in branch name to avoid collisions
- Replace --force-with-lease with --force (remote ref not fetched)
- Make PR creation idempotent by checking for existing PR first
- Output both root and api versions in PR description

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tuxerrante
Copy link
Copy Markdown
Collaborator

Fixes applied

Addressed 5 of the 6 review comments from Copilot:

  1. Concurrency group — Added concurrency: group: go-fix to prevent parallel workflow runs from conflicting on the same branch/PR.

  2. setup-go version — Changed from go-version-file: go.mod (always root) to go-version: <highest>, computed via sort -V across both modules. This ensures go fix runs with the correct Go version regardless of which module was bumped.

  3. Branch naming — Changed from automated/go-fix-<root-version> to automated/go-fix-root-<root>-api-<api> to avoid collisions when only one module is bumped.

  4. --force-with-lease--force — The remote branch is never fetched (fetch-depth: 2 only fetches the main branch), so --force-with-lease provided no safety and could fail unexpectedly.

  5. Idempotent PR creation — Added a check for an existing PR on the head branch before calling gh pr create, so reruns don't fail.

Not fixed (false positive): git show HEAD~1:pkg/api/go.mod failure — both go.mod files have existed since 2023, and the workflow only triggers when these files are modified (meaning they already exist in HEAD).

group: go-fix
cancel-in-progress: false

permissions:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@mociarain do we have the rights for these permissions?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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:

  • Are these the correct permissions for the workflow?
  • Do we have the rights to grant these permissions?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The second one, I know these could be an issue:

  contents: write
  pull-requests: write

exit 0
fi
git commit -m "run go fix for Go ${{ steps.go-version.outputs.current }}"
git push --force origin "$BRANCH"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

with the idempotent PR check we added, you could argue the workflow should just skip entirely if the branch already exists. We could replace the force push with a check-and-skip:

  if git ls-remote --exit-code origin "refs/heads/$BRANCH" >/dev/null 2>&1; then
    echo "Branch $BRANCH already exists, skipping."
    exit 0
  fi
  git push origin "$BRANCH"

@@ -0,0 +1,95 @@
name: go-fix

on:
Copy link
Copy Markdown
Collaborator

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:

  • It triggers on pushes to master that modify go.mod
  • workflow_dispatch only works if the workflow file already exists on the default branch

To actually test this, you'd need to either:

  • Fork the repo and merge the workflow into the fork's default branch, then trigger workflow_dispatch
  • Create a test workflow on a branch that uses on: push to that branch instead of master (temporary, just for validation)
  • Merge to master and test live (risky for a first run)

Copy link
Copy Markdown
Collaborator

@mociarain mociarain left a comment

Choose a reason for hiding this comment

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

Could we do a PR off this one that bumps something in each of the go.mods to prove it works? Or does it have to be merged first?

@tuxerrante
Copy link
Copy Markdown
Collaborator

tuxerrante commented Apr 3, 2026

Could we do a PR off this one that bumps something in each of the go.mods to prove it works? Or does it have to be merged first?

@mociarain I can try if it would start also when pushing onto another branch which is not master

#4678 (comment)

test: temporarily trigger go-fix on PR branch
@tuxerrante
Copy link
Copy Markdown
Collaborator

tuxerrante commented Apr 3, 2026

Pre-merge workflow validation update (second pass):

  1. Obsolete action/runtime warning
  • Updated .github/workflows/go-fix.yml from step-security/harden-runner@v2.15.0 to v2.16.1 (fe104658747b27e96e4f7e80cd0a94068e53901d).
  • Merged via chore: bump harden-runner action to v2.16.1 #4746
  • In subsequent runs, no Node.js 20 actions are deprecated annotation was observed.
  1. Non-empty go-fix path validation for Go 1.26

Conclusion: PR creation was NOT skipped for empty output in the Go 1.26 scenario; it failed due GitHub Actions permissions.

  1. Cleanup/restoration after test

Current branch state (copilot/automate-go-fix-commands):

  • go.mod: go 1.25.3
  • pkg/api/go.mod: go 1.24.0
  • go-fix trigger scope: master only
  • harden-runner pin: v2.16.1

Note: remote branch automated/go-fix-root-1.26.1-api-1.26.1 exists from the failed create-PR step, but no PR was created for it.

tuxerrante and others added 10 commits April 3, 2026 10:38
chore: bump harden-runner action to v2.16.1
…enable

test: temporarily enable PR-branch go-fix trigger for go1.26 validation
test: trigger go-fix non-empty path with temporary Go 1.26.1 bump
test: revert temporary Go 1.26.1 module bumps
…cleanup

test: remove temporary PR-branch trigger after Go1.26 validation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants