Skip to content

Fix bump-go.sh to tolerate missing toolchain directive#12581

Merged
williammartin merged 7 commits into
trunkfrom
copilot/update-bump-go-script-resilience
May 13, 2026
Merged

Fix bump-go.sh to tolerate missing toolchain directive#12581
williammartin merged 7 commits into
trunkfrom
copilot/update-bump-go-script-resilience

Conversation

Copilot AI commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Summary: Improve bump-go.sh resilience and simplify toolchain handling

Fixes the bump-go.sh script to tolerate missing toolchain directives in go.mod and simplifies the core logic.

Problem

When library maintainers bump their minimum Go version to the latest, go mod tidy removes the toolchain line from go.mod (because it becomes redundant). The previous script expected the toolchain directive to always be present and used fragile grep/sed text manipulation, causing workflow failures.

Changes

Replaced manual parsing with go mod edit:

  • Read go.mod state via go mod edit -json | jq instead of grep
  • Write directives via go mod edit -go and -toolchain instead of sed

Simplified toolchain logic (addresses review feedback):

  • Always set both go and toolchain directives via go mod edit
  • Run go mod tidy afterward to normalize — if the toolchain line is redundant, tidy removes it (this is expected Go behavior)
  • Eliminates the previous complex conditional logic for add/skip/update toolchain

Use git diff for up-to-date detection:

  • Instead of manually comparing version strings, apply changes + tidy, then check git diff --quiet
  • Handles all edge cases (missing toolchain, patch-level go directive, etc.) correctly

Additional improvements:

  • Commit go.sum alongside go.mod (tidy updates both)
  • Filter existing PR search to open PRs only (--state open)
  • Use $GITHUB_REPOSITORY instead of hardcoded cli/cli
  • Guard cleanup trap with BRANCH_CREATED flag to avoid errors on early exit

Copilot AI changed the title [WIP] Update bump-go.sh to handle missing toolchain gracefully Fix bump-go.sh to tolerate missing toolchain directive Jan 29, 2026
Copilot AI requested a review from williammartin January 29, 2026 19:19
@williammartin

Copy link
Copy Markdown
Member

@copilot can you rewrite this using go mod edit -json | jq to get the details and go mod edit -go and go mod edit -toolchain to do the edits, rather than my janky script.

Copilot AI commented Jan 29, 2026

Copy link
Copy Markdown
Contributor Author

@copilot can you rewrite this using go mod edit -json | jq to get the details and go mod edit -go and go mod edit -toolchain to do the edits, rather than my janky script.

Done! Rewrote the script to use go mod edit -json | jq for reading and go mod edit -go/-toolchain for editing. All grep/sed text manipulation has been replaced with official Go tooling. See commit aa57c27.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh gh search prs --repo cli/cli --match title Bump Go to 1.25.6 --json title --jq map(select(.title == "Bump Go to 1.25.6") | .title) | length > 0 (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Comment thread .github/workflows/scripts/bump-go.sh Outdated
Comment thread .github/workflows/scripts/bump-go.sh Outdated
Comment thread .github/workflows/scripts/bump-go.sh Outdated
Copilot AI requested a review from babakks January 29, 2026 19:55
Comment thread .github/workflows/scripts/bump-go.sh
@cli cli deleted a comment May 13, 2026
Copilot AI and others added 6 commits May 13, 2026 14:41
- Add early trap setup to avoid exit code issues
- Handle missing toolchain directive gracefully with `|| true`
- Add logic to detect when toolchain is expected to be missing
- Add informative messages about missing toolchain
- Implement smart toolchain handling:
  - Skip toolchain when go version matches latest (redundant)
  - Add toolchain when go version is older than latest
  - Update toolchain when it exists but is outdated

Co-authored-by: williammartin <1611510+williammartin@users.noreply.github.com>
- Compare major.minor versions instead of exact string match
- Preserve go directive if already at latest major.minor
- Handle cases where go.mod has full patch version (e.g., 1.25.6)
- Update PR body to use actual go directive from modified go.mod
- Add detailed comments explaining version handling logic

Co-authored-by: williammartin <1611510+williammartin@users.noreply.github.com>
- Clarify comment to say "matches" instead of "matches or exceeds"
- Update PR body to accurately reflect final go.mod state
- Show actual toolchain if present, or note it's not specified
- Provide clear explanation when toolchain is omitted

Co-authored-by: williammartin <1611510+williammartin@users.noreply.github.com>
Replace manual parsing and editing with go mod edit:
- Use 'go mod edit -json' to read current go and toolchain directives
- Use 'go mod edit -go' to update go directive
- Use 'go mod edit -toolchain' to update toolchain directive
- Remove manual sed/grep parsing and .bak file handling
- More reliable and maintainable than custom text manipulation

Co-authored-by: williammartin <1611510+williammartin@users.noreply.github.com>
The jq -r flag with // "" operator already returns empty string
for null/missing values, never the literal string "null".
The checks for == "null" are unnecessary.

Co-authored-by: babakks <36728931+babakks@users.noreply.github.com>
@williammartin williammartin marked this pull request as ready for review May 13, 2026 12:44
@williammartin williammartin requested a review from a team as a code owner May 13, 2026 12:44
Copilot AI review requested due to automatic review settings May 13, 2026 12:44
@williammartin williammartin force-pushed the copilot/update-bump-go-script-resilience branch from b7fd470 to d32b18e Compare May 13, 2026 12:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Improves the Go bump automation script to better handle go.mod files that may not contain a toolchain directive, moving parsing/editing to go mod edit -json + jq and adjusting branch cleanup/PR body generation.

Changes:

  • Replace grep/sed parsing with go mod edit -json + jq, and update go.mod via go mod edit -go / -toolchain.
  • Add early “up-to-date” detection that tolerates missing toolchain, and guard branch cleanup with a BRANCH_CREATED flag.
  • Build PR body from the post-edit go.mod state (including a “toolchain not specified” case).
Show a summary per file
File Description
.github/workflows/scripts/bump-go.sh Switches to go mod edit-based parsing/editing and adjusts toolchain/up-to-date logic, cleanup handling, and PR body generation.

Copilot's findings

Tip

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

Comments suppressed due to low confidence (3)

.github/workflows/scripts/bump-go.sh:99

  • NEW_GO_DIRECTIVE is forced to X.Y.0, but this repository’s go.mod currently uses a patch-level go directive (e.g. go 1.25.6). Forcing .0 will change both style and semantics (minimum required patch), and it also makes the “toolchain becomes redundant” path less likely to occur. Consider preserving the existing go directive form (patch vs .0) or setting it to the target toolchain patch version.

git add "$GO_MOD"
[[ -f "$GO_SUM" ]] && git add "$GO_SUM"

# ---- Commit -----------------------------------------------------------------
COMMIT_MSG="Bump Go to $TOOLCHAIN_VERSION"
git commit -m "$COMMIT_MSG" >/dev/null

.github/workflows/scripts/bump-go.sh:153

  • PR description mentions switching the PR search to --state open and using $GITHUB_REPOSITORY instead of a hardcoded repo, but the script still runs gh search prs --repo cli/cli without --state open (later in the file). Either update the implementation to match the description or adjust the PR description to avoid documenting changes that aren’t present.
    .github/workflows/scripts/bump-go.sh:169
  • In the no-toolchain PR body path, the text says “go version matches latest toolchain X.Y.Z”, but the script’s logic treats a major.minor match as “latest” and may set the go directive to X.Y.0. That message can be misleading (especially for patch releases). Consider either bumping the go directive to the full patch version or rewording this line to explicitly state it’s matching only major.minor.
  • Files reviewed: 1/1 changed files
  • Comments generated: 2

Comment thread .github/workflows/scripts/bump-go.sh
Comment thread .github/workflows/scripts/bump-go.sh
@williammartin williammartin requested a review from Copilot May 13, 2026 12:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread .github/workflows/scripts/bump-go.sh
Comment thread .github/workflows/scripts/bump-go.sh Outdated
Comment thread .github/workflows/scripts/bump-go.sh Outdated
Address review feedback: always set both go and toolchain
directives via go mod edit, then let go mod tidy normalize.
This eliminates complex conditional toolchain handling.

Additional fixes:
- Add go mod tidy after edits to reconcile dependencies
- Commit go.sum alongside go.mod
- Filter PR search to open PRs only (--state open)
- Use GITHUB_REPOSITORY for repo instead of hardcoding
- Use git diff to detect no-op bumps post-tidy
- Read go.mod state via go mod edit -json instead of grep

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@williammartin williammartin force-pushed the copilot/update-bump-go-script-resilience branch from d32b18e to e5f5427 Compare May 13, 2026 13:29
@williammartin williammartin enabled auto-merge May 13, 2026 13:45
@williammartin williammartin merged commit 2b7e776 into trunk May 13, 2026
14 of 15 checks passed
@williammartin williammartin deleted the copilot/update-bump-go-script-resilience branch May 13, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants