diff --git a/AzureSearchEmulator.Aspire.Tests/AzureSearchEmulatorResourceTests.cs b/AzureSearchEmulator.Aspire.Tests/AzureSearchEmulatorResourceTests.cs index 09a936e..88b03a7 100644 --- a/AzureSearchEmulator.Aspire.Tests/AzureSearchEmulatorResourceTests.cs +++ b/AzureSearchEmulator.Aspire.Tests/AzureSearchEmulatorResourceTests.cs @@ -1,5 +1,4 @@ -using System.Xml.Linq; -using F23.Aspire.Hosting.AzureSearchEmulator; +using F23.Aspire.Hosting.AzureSearchEmulator; namespace AzureSearchEmulator.Aspire.Tests; @@ -28,17 +27,10 @@ public void ImageTag_MatchesPackageVersion() // a second place to edit at release time; this asserts that derivation stays correct. // Arrange - // Read the version the package actually ships from the csproj, rather than from the + // Read the version the package actually ships from the VERSION file, rather than from the // assembly the tag is already derived from -- comparing the derivation against its own // input would pass no matter what the release version is. - var csproj = Path.Combine(GetRepositoryRoot(), - "AzureSearchEmulator.Aspire", "AzureSearchEmulator.Aspire.csproj"); - - var packageVersion = XDocument.Load(csproj) - .Descendants("Version") - .Single() - .Value - .Trim(); + var packageVersion = File.ReadAllText(Path.Combine(GetRepositoryRoot(), "VERSION")).Trim(); // Act var tag = AzureSearchEmulatorResource.ImageTag; diff --git a/AzureSearchEmulator.Aspire/AzureSearchEmulator.Aspire.csproj b/AzureSearchEmulator.Aspire/AzureSearchEmulator.Aspire.csproj index f3fc36e..d4b9982 100644 --- a/AzureSearchEmulator.Aspire/AzureSearchEmulator.Aspire.csproj +++ b/AzureSearchEmulator.Aspire/AzureSearchEmulator.Aspire.csproj @@ -13,7 +13,6 @@ azure search emulator ai hosting docker Azure Search Emulator hosting support for Aspire. true - 1.0.0-beta.4 feature[23] Copyright (c) feature[23] 2025 Paul Irwin diff --git a/AzureSearchEmulator.UnitTests/EmulatorVersionTests.cs b/AzureSearchEmulator.UnitTests/EmulatorVersionTests.cs new file mode 100644 index 0000000..6d0a982 --- /dev/null +++ b/AzureSearchEmulator.UnitTests/EmulatorVersionTests.cs @@ -0,0 +1,33 @@ +using Xunit; + +namespace AzureSearchEmulator.UnitTests; + +/// +/// Tests for the version the emulator reports on startup and on the dashboard (issue #89). +/// +public class EmulatorVersionTests +{ + [Fact] + public void Current_MatchesVersionFile() + { + // Read from the VERSION file rather than the assembly, so this fails if the build stops + // stamping the assembly from it. + var expected = File.ReadAllText(Path.Combine(GetRepositoryRoot(), "VERSION")).Trim(); + + Assert.Equal(expected, EmulatorVersion.Current); + } + + private static string GetRepositoryRoot() + { + var directory = new DirectoryInfo(AppContext.BaseDirectory); + + while (directory is not null && !File.Exists(Path.Combine(directory.FullName, "AzureSearchEmulator.sln"))) + { + directory = directory.Parent; + } + + Assert.NotNull(directory); + + return directory.FullName; + } +} diff --git a/AzureSearchEmulator/AzureSearchEmulator.csproj b/AzureSearchEmulator/AzureSearchEmulator.csproj index 1c11d6a..993f12d 100644 --- a/AzureSearchEmulator/AzureSearchEmulator.csproj +++ b/AzureSearchEmulator/AzureSearchEmulator.csproj @@ -5,7 +5,6 @@ 6751dc28-24d4-4572-8f44-e652593dd678 enable enable - 1.0.0-beta.4 Nullable 14 true diff --git a/AzureSearchEmulator/EmulatorVersion.cs b/AzureSearchEmulator/EmulatorVersion.cs new file mode 100644 index 0000000..8022348 --- /dev/null +++ b/AzureSearchEmulator/EmulatorVersion.cs @@ -0,0 +1,29 @@ +using System.Reflection; + +namespace AzureSearchEmulator; + +/// +/// The release version of the running emulator, as set in the repository's VERSION file. +/// +public static class EmulatorVersion +{ + public static string Current { get; } = GetVersion(); + + private static string GetVersion() + { + var assembly = typeof(EmulatorVersion).Assembly; + + var informational = assembly.GetCustomAttribute() + ?.InformationalVersion; + + if (!string.IsNullOrEmpty(informational)) + { + // The informational version carries a "+" suffix when the build has source + // link enabled; callers want the version, not the provenance. + var plus = informational.IndexOf('+'); + return plus < 0 ? informational : informational[..plus]; + } + + return assembly.GetName().Version?.ToString() ?? "unknown"; + } +} diff --git a/AzureSearchEmulator/Health/EmulatorStatus.cs b/AzureSearchEmulator/Health/EmulatorStatus.cs index 19d2c61..bffbaa1 100644 --- a/AzureSearchEmulator/Health/EmulatorStatus.cs +++ b/AzureSearchEmulator/Health/EmulatorStatus.cs @@ -1,4 +1,3 @@ -using System.Reflection; using Microsoft.Extensions.Diagnostics.HealthChecks; namespace AzureSearchEmulator.Health; @@ -40,8 +39,6 @@ public class EmulatorStatusService( Microsoft.Extensions.Options.IOptions options, TimeProvider timeProvider) { - private static readonly string AssemblyVersion = GetAssemblyVersion(); - private static readonly long StartedAtTimestamp = System.Diagnostics.Stopwatch.GetTimestamp(); public async Task GetStatusAsync(CancellationToken cancellationToken = default) @@ -64,28 +61,10 @@ public async Task GetStatusAsync(CancellationToken cancellationT report.Status, report.TotalDuration, entries, - AssemblyVersion, + EmulatorVersion.Current, hostEnvironment.EnvironmentName, options.Value.IndexesDirectory, System.Diagnostics.Stopwatch.GetElapsedTime(StartedAtTimestamp), timeProvider.GetUtcNow()); } - - private static string GetAssemblyVersion() - { - var assembly = typeof(EmulatorStatusService).Assembly; - - var informational = assembly.GetCustomAttribute() - ?.InformationalVersion; - - if (!string.IsNullOrEmpty(informational)) - { - // The informational version carries a "+" suffix when the build has source - // link enabled; the dashboard wants the version, not the provenance. - var plus = informational.IndexOf('+'); - return plus < 0 ? informational : informational[..plus]; - } - - return assembly.GetName().Version?.ToString() ?? "unknown"; - } } diff --git a/AzureSearchEmulator/Program.cs b/AzureSearchEmulator/Program.cs index 0ae72d2..beb6b05 100644 --- a/AzureSearchEmulator/Program.cs +++ b/AzureSearchEmulator/Program.cs @@ -176,6 +176,10 @@ var app = builder.Build(); +// Logged first so the version is on screen before anything else, including a failure to start +// (issue #89). +app.Logger.LogInformation("Azure Search Emulator {Version}", EmulatorVersion.Current); + // Outermost, so it also covers the model binding and OData formatter work that runs before a // controller action is reached (issue #40). // diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..7ad8c0e --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,10 @@ + + + + + $([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)VERSION').Trim()) + + + diff --git a/Dockerfile b/Dockerfile index 11d60a4..158ed5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ EXPOSE 443 FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build WORKDIR /src +COPY ["VERSION", "Directory.Build.props", "./"] COPY ["AzureSearchEmulator/AzureSearchEmulator.csproj", "AzureSearchEmulator/"] RUN dotnet restore "AzureSearchEmulator/AzureSearchEmulator.csproj" COPY . . diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..9c21819 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.0.0-rc.1