Workflow: go-upgrade-workflow
This skill guides you through the process of safely upgrading Go dependencies. Follow these steps exactly to ensure project stability and maintain a clean go.mod file.
Prerequisites
Before starting, ensure:
- • Go toolchain (1.11+) is installed and available in the PATH.
- • A
go.modfile exists in the project root. - • The current codebase compiles and the test suite is passing.
Steps
1. Preparation & Baseline
- •Integrity Check:
- •Run
go mod verifyto ensure the local cache has not been tampered with.
- •Run
- •Health Check:
- •Run the test suite:
go test ./... - •Verification: If tests fail, do not proceed until the baseline is fixed.
- •Run the test suite:
- •Back up Module Files:
- •
cp go.mod go.mod.bak - •
cp go.sum go.sum.bak - •Verification: Check that backup files exist.
- •
2. Execution
Choose one of the following upgrade paths:
- •Option A: Full Upgrade (All dependencies to latest minor/patch):
- •Run
go get -u ./...
- •Run
- •Option B: Patch-only Upgrade (All dependencies to latest patch):
- •Run
go get -u=patch ./...
- •Run
- •Option C: Targeted Upgrade (Specific package):
- •Run
go get -u <package_path>(e.g.,go get -u github.com/gin-gonic/gin)
- •Run
3. Validation & Tidying
- •Tidy Modules:
- •Run
go mod tidyto remove unused dependencies and updatego.sum. - •Verification: Ensure no errors are reported by
go mod tidy.
- •Run
- •Verify Integrity:
- •Run
go mod verifyagain.
- •Run
- •Run Tests:
- •Run
go test ./... - •Verification: Ensure all tests pass with the upgraded dependencies.
- •Run
- •Linting (Optional but Recommended):
- •If
trunkis available, runtrunk check. - •Otherwise, run your project's standard linter (e.g.,
golangci-lint run).
- •If
4. Finalization
- •Cleanup:
- •If all validations pass, remove the backups:
rm go.mod.bak go.sum.bak.
- •If all validations pass, remove the backups:
- •Commit Changes:
- •Commit
go.modandgo.sum.
- •Commit
Rollback / Failure Handling
If any step fails, especially the validation or test steps:
- •Restore Module Files:
- •
mv go.mod.bak go.mod - •
mv go.sum.bak go.sum
- •
- •Verify Restore:
- •Run
go mod downloadto ensure the original state is restored.
- •Run
- •Report Failure:
- •Provide the failure logs and list the packages that were being upgraded.