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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Xml.Linq;
using F23.Aspire.Hosting.AzureSearchEmulator;
using F23.Aspire.Hosting.AzureSearchEmulator;

namespace AzureSearchEmulator.Aspire.Tests;

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<PackageTags>azure search emulator ai hosting docker</PackageTags>
<Description>Azure Search Emulator hosting support for Aspire.</Description>
<IsPackable>true</IsPackable>
<Version>1.0.0-beta.4</Version>
<Company>feature[23]</Company>
<Copyright>Copyright (c) feature[23] 2025</Copyright>
<Authors>Paul Irwin</Authors>
Expand Down
33 changes: 33 additions & 0 deletions AzureSearchEmulator.UnitTests/EmulatorVersionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Xunit;

namespace AzureSearchEmulator.UnitTests;

/// <summary>
/// Tests for the version the emulator reports on startup and on the dashboard (issue #89).
/// </summary>
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;
}
}
1 change: 0 additions & 1 deletion AzureSearchEmulator/AzureSearchEmulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<UserSecretsId>6751dc28-24d4-4572-8f44-e652593dd678</UserSecretsId>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.0.0-beta.4</Version>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<LangVersion>14</LangVersion>
<IsPackable>true</IsPackable>
Expand Down
29 changes: 29 additions & 0 deletions AzureSearchEmulator/EmulatorVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Reflection;

namespace AzureSearchEmulator;

/// <summary>
/// The release version of the running emulator, as set in the repository's VERSION file.
/// </summary>
public static class EmulatorVersion
{
public static string Current { get; } = GetVersion();

private static string GetVersion()
{
var assembly = typeof(EmulatorVersion).Assembly;

var informational = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
?.InformationalVersion;

if (!string.IsNullOrEmpty(informational))
{
// The informational version carries a "+<commit sha>" 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";
}
}
23 changes: 1 addition & 22 deletions AzureSearchEmulator/Health/EmulatorStatus.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Reflection;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace AzureSearchEmulator.Health;
Expand Down Expand Up @@ -40,8 +39,6 @@ public class EmulatorStatusService(
Microsoft.Extensions.Options.IOptions<EmulatorOptions> options,
TimeProvider timeProvider)
{
private static readonly string AssemblyVersion = GetAssemblyVersion();

private static readonly long StartedAtTimestamp = System.Diagnostics.Stopwatch.GetTimestamp();

public async Task<EmulatorStatus> GetStatusAsync(CancellationToken cancellationToken = default)
Expand All @@ -64,28 +61,10 @@ public async Task<EmulatorStatus> 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<AssemblyInformationalVersionAttribute>()
?.InformationalVersion;

if (!string.IsNullOrEmpty(informational))
{
// The informational version carries a "+<commit sha>" 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";
}
}
4 changes: 4 additions & 0 deletions AzureSearchEmulator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
//
Expand Down
10 changes: 10 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>

<!-- The single release version for every artifact: the emulator tool package, the Aspire
hosting package, and (via the git tag) the container image. The Aspire package pins its
image tag to its own version, so these must never drift apart. -->
<PropertyGroup>
<Version>$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)VERSION').Trim())</Version>
</PropertyGroup>

</Project>
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 . .
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0-rc.1
Loading