diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b4b5d8b..b303971 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,7 +23,7 @@ jobs: - run: dotnet restore - - run: dotnet pack --no-restore --include-symbols -o . /p:PackageVersion=${VERSION} + - run: dotnet pack --no-restore --include-symbols -o . /p:Version=${VERSION} - name: Deploy to NuGet run: dotnet nuget push *.nupkg --api-key $NUGET_AUTH_TOKEN --source https://api.nuget.org/v3/index.json diff --git a/src/Anexia.E5E.Tests/Integration/StartupTests.cs b/src/Anexia.E5E.Tests/Integration/StartupTests.cs index c52cc30..4e6bb53 100644 --- a/src/Anexia.E5E.Tests/Integration/StartupTests.cs +++ b/src/Anexia.E5E.Tests/Integration/StartupTests.cs @@ -25,7 +25,7 @@ public StartupTests(ITestOutputHelper outputHelper) : base(outputHelper) public async Task OutputMatches() { await Host.StartAsync(); - var expected = JsonSerializer.Serialize(new E5ERuntimeMetadata(), E5EJsonSerializerOptions.Default); + var expected = JsonSerializer.Serialize(E5ERuntimeMetadata.Current, E5EJsonSerializerOptions.Default); var stdout = await Host.GetStdoutAsync(); Assert.Equal(expected, stdout); } diff --git a/src/Anexia.E5E.Tests/Serialization/SerializationTests.cs b/src/Anexia.E5E.Tests/Serialization/SerializationTests.cs index 4653a76..187d4f4 100644 --- a/src/Anexia.E5E.Tests/Serialization/SerializationTests.cs +++ b/src/Anexia.E5E.Tests/Serialization/SerializationTests.cs @@ -100,7 +100,7 @@ public void ResponseSerializationRecognisesCorrectType() Assert.Equal(E5EResponseType.Binary, E5EResponse.From("test"u8.ToArray()).Type); Assert.Equal(E5EResponseType.Binary, E5EResponse.From("test"u8.ToArray().AsEnumerable()).Type); Assert.Equal(E5EResponseType.Binary, E5EResponse.From(new E5EFileData("something"u8.ToArray())).Type); - Assert.Equal(E5EResponseType.StructuredObject, E5EResponse.From(new E5ERuntimeMetadata()).Type); + Assert.Equal(E5EResponseType.StructuredObject, E5EResponse.From(E5ERuntimeMetadata.Current).Type); } [Theory] @@ -125,7 +125,7 @@ public void EnumsAreProperSerialized(object type, string expected) [Fact] public void MetadataIsProperSerialized() { - var json = JsonSerializer.Serialize(new E5ERuntimeMetadata(), _options); + var json = JsonSerializer.Serialize(E5ERuntimeMetadata.Current, _options); var deserialized = JsonSerializer.Deserialize(json); var sut = deserialized.EnumerateObject().ToDictionary(x => x.Name, x => x.Value); @@ -135,7 +135,8 @@ public void MetadataIsProperSerialized() () => Assert.Contains("runtime", sut), () => Assert.Contains("features", sut), () => Assert.Contains("library_version", sut), - () => Assert.Equal(1, sut["features"].GetArrayLength()) + () => Assert.Equal(1, sut["features"].GetArrayLength()), + () => Assert.Equal("1.0.0", sut["library_version"].GetString()) ); } @@ -158,7 +159,7 @@ private class SerializationTestsData : IEnumerable { new E5EContext("generic", DateTimeOffset.FromUnixTimeSeconds(0), true), new E5ERequestParameters(), - new E5ERuntimeMetadata(), + E5ERuntimeMetadata.Current, new E5EFileData("data"u8.ToArray()), }; diff --git a/src/Anexia.E5E/Anexia.E5E.csproj b/src/Anexia.E5E/Anexia.E5E.csproj index a3a0fa7..ea42ca4 100644 --- a/src/Anexia.E5E/Anexia.E5E.csproj +++ b/src/Anexia.E5E/Anexia.E5E.csproj @@ -8,7 +8,6 @@ Anexia.E5E - 1.0.0 A helper library to help you build serverless functions on top of the Anexia Engine. anexia ANEXIA Internetdienstleistungs GmbH diff --git a/src/Anexia.E5E/Hosting/E5EHostWrapper.cs b/src/Anexia.E5E/Hosting/E5EHostWrapper.cs index 37f8154..0feab72 100644 --- a/src/Anexia.E5E/Hosting/E5EHostWrapper.cs +++ b/src/Anexia.E5E/Hosting/E5EHostWrapper.cs @@ -39,10 +39,10 @@ public async Task StartAsync(CancellationToken cancellationToken = default) } #if NET8_0_OR_GREATER - var metadata = JsonSerializer.Serialize(new E5ERuntimeMetadata(), + var metadata = JsonSerializer.Serialize(E5ERuntimeMetadata.Current, E5ESerializationContext.Default.E5ERuntimeMetadata); #else - var metadata = JsonSerializer.Serialize(new E5ERuntimeMetadata(), E5EJsonSerializerOptions.Default); + var metadata = JsonSerializer.Serialize(E5ERuntimeMetadata.Current, E5EJsonSerializerOptions.Default); #endif _console.Open(); diff --git a/src/Anexia.E5E/Runtime/E5ERuntimeMetadata.cs b/src/Anexia.E5E/Runtime/E5ERuntimeMetadata.cs index f02ac1a..05d77ea 100644 --- a/src/Anexia.E5E/Runtime/E5ERuntimeMetadata.cs +++ b/src/Anexia.E5E/Runtime/E5ERuntimeMetadata.cs @@ -8,8 +8,19 @@ namespace Anexia.E5E.Runtime; /// [SuppressMessage("ReSharper", "UnusedMember.Global")] [SuppressMessage("Performance", "CA1822:Mark members as static")] -public record E5ERuntimeMetadata +public sealed record E5ERuntimeMetadata { + private E5ERuntimeMetadata() + { + // We try to fetch the informational version from the generated AssemblyInfo. Because SourceLink appends the + // commit hash, we have to trim it afterwards. + var version = typeof(E5ERuntimeMetadata).Assembly + .GetCustomAttribute() + ?.InformationalVersion ?? "0.0.0+unknown"; + + LibraryVersion = version[..version.IndexOf('+')]; + } + /// /// The current instance of the metadata. /// @@ -18,9 +29,7 @@ public record E5ERuntimeMetadata /// /// The installed version of this NuGet library. /// - public string LibraryVersion => - typeof(E5ERuntimeMetadata).Assembly.GetCustomAttribute()?.Version ?? - "0.0.0-unrecognized"; + public string LibraryVersion { get; } /// /// The runtime this function is running in.