Skip to content

Commit fc2b397

Browse files
mitchdennyMitch DennyCopilot
authored
Make VerifyAspireCliVersionAsync resilient across branches (#15561)
Read VersionPrefix dynamically from eng/Versions.props instead of hardcoding a specific version. For non-stabilized builds (all normal PR builds), also verify the commit SHA suffix for exact build identity. This replaces the hardcoded '13.2.0' check that was added for the stabilized 13.2.0 release build. Co-authored-by: Mitch Denny <mitch@mitchdeny.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4961db2 commit fc2b397

File tree

2 files changed

+66
-8
lines changed

2 files changed

+66
-8
lines changed

tests/Aspire.Cli.EndToEnd.Tests/Helpers/CliE2EAutomatorHelpers.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,33 @@ internal static async Task SourceAspireCliEnvironmentAsync(
147147
}
148148

149149
/// <summary>
150-
/// Verifies the installed Aspire CLI version matches the expected version.
150+
/// Verifies the installed Aspire CLI version matches the expected build.
151+
/// Always checks the dynamic version prefix from eng/Versions.props.
152+
/// For non-stabilized builds (all normal PR builds), also verifies the commit SHA suffix.
151153
/// </summary>
152-
#pragma warning disable IDE0060 // commitSha is unused during stabilized builds — restore when merging back to main
153154
internal static async Task VerifyAspireCliVersionAsync(
154155
this Hex1bTerminalAutomator auto,
155156
string commitSha,
156157
SequenceCounter counter)
157-
#pragma warning restore IDE0060
158158
{
159+
var versionPrefix = CliE2ETestHelpers.GetVersionPrefix();
160+
var isStabilized = CliE2ETestHelpers.IsStabilizedBuild();
161+
159162
await auto.TypeAsync("aspire --version");
160163
await auto.EnterAsync();
161164

162-
// When the build is stabilized (StabilizePackageVersion=true), the CLI version
163-
// is just "13.2.0" with no commit SHA suffix. When not stabilized, it includes
164-
// the SHA (e.g., "13.2.0-preview.1.g<sha>"). In both cases, "13.2.0" is present.
165-
// TODO: This change should be reverted on the integration to the main branch.
166-
await auto.WaitUntilTextAsync("13.2.0", timeout: TimeSpan.FromSeconds(10));
165+
// Always verify the version prefix matches the branch's version (e.g., "13.3.0").
166+
await auto.WaitUntilTextAsync(versionPrefix, timeout: TimeSpan.FromSeconds(10));
167+
168+
// For non-stabilized builds (all PR CI builds), also verify the commit SHA suffix
169+
// to uniquely identify the exact build. Stabilized builds (official releases only)
170+
// produce versions without SHA suffixes, so we skip this check.
171+
if (!isStabilized && commitSha.Length == 40)
172+
{
173+
var shortCommitSha = commitSha[..8];
174+
var expectedVersionSuffix = $"g{shortCommitSha}";
175+
await auto.WaitUntilTextAsync(expectedVersionSuffix, timeout: TimeSpan.FromSeconds(10));
176+
}
167177

168178
await auto.WaitForSuccessPromptAsync(counter);
169179
}

tests/Aspire.Cli.EndToEnd.Tests/Helpers/CliE2ETestHelpers.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Runtime.CompilerServices;
5+
using System.Xml.Linq;
56
using Aspire.Cli.Tests.Utils;
67
using Hex1b;
78
using Xunit;
@@ -309,4 +310,51 @@ internal static string ToContainerPath(string hostPath, TemporaryWorkspace works
309310
var relativePath = Path.GetRelativePath(workspace.WorkspaceRoot.FullName, hostPath);
310311
return $"/workspace/{workspace.WorkspaceRoot.Name}/" + relativePath.Replace('\\', '/');
311312
}
313+
314+
/// <summary>
315+
/// Reads the VersionPrefix (e.g., "13.3.0") from eng/Versions.props by parsing
316+
/// the MajorVersion, MinorVersion, and PatchVersion MSBuild properties.
317+
/// </summary>
318+
internal static string GetVersionPrefix()
319+
{
320+
var repoRoot = GetRepoRoot();
321+
var versionsPropsPath = Path.Combine(repoRoot, "eng", "Versions.props");
322+
323+
var doc = XDocument.Load(versionsPropsPath);
324+
var ns = doc.Root?.Name.Namespace ?? XNamespace.None;
325+
326+
string? GetProperty(string name) =>
327+
doc.Descendants(ns + name).FirstOrDefault()?.Value;
328+
329+
var major = GetProperty("MajorVersion")
330+
?? throw new InvalidOperationException("MajorVersion not found in eng/Versions.props");
331+
var minor = GetProperty("MinorVersion")
332+
?? throw new InvalidOperationException("MinorVersion not found in eng/Versions.props");
333+
var patch = GetProperty("PatchVersion")
334+
?? throw new InvalidOperationException("PatchVersion not found in eng/Versions.props");
335+
336+
return $"{major}.{minor}.{patch}";
337+
}
338+
339+
/// <summary>
340+
/// Checks whether the build is stabilized (StabilizePackageVersion=true in eng/Versions.props).
341+
/// Stabilized builds produce version strings without commit SHA suffixes (e.g., "13.2.0" instead
342+
/// of "13.2.0-preview.1.25175.1+g{sha}"). This is only true for official release builds,
343+
/// never for normal PR CI builds.
344+
/// </summary>
345+
internal static bool IsStabilizedBuild()
346+
{
347+
var repoRoot = GetRepoRoot();
348+
var versionsPropsPath = Path.Combine(repoRoot, "eng", "Versions.props");
349+
350+
var doc = XDocument.Load(versionsPropsPath);
351+
var ns = doc.Root?.Name.Namespace ?? XNamespace.None;
352+
353+
// The default value in Versions.props uses a Condition to default to "false",
354+
// so we read the element's text directly.
355+
var stabilize = doc.Descendants(ns + "StabilizePackageVersion")
356+
.FirstOrDefault()?.Value;
357+
358+
return string.Equals(stabilize, "true", StringComparison.OrdinalIgnoreCase);
359+
}
312360
}

0 commit comments

Comments
 (0)