Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIANXSVC-1203: Ensure library_version has correct value #8

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
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Anexia.E5E.Tests/Integration/StartupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions src/Anexia.E5E.Tests/Serialization/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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<JsonElement>(json);
var sut = deserialized.EnumerateObject().ToDictionary(x => x.Name, x => x.Value);

Expand All @@ -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())
);
}

Expand All @@ -158,7 +159,7 @@ private class SerializationTestsData : IEnumerable<object[]>
{
new E5EContext("generic", DateTimeOffset.FromUnixTimeSeconds(0), true),
new E5ERequestParameters(),
new E5ERuntimeMetadata(),
E5ERuntimeMetadata.Current,
new E5EFileData("data"u8.ToArray()),
};

Expand Down
1 change: 0 additions & 1 deletion src/Anexia.E5E/Anexia.E5E.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

<!-- NuGet specific metadata, according to: https://learn.microsoft.com/en-us/dotnet/standard/library-guidance/nuget#important-nuget-package-metadata -->
<PackageId>Anexia.E5E</PackageId>
<PackageVersion>1.0.0</PackageVersion> <!-- This is a placeholder, overridden by Nerdbank.GitVersioning -->
<Description>A helper library to help you build serverless functions on top of the Anexia Engine.</Description>
<Authors>anexia</Authors> <!-- needs to match the NuGet profiles -->
<Company>ANEXIA Internetdienstleistungs GmbH</Company>
Expand Down
4 changes: 2 additions & 2 deletions src/Anexia.E5E/Hosting/E5EHostWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 13 additions & 4 deletions src/Anexia.E5E/Runtime/E5ERuntimeMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,19 @@ namespace Anexia.E5E.Runtime;
/// </summary>
[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<AssemblyInformationalVersionAttribute>()
?.InformationalVersion ?? "0.0.0+unknown";

LibraryVersion = version[..version.IndexOf('+')];
}

/// <summary>
/// The current instance of the metadata.
/// </summary>
Expand All @@ -18,9 +29,7 @@ public record E5ERuntimeMetadata
/// <summary>
/// The installed version of this NuGet library.
/// </summary>
public string LibraryVersion =>
typeof(E5ERuntimeMetadata).Assembly.GetCustomAttribute<AssemblyVersionAttribute>()?.Version ??
"0.0.0-unrecognized";
public string LibraryVersion { get; }

/// <summary>
/// The runtime this function is running in.
Expand Down
Loading