codeql
codeql copied to clipboard
Go: Use new type for all semantic versions
Context
Throughout the Go autobuilder, we handle semantic versions. The semver package has no dedicated type for them and all functions from the package work on string values. This makes it difficult to understand where in the code we have something that we know is a valid semantic version and where we might have a string value that isn't. This is made worse by semver requiring all semantic versions to have a v prefix.
What this PR does
We introduce a new SemVer interface, backed by an implementation based on a private type, which is intended to guarantee that a SemVer value is a valid semantic version. Since the type is not exported, the NewSemVer function must be used to construct SemVer values. This function expects any version string as input and formats it according to semver's requirements.
All existing code in the autobuilder is modified to use the SemVer type whereever we would previously have used functions from the semver package.
How to review
Best reviewed commit-by-commit.
After the set of most recent changes, some things to check:
- Do we miss out on
Canonicalanywhere now that it is no longer inNewSemVer? - Is there anywhere else that needs
StandardSemVer()?