| name | go-upgrade-workflow |
| description | Step-by-step workflow for safely upgrading Go dependencies using the standard Go toolchain. |
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:
Steps
1. Preparation & Baseline
- Integrity Check:
- Run
go mod verify to ensure the local cache has not been tampered with.
- Health Check:
- Run the test suite:
go test ./...
- Verification: If tests fail, do not proceed until the baseline is fixed.
- 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):
- Option B: Patch-only Upgrade (All dependencies to latest patch):
- Run
go get -u=patch ./...
- Option C: Targeted Upgrade (Specific package):
- Run
go get -u <package_path> (e.g., go get -u github.com/gin-gonic/gin)
3. Validation & Tidying
- Tidy Modules:
- Run
go mod tidy to remove unused dependencies and update go.sum.
- Verification: Ensure no errors are reported by
go mod tidy.
- Verify Integrity:
- Run Tests:
- Run
go test ./...
- Verification: Ensure all tests pass with the upgraded dependencies.
- Linting (Optional but Recommended):
- If
trunk is available, run trunk check.
- Otherwise, run your project's standard linter (e.g.,
golangci-lint run).
4. Finalization
- Cleanup:
- If all validations pass, remove the backups:
rm go.mod.bak go.sum.bak.
- Commit Changes:
- Commit
go.mod and go.sum.
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 download to ensure the original state is restored.
- Report Failure:
- Provide the failure logs and list the packages that were being upgraded.