From f87f666f5621f40f8f73ed68eed6070e070bc5c1 Mon Sep 17 00:00:00 2001 From: xping-admin Date: Mon, 10 Aug 2026 13:53:18 +0200 Subject: [PATCH] feat: integrate XpingVersion for consistent SDK versioning across components --- src/Xping.Cli/Program.cs | 21 ++++++------------- src/Xping.Cli/Xping.Cli.csproj | 1 + .../XpingServiceCollectionExtensions.cs | 2 +- src/Xping.Sdk.Core/Models/TestSession.cs | 5 ++--- .../XpingContextOrchestrator.cs | 2 +- .../XpingVersion.cs} | 6 +++--- .../Models/TestSessionTests.cs | 6 +++--- .../Upload/XpingUploaderTests.cs | 4 ++-- .../Xping.Sdk.Core.Tests.csproj | 1 + 9 files changed, 20 insertions(+), 28 deletions(-) rename src/{Xping.Sdk.Core/XpingSdkVersion.cs => Xping.Sdk.Shared/XpingVersion.cs} (93%) diff --git a/src/Xping.Cli/Program.cs b/src/Xping.Cli/Program.cs index 7b7f23c..890481e 100644 --- a/src/Xping.Cli/Program.cs +++ b/src/Xping.Cli/Program.cs @@ -6,8 +6,8 @@ using System.CommandLine; using System.CommandLine.Parsing; using System.Globalization; -using System.Reflection; using Xping.Cli.Commands; +using Xping.Sdk.Shared; namespace Xping.Cli; @@ -32,7 +32,7 @@ internal static int Run( bool noArgs = args.Length == 0; - // Matches the historical bare-word `help` verb; `--help`/`-h` are already recognised by + // Matches the historical bare-word `help` verb; `--help`/`-h` are already recognized by // the root command itself. string[] effectiveArgs = noArgs ? ["--help"] @@ -211,24 +211,15 @@ private static Command BuildVersionCommand(TextWriter output) { Command command = new("version", "Print the tool version"); - // Reads the same AssemblyInformationalVersionAttribute that System.CommandLine's built-in - // `--version` root option uses, so `xping version` and `xping --version` always agree. + // Uses the shared XpingSdkVersion (the same clean SemVer reported in the SDK's User-Agent + // header and TestSession.SdkVersion), so it may omit the local source-revision suffix + // (e.g. "+abc123") that System.CommandLine's built-in `--version` option can include. command.SetAction(_ => { - output.WriteLine(GetInformationalVersion()); + output.WriteLine(XpingVersion.Current); return 0; }); return command; } - - private static string GetInformationalVersion() - { - AssemblyInformationalVersionAttribute? attribute = typeof(Program).Assembly - .GetCustomAttribute(); - - return attribute?.InformationalVersion is { Length: > 0 } version - ? version - : typeof(Program).Assembly.GetName().Version?.ToString() ?? "unknown"; - } } diff --git a/src/Xping.Cli/Xping.Cli.csproj b/src/Xping.Cli/Xping.Cli.csproj index c7ff2c2..ede142d 100644 --- a/src/Xping.Cli/Xping.Cli.csproj +++ b/src/Xping.Cli/Xping.Cli.csproj @@ -28,6 +28,7 @@ + diff --git a/src/Xping.Sdk.Core/Extensions/XpingServiceCollectionExtensions.cs b/src/Xping.Sdk.Core/Extensions/XpingServiceCollectionExtensions.cs index a592536..932d7fa 100644 --- a/src/Xping.Sdk.Core/Extensions/XpingServiceCollectionExtensions.cs +++ b/src/Xping.Sdk.Core/Extensions/XpingServiceCollectionExtensions.cs @@ -491,7 +491,7 @@ public static IServiceCollection AddXpingUploader(this IServiceCollection servic new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Add("X-API-Key", config.ApiKey); client.DefaultRequestHeaders.Add("X-Project-Id", config.ProjectId); - client.DefaultRequestHeaders.Add("User-Agent", $"Xping-SDK-DotNet/{XpingSdkVersion.Current}"); + client.DefaultRequestHeaders.Add("User-Agent", $"Xping-SDK-DotNet/{XpingVersion.Current}"); }) .AddResilienceHandler("xping-upload-resilience", (builder, context) => { diff --git a/src/Xping.Sdk.Core/Models/TestSession.cs b/src/Xping.Sdk.Core/Models/TestSession.cs index 8ee8606..67ee1ea 100644 --- a/src/Xping.Sdk.Core/Models/TestSession.cs +++ b/src/Xping.Sdk.Core/Models/TestSession.cs @@ -3,7 +3,6 @@ * License: [MIT] */ -using Xping.Sdk.Core; using Xping.Sdk.Core.Models.Environments; using Xping.Sdk.Core.Models.Executions; using Xping.Sdk.Core.Models.PullRequests; @@ -31,7 +30,7 @@ public TestSession() SessionState = TestSessionState.Initial; PullRequestContext = null; QuickStatistics = null; - SdkVersion = XpingSdkVersion.Current; + SdkVersion = XpingVersion.Current; } /// @@ -57,7 +56,7 @@ internal TestSession( SessionState = sessionState; PullRequestContext = pullRequestContext; QuickStatistics = quickStatistics; - SdkVersion = XpingSdkVersion.Current; + SdkVersion = XpingVersion.Current; } /// diff --git a/src/Xping.Sdk.Core/XpingContextOrchestrator.cs b/src/Xping.Sdk.Core/XpingContextOrchestrator.cs index 5e5dc05..7aa2da7 100644 --- a/src/Xping.Sdk.Core/XpingContextOrchestrator.cs +++ b/src/Xping.Sdk.Core/XpingContextOrchestrator.cs @@ -65,7 +65,7 @@ public abstract class XpingContextOrchestrator : IAsyncDisposable private readonly ILocalRunWriter? _localRunWriter; // Slim projections of every execution drained during this session. Accumulated at drain time - // rather than in RecordTestExecution so the per-test hot path stays free of any local-store work. + // rather than in RecordTestExecution, so the per-test hot path stays free of any local-store work. private readonly List _localRecords = []; private readonly object _localRecordsLock = new(); diff --git a/src/Xping.Sdk.Core/XpingSdkVersion.cs b/src/Xping.Sdk.Shared/XpingVersion.cs similarity index 93% rename from src/Xping.Sdk.Core/XpingSdkVersion.cs rename to src/Xping.Sdk.Shared/XpingVersion.cs index abce363..c4fe45e 100644 --- a/src/Xping.Sdk.Core/XpingSdkVersion.cs +++ b/src/Xping.Sdk.Shared/XpingVersion.cs @@ -5,7 +5,7 @@ using System.Reflection; -namespace Xping.Sdk.Core; +namespace Xping.Sdk.Shared; /// /// Provides the current version of the Xping SDK, read from assembly metadata at runtime. @@ -24,7 +24,7 @@ namespace Xping.Sdk.Core; /// string version = XpingSdkVersion.Current; // e.g. "1.2.3" or "1.3.0-beta.1" /// /// -public static class XpingSdkVersion +public static class XpingVersion { /// /// The current version of the Xping SDK (e.g. "1.2.3" or "1.3.0-beta.1"). @@ -33,7 +33,7 @@ public static class XpingSdkVersion private static string ReadVersion() { - var attribute = typeof(XpingSdkVersion).Assembly + var attribute = typeof(XpingVersion).Assembly .GetCustomAttribute(); if (attribute == null) diff --git a/tests/Xping.Sdk.Core.Tests/Models/TestSessionTests.cs b/tests/Xping.Sdk.Core.Tests/Models/TestSessionTests.cs index bc75daf..a90480b 100644 --- a/tests/Xping.Sdk.Core.Tests/Models/TestSessionTests.cs +++ b/tests/Xping.Sdk.Core.Tests/Models/TestSessionTests.cs @@ -3,10 +3,10 @@ * License: [MIT] */ -using Xping.Sdk.Core; using Xping.Sdk.Core.Models; using Xping.Sdk.Core.Models.Builders; using Xping.Sdk.Core.Models.Executions; +using Xping.Sdk.Shared; namespace Xping.Sdk.Core.Tests.Models; @@ -21,7 +21,7 @@ public void Constructor_DefaultParameterless_SdkVersionMatchesXpingSdkVersionCur { var session = new TestSession(); - Assert.Equal(XpingSdkVersion.Current, session.SdkVersion); + Assert.Equal(XpingVersion.Current, session.SdkVersion); } // --------------------------------------------------------------------------- @@ -39,6 +39,6 @@ public void Build_WithExecution_SdkVersionMatchesXpingSdkVersionCurrent() .Build()) .Build(); - Assert.Equal(XpingSdkVersion.Current, session.SdkVersion); + Assert.Equal(XpingVersion.Current, session.SdkVersion); } } diff --git a/tests/Xping.Sdk.Core.Tests/Upload/XpingUploaderTests.cs b/tests/Xping.Sdk.Core.Tests/Upload/XpingUploaderTests.cs index b7b3c62..40cff62 100644 --- a/tests/Xping.Sdk.Core.Tests/Upload/XpingUploaderTests.cs +++ b/tests/Xping.Sdk.Core.Tests/Upload/XpingUploaderTests.cs @@ -9,13 +9,13 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Http; using Polly.CircuitBreaker; -using Xping.Sdk.Core; using Xping.Sdk.Core.Configuration; using Xping.Sdk.Core.Extensions; using Xping.Sdk.Core.Models; using Xping.Sdk.Core.Models.Builders; using Xping.Sdk.Core.Models.Executions; using Xping.Sdk.Core.Services.Upload; +using Xping.Sdk.Shared; namespace Xping.Sdk.Core.Tests.Upload; @@ -416,6 +416,6 @@ public async Task UploadAsync_ShouldInclude_UserAgentHeader_WithSdkVersion() // Assert Assert.NotNull(captured); Assert.True(captured.Headers.TryGetValues("User-Agent", out var values)); - Assert.Equal($"Xping-SDK-DotNet/{XpingSdkVersion.Current}", string.Join(" ", values)); + Assert.Equal($"Xping-SDK-DotNet/{XpingVersion.Current}", string.Join(" ", values)); } } diff --git a/tests/Xping.Sdk.Core.Tests/Xping.Sdk.Core.Tests.csproj b/tests/Xping.Sdk.Core.Tests/Xping.Sdk.Core.Tests.csproj index ab8811c..2c75e8f 100644 --- a/tests/Xping.Sdk.Core.Tests/Xping.Sdk.Core.Tests.csproj +++ b/tests/Xping.Sdk.Core.Tests/Xping.Sdk.Core.Tests.csproj @@ -28,6 +28,7 @@ +