Skip to content

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

Draft
Copilot wants to merge 6 commits intotrunkfrom
copilot/update-bump-go-script-resilience
Draft

Fix bump-go.sh to tolerate missing toolchain directive#12581
Copilot wants to merge 6 commits intotrunkfrom
copilot/update-bump-go-script-resilience

Conversation

Copy link
Contributor

Copilot AI commented Jan 29, 2026

Summary: Fix bump-go.sh to tolerate missing toolchain directive

Successfully updated the script to handle missing toolchain directives and rewrote it using go mod edit commands.

Latest Changes (This Commit)

Simplified jq output handling based on code review feedback:

  • Removed unnecessary == "null" checks (lines 56-57, 160)
  • jq -r '.Field // ""' already returns empty string for null/missing values
  • The -r (raw) flag ensures we get unquoted output
  • The // "" operator provides empty string as default

Previous Changes

Replaced manual parsing with go mod edit:

  • Use go mod edit -json | jq to read go and toolchain directives
  • Use go mod edit -go and -toolchain to update directives
  • More reliable than grep/sed text manipulation

Smart version comparison:

  • Compare major.minor versions to handle both X.Y.0 and X.Y.Z formats
  • Prevents unnecessary downgrades

Proper error handling:

  • Early trap setup with BRANCH_CREATED flag
  • Clear messaging when toolchain is missing (expected behavior)

All scenarios tested and working correctly.

Original prompt

Currently, the bump-go.sh script expects a toolchain directive in go.mod. However, when library maintainers bump their minimum Go version to the latest, we are forced to also bump ours, causing go mod tidy to remove the toolchain line if the minimum Go version matches the latest toolchain. This causes workflow disruptions. Update the bump-go.sh script to tolerate (and not fail on) missing toolchain when the minimum Go version equals the latest toolchain. The script should, as much as possible, preserve the lowest possible minimum Go version while keeping the highest possible toolchain version specified. Improve its resilience and add checks or notes to clarify why the toolchain may be missing in certain cases (i.e., this is expected when minimum Go == latest toolchain).

This pull request was created from Copilot chat.


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

Copilot AI and others added 3 commits January 29, 2026 19:11
- 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>
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
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.

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>
Copy link
Contributor Author

Copilot AI commented Jan 29, 2026

@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 == &#34;Bump Go to 1.25.6&#34;) | .title) | length &gt; 0 (http block)

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

Comment on lines 56 to 57
[[ "$CURRENT_GO_DIRECTIVE" == "null" || -z "$CURRENT_GO_DIRECTIVE" ]] && CURRENT_GO_DIRECTIVE=""
[[ "$CURRENT_TOOLCHAIN_DIRECTIVE" == "null" || -z "$CURRENT_TOOLCHAIN_DIRECTIVE" ]] && CURRENT_TOOLCHAIN_DIRECTIVE=""
Copy link
Member

Choose a reason for hiding this comment

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

@copilot These vars cannot be "null", right? They're just defaulted to "".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct! With jq -r '.Field // ""', the output is always an empty string for null/missing values, never the literal "null". Removed the unnecessary checks in commit b7fd470.

FINAL_TOOLCHAIN_DIRECTIVE=$(jq -r '.Toolchain // ""' <<< "$FINAL_GO_MOD_JSON")

# Handle empty/null values
[[ "$FINAL_TOOLCHAIN_DIRECTIVE" == "null" || -z "$FINAL_TOOLCHAIN_DIRECTIVE" ]] && FINAL_TOOLCHAIN_DIRECTIVE=""
Copy link
Member

Choose a reason for hiding this comment

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

@copilot also this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit b7fd470.

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>
Comment on lines +73 to +89
if [[ "$CURRENT_MAJOR_MINOR" = "$LATEST_MAJOR_MINOR" ]]; then
# Current go directive is at the same major.minor as latest
if [[ -z "$CURRENT_TOOLCHAIN_DIRECTIVE" ]]; then
# No toolchain directive present - this is expected when go version matches latest
echo "Already on latest Go version: $CURRENT_GO_DIRECTIVE (latest toolchain: $TOOLCHAIN_VERSION)"
echo " → Note: No toolchain directive (expected when go version matches latest toolchain)"
exit 0
elif [[ "$CURRENT_TOOLCHAIN_DIRECTIVE" = "go$TOOLCHAIN_VERSION" ]]; then
echo "Already on latest Go version: $CURRENT_GO_DIRECTIVE (toolchain: $CURRENT_TOOLCHAIN_DIRECTIVE)"
exit 0
fi
# Current go directive is latest but toolchain is outdated - continue to update toolchain
fi

echo "Creating branch $BRANCH"
git switch -c "$BRANCH" >/dev/null 2>&1

# ---- Patch go.mod -----------------------------------------------------------
if [[ "$CURRENT_GO_DIRECTIVE" != "$GO_DIRECTIVE_VERSION" ]]; then
sed -Ei.bak "s/^go [0-9]+\.[0-9]+.*$/go $GO_DIRECTIVE_VERSION/" "$GO_MOD"
echo " • go directive $CURRENT_GO_DIRECTIVE → $GO_DIRECTIVE_VERSION"
BRANCH_CREATED=1
Copy link
Member

Choose a reason for hiding this comment

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

@williammartin maybe we should get rid of this part, and apply the toolchain regardess. Then run a tidy at the end to wrap up?

Copilot AI requested a review from babakks January 29, 2026 19:55
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.

3 participants