Skip to content

refactor(version,git): derive the tag grammar from the canonical spec - #499

Merged
joshua-temple merged 2 commits into
mainfrom
feat/version-git-delegate
Jul 7, 2026
Merged

joshua-temple merged 2 commits into
mainfrom
feat/version-git-delegate

Conversation

@joshua-temple

Copy link
Copy Markdown
Collaborator

Problem

internal/version and internal/git each carried their own hand-written copy of the release-tag regex (semverRegex, baseVersionRegex, rcSuffixRegex, and git's versionTagRegex), policed only by a cross-package drift test. The git release classifier also decided "is this a published release" with a literal !strings.Contains(tag, "-rc."), which misclassifies any non-default prerelease token as a finished release.

Fix

Back both packages with the internal/taggrammar leaf spec introduced in #498, so the parser and the tag predicate can no longer diverge:

  • version derives its parse and String() output from a taggrammar.Spec. Adds NewCalculatorWithGrammar, ParseWithGrammar, ParseBaseWithGrammar; the existing NewCalculator/Parse/ParseBase stay as default-spec wrappers so no call site changes. Default output is byte-identical.
  • git delegates IsValidVersionTag to the spec (deletes the hand-copied regex) and adds IsValidVersionTagSpec. The release classifier now asks the spec "parses as a version with no prerelease segment" instead of matching a literal -rc., via a new GetLatestReleaseTagSpec. git imports only taggrammar (no version cycle).
  • The cross-package drift test is replaced by a same-source assertion, since both sides now share one grammar.

No behavior change under the default grammar; this is the plumbing the configurable block wires into next.

Verification

  • go build ./... clean
  • go test ./... -race green (2471 tests)
  • golangci-lint run ./internal/version/ ./internal/git/ clean
  • git does not import version (confirmed via go list -deps)

Relates to #434.

Signed-off-by: Joshua Temple <joshua.temple@stablekernel.com>
…r from taggrammar

Signed-off-by: Joshua Temple <joshua.temple@stablekernel.com>
@joshua-temple
joshua-temple merged commit c952a66 into main Jul 7, 2026
20 checks passed
@joshua-temple
joshua-temple deleted the feat/version-git-delegate branch July 7, 2026 02:22
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.

1 participant