Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- **Bumped Scriban 7.1.0 → 7.2.0** (#84) to clear NU1903.
- **Fixed `[GitHubActions]` `CheckoutRef` breaking cross-repo / fork PRs**. The generator emitted `ref: ${{ github.head_ref }}` but didn't set `repository:`, so the default `${{ github.repository }}` was used. For PRs from a fork, the source branch only exists on the fork; checkout tried to resolve it on origin and failed with "branch or tag could not be found" (regressed in #175). Generator now also emits `repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}` whenever `CheckoutRef` is set — works for fork PRs, same-repo PRs, AND push events (the `||` fallback). Regenerate via any `dotnet fallout <target>` to pick up the fix.
- **Fixed `fallout-migrate` producing unrestorable `_build.csproj`** (closes #217). The Nuke → Fallout namespace rewrite carried the original NUKE `Version="10.1.0"` pins onto `Fallout.*` packages — but `Fallout.*` was never published at `10.1.0`, so NuGet hit NU1603 ("not found, falling back to next-higher") and `WarningsAsErrors` in the migrated project escalated to fatal. Migrate now bumps inline `Version="..."` attributes on Nuke → Fallout PackageReferences to the running migrate tool's own version in the same regex pass, and strips the stale `System.Security.Cryptography.Xml` `<PackageReference>` (NUKE-era projects often pinned an older major that conflicts with `Fallout.Common`'s transitive ≥ 10.0.6 — NU1605 downgrade). CPM-managed references (no inline Version) keep namespace-only rewrite — version stays in Directory.Packages.props.
- **Fixed Build.GitVersion injection on GitVersion 6.x** (closes #218). GitVersion 6.x emits BuildMetaData, CommitsSinceVersionSource, PreReleaseNumber, and WeightedPreReleaseNumber as JSON numbers instead of quoted strings. New NumberToStringJsonConverter in Fallout.Utilities.Text.Json handles both shapes so consumers continue to see string for all four. Backwards-compatible with GitVersion 5.x output.

### Added

Expand Down
5 changes: 5 additions & 0 deletions src/Fallout.Common/Tools/GitVersion/GitVersionTasks.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using Fallout.Common.Tooling;
using Fallout.Common.Utilities;
using Fallout.Common.Utilities.Collections;
Expand Down Expand Up @@ -30,8 +31,11 @@ public record GitVersion(
string PreReleaseTagWithDash,
string PreReleaseLabel,
string PreReleaseLabelWithDash,
[property: JsonConverter(typeof(NumberToStringJsonConverter))]
string PreReleaseNumber,
[property: JsonConverter(typeof(NumberToStringJsonConverter))]
string WeightedPreReleaseNumber,
[property: JsonConverter(typeof(NumberToStringJsonConverter))]
string BuildMetaData,
string BuildMetaDataPadded,
string FullBuildMetaData,
Expand All @@ -52,6 +56,7 @@ public record GitVersion(
string NuGetPreReleaseTagV2,
string NuGetPreReleaseTag,
string VersionSourceSha,
[property: JsonConverter(typeof(NumberToStringJsonConverter))]
string CommitsSinceVersionSource,
string CommitsSinceVersionSourcePadded,
int? UncommittedChanges,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2026 Maintainers of Fallout.
// Originally based on NUKE by Matthias Koch and contributors.
// Distributed under the MIT License.
// https://github.com/ChrisonSimtian/Fallout/blob/main/LICENSE

using System;
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Fallout.Common.Tools.GitVersion;

/// <summary>
/// Deserializes a JSON string <em>or</em> JSON number as a C# <see langword="string"/>.
/// Useful for tool outputs (e.g. GitVersion 6.x) where a field that was previously
/// a quoted string is now emitted as a bare number.
/// </summary>
internal sealed class NumberToStringJsonConverter : JsonConverter<string>
{
public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return reader.TokenType switch
{
JsonTokenType.String => reader.GetString(),
JsonTokenType.Number => reader.TryGetInt64(out var l) ? l.ToString() : reader.GetDouble().ToString(CultureInfo.InvariantCulture),
JsonTokenType.Null => null,
_ => throw new JsonException($"Unexpected token type {reader.TokenType} when deserializing string.")
};
}

public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
{
if (value is null)
{
writer.WriteNullValue();
}
else
{
writer.WriteStringValue(value);
}
}
}
73 changes: 73 additions & 0 deletions tests/Fallout.Common.Tests/GitVersionParseTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2026 Maintainers of Fallout.
// Originally based on NUKE by Matthias Koch and contributors.
// Distributed under the MIT License.
// https://github.com/ChrisonSimtian/Fallout/blob/main/LICENSE

using FluentAssertions;
using Fallout.Common.Tools.GitVersion;
using Fallout.Common.Utilities;
using Xunit;

namespace Fallout.Common.Tests;

/// <summary>
/// Regression tests for GitVersion JSON deserialisation (issue #218).
/// GitVersion 6.x emits several fields as bare JSON numbers instead of quoted strings.
/// </summary>
public class GitVersionParseTest
{
// Exact payload from issue #218 — BuildMetaData, CommitsSinceVersionSource,
// PreReleaseNumber and WeightedPreReleaseNumber are numbers, not strings.
private const string GitVersion6Json = """
{
"AssemblySemFileVer": "8.10.1.0",
"AssemblySemVer": "8.10.1.0",
"BranchName": "switch-to-fallout",
"BuildMetaData": 7,
"CommitDate": "2026-05-26",
"CommitsSinceVersionSource": 7,
"EscapedBranchName": "switch-to-fallout",
"FullBuildMetaData": "7.Branch.switch-to-fallout.Sha.6419fa509c7934f0b34a0ea5e5306c44c0a9a259",
"FullSemVer": "8.10.1-switch-to-fallout.1+7",
"InformationalVersion": "8.10.1-switch-to-fallout.1+7.Branch.switch-to-fallout.Sha.6419fa509c7934f0b34a0ea5e5306c44c0a9a259",
"Major": 8,
"MajorMinorPatch": "8.10.1",
"Minor": 10,
"Patch": 1,
"PreReleaseLabel": "switch-to-fallout",
"PreReleaseLabelWithDash": "-switch-to-fallout",
"PreReleaseNumber": 1,
"PreReleaseTag": "switch-to-fallout.1",
"PreReleaseTagWithDash": "-switch-to-fallout.1",
"SemVer": "8.10.1-switch-to-fallout.1",
"Sha": "6419fa509c7934f0b34a0ea5e5306c44c0a9a259",
"ShortSha": "6419fa5",
"UncommittedChanges": 13,
"VersionSourceDistance": 7,
"VersionSourceIncrement": "None",
"VersionSourceSemVer": "8.10.0",
"VersionSourceSha": "0954811776a71005283221b91aabafc5fec332b7",
"WeightedPreReleaseNumber": 1
}
""";

[Fact]
public void Can_parse_a_v6_response()
{
var result = GitVersion6Json.GetJson<GitVersion>();

result.Should().BeEquivalentTo(new
{
BuildMetaData = "7",
CommitsSinceVersionSource = "7",
PreReleaseNumber = "1",
WeightedPreReleaseNumber = "1",
Major = 8,
Minor = 10,
Patch = 1,
BranchName = "switch-to-fallout",
FullSemVer = "8.10.1-switch-to-fallout.1+7",
UncommittedChanges = 13
});
}
}
Loading