Handle numeric fields in GitVersion 6.x JSON output (#218)#222
Conversation
ChrisonSimtian
left a comment
There was a problem hiding this comment.
Took the branch for a spin against current `main` (now includes #224/#225/#226 since you merged it up) — fix works end-to-end. `tests/Fallout.Common.Tests` runs 35/35 passing (7 env-conditional skips) including your three new `GitVersionParseTest` cases.
Approach is good — much nicer than my first instinct, which was to change the field types to `int`. Keeping them `string` via a custom converter means zero downstream API churn for anyone reading `gitVersion.BuildMetaData` etc. Bidirectional compat (accepts both `"7"` and `7`) keeps older GitVersion installs working.
A couple of small things, both optional / non-blocking:
-
InvariantCultureon theDouble.ToString()fallback. InNumberToStringJsonConverter.Read:JsonTokenType.Number => reader.TryGetInt64(out var l) ? l.ToString() : reader.GetDouble().ToString(),
Double.ToString()is culture-sensitive — onde-DE/fr-FRetc. it produces"1,5"instead of"1.5". Realistically GitVersion never emits non-integers here (`BuildMetaData` and friends are integer counts), so this is purely defensive — but worth tightening:JsonTokenType.Number => reader.TryGetInt64(out var l) ? l.ToString(CultureInfo.InvariantCulture) : reader.GetDouble().ToString(CultureInfo.InvariantCulture),
(
Int64.ToString()is invariant in practice — no decimal — but it's nice to be explicit on both branches.) -
CHANGELOG entry under
[Unreleased] — 11.0would be a nice touch — matches the pattern we set on a previous bug fix in #226. Something like:Fixed
Build.GitVersioninjection on GitVersion 6.x (closes #218). GitVersion 6.x emitsBuildMetaData,CommitsSinceVersionSource,PreReleaseNumber, andWeightedPreReleaseNumberas JSON numbers instead of quoted strings. NewNumberToStringJsonConverterinFallout.Utilities.Text.Jsonhandles both shapes so consumers continue to seestringfor all four. Backwards-compatible with GitVersion 5.x output.
Tagged the PR with `target/v11` per our newly-documented PR-creation flow (CLAUDE.md > Semver policy) — Dennis you wouldn't have known about it, no action needed on your end.
Happy to merge as-is or after the polish lands. Your call.
Regression introduced by #175. The generated workflow emitted: - uses: actions/checkout@v6 with: ref: ${{ github.head_ref }} …but didn't set `repository:`. Checkout defaulted to `${{ github.repository }}` (this repo) and tried to resolve `fix/whatever` as a local branch — which fails for fork PRs because the source branch only exists on the contributor's fork. Symptom: cross-repo PRs (e.g. Dennis Doomen's #222 from his fork) fail at the `Run actions/checkout@v6` step with: fatal: A branch or tag with the name 'fix/...' could not be found #175's `CheckoutRef = "${{ github.head_ref }}"` was added so GitVersion / GitRepository.FromLocalDirectory see the source branch in `.git/HEAD` (otherwise checkout puts you on the merge ref in detached-HEAD state). Goal correct; cross-repo coverage missed. Fix: - GitHubActionsCheckoutStep.Write now emits a `repository:` line whenever `Ref` is non-empty: repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} The `||` fallback covers push events (no pull_request context). - Doc comments on CheckoutRef + Ref updated. - New regression test case `checkout-ref` in ConfigurationGenerationTest locks the YAML shape. Verified snapshot committed alongside. - .github/workflows/ubuntu-latest.yml regenerated by the build. macos-latest / windows-latest / release.yml unchanged (none set CheckoutRef). - CHANGELOG.md entry under [Unreleased] — 11.0. After this lands, Dennis's PR #222 will pick up the fix on the next workflow run (any rerun, or a push to his branch). Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
eedd359 to
9802daf
Compare
…/tests (#232) * chore(repo): add CODEOWNERS pointing to @ChrisonSimtian Prep for tightening main branch protection now that external contributors are opening PRs (dennisdoomen, #222 / #230). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore(repo): scope CODEOWNERS to /src and /tests only Docs, build orchestrator, CI workflows, and root config remain unowned. The follow-up branch-protection update will pair this with required_approving_review_count=0 + require_code_owner_reviews=true, so docs PRs need only CI green while src/tests PRs require explicit owner approval. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ChrisonSimtian Why did you merge |
50909a3 to
32b1b3a
Compare
ah sorry must've been in the wrong tab, that wasn't on purpose 😅 |
55f92b9 to
04dafa8
Compare
04dafa8 to
65e4f49
Compare
GitVersion 6.x changed BuildMetaData, CommitsSinceVersionSource, PreReleaseNumber and WeightedPreReleaseNumber from quoted strings to bare JSON integers. System.Text.Json cannot coerce a Number token to a C# string without an explicit converter. - Add NumberToStringJsonConverter in Fallout.Utilities.Text.Json that accepts both JSON string and JSON number tokens, returning a string. - Annotate the four affected positional parameters in the GitVersion record with [property: JsonConverter(typeof(NumberToStringJsonConverter))]. - Add GitVersionParseTest with three regression tests using the exact payload from the issue report. Non-breaking: consumer code still sees string for all four fields; GitVersion 5.x (which emits quoted strings) continues to work. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
65e4f49 to
9234df3
Compare
|
Hello Guys, I do have actually the same error using GitVersion version 5 (5.12.0), did this fix made it in a stable release ? Thanks |
|
not yet but we'll release another stable soon. in the meantime you can use the gh packages as a preview |
|
ok great thx |

Summary
Fixes #218
GitVersion 6.x changed
BuildMetaData,CommitsSinceVersionSource,PreReleaseNumber, andWeightedPreReleaseNumberfrom quoted JSON strings to bare JSON integers.System.Text.Jsonthrows:Root Cause
The
GitVersionrecord declares those four fields asstring, but the deserializer has no way to coerce aNumbertoken to a C#stringwithout an explicit converter.Changes
src/Fallout.Utilities.Text.Json/NumberToStringJsonConverter.cs(new)A
JsonConverter<string>that accepts both JSON string tokens and JSON number tokens, converting both tostring. Compatible with old (string-output) and new (number-output) GitVersion.src/Fallout.Common/Tools/GitVersion/GitVersionTasks.csAdded
[property: JsonConverter(typeof(NumberToStringJsonConverter))]to the four affected positional record parameters:PreReleaseNumber,WeightedPreReleaseNumber,BuildMetaData,CommitsSinceVersionSource.tests/Fallout.Common.Tests/GitVersionParseTest.cs(new)Three regression tests using the exact JSON payload from the issue:
Non-Breaking
Consumer code continues to see
stringfor all four fields. GitVersion 5.x (which emits quoted strings) continues to work unchanged.