mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-22 09:37:12 +08:00
e9313ef957
## Description Two related changes to how the 2.0 line is built and shipped. ### 1. Release-branch-only package publication - `master` produces development previews only. - Stable packages can only be built from a canonical `release/<major>.<minor>` branch and are promoted manually from the exact signed candidate artifact. - Core packages use explicit `major.minor.patch` versions (`2.0.0`, `2.0.1`, then `2.1.0`); git height never changes a stable package patch. - XRegistry, WoT Connectivity, Vision, Robotics, Redundancy, Positioning, OpenUSD, ISA95, AI, DI, the relevant MCP extensions, and OpenUSD connector tools remain `-preview.N` while following the core numeric version. - nuget.org receives only non-`.Debug` package IDs; GitHub Packages retains the complete signed Release/Debug candidate. - `docs/ReleaseProcess.md` is a reproducible runbook for developers and agents, with each step stating its completion evidence. Promotion is source-bound and byte-checked: `release.yml` checks out nothing until the candidate SHA is known, and `assert-published-packages-match.ps1` proves that any version already on a feed holds *this* candidate's content before `--skip-duplicate` is allowed to skip it. Canonical release-branch naming is matched case-sensitively with no leading zeroes, and `version.json`'s `publicReleaseRefSpec`, both policy helpers and the copy `release.yml` inlines are pinned to one expression by tests. ### 2. PR CI moved to GitHub-hosted runners - `.github/workflows/buildandtest.yml` (**CI**) now owns pull-request validation outright, covering the Windows Debug/Release net48 + net10.0 solution builds and fast tests that only Azure Pipelines ran, alongside the existing Linux/macOS, all-target and NativeAOT legs. `build-and-test summary` remains the stable required check name. - `.github/workflows/nightly.yml` is a new **manual-only** (`workflow_dispatch`) full-scope workflow covering the Azure nightly workload: all solutions x seven target profiles x Debug/Release, the net472/netstandard profiles, Windows + Linux NativeAOT, and the long-running and durable tiers. - Shared deterministic discovery/batching lives in `.github/scripts/get-ci-matrix.ps1` with a local composite action, so both entry points expand the same workload manifest instead of duplicating a large embedded script. - `azure-pipelines.yml` is set to `pr: none`. - The standalone pump sample image workflow is folded into the consolidated **Images CI** workflow, which now builds all ten images and publishes an `images summary` rollup suitable as a required check. ## Related Issues No related issue provided. ## Checklist - [ ] I have signed the [CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf) and read the [CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md) doc. - [x] I have added tests that prove my fix is effective or that my feature works and increased code coverage. - [x] I have added all necessary documentation. - [x] I have verified that my changes do not introduce (new) build or analyzer warnings. - [ ] I ran **all** tests locally using the **UA.slnx** solution against at least .net **framework** and .net **10**, and all passed. - [ ] I fixed **all** failing and flaky tests in the CI pipelines and **all** CodeQL warnings. - [x] I have addressed **all** PR feedback received. ## Validation - `Opc.Ua.Tools.Tests` full `net10.0` suite: **959 passed, 1 skipped, 0 failed**. - Version/package-policy regression subset (`PackageVersionPolicyTests`): **60 passed, 0 failed**. - GitHub Actions **CI** run 35719807620: **149/149 jobs green** on GitHub-hosted runners. - Canonical release-branch rule verified against the pinned nbgv 3.7.115 by building throwaway branches: `release/2.0`, `release/0.9`, `release/10.42` -> `PublicRelease=True`; `release/02.0`, `release/2.00`, `Release/2.0` -> `False`. - Package identity gate verified against a live nuget.org package: served packages carry a repository `.signature.p7s`, so equality is decided on content excluding that part. Re-signing and zip reordering produce an identical digest; a one-byte content change does not. - Synthetic Release-only, Debug-only, combined, preview, duplicate, orphaned-symbol, mismatched-root and accidental-stable-family package sets exercise the shared validator. - Stable-release rehearsal in an isolated `release/2.0` clone: `Opc.Ua.Di` packed as `2.0.0-preview.6` depending on stable Core `2.0.0`; `Opc.Ua.Di.Client` likewise against stable Client `2.0.0`. - All workflow YAML, `version.json`, the package-policy PowerShell scripts and the internal release-runbook anchors parse. ## Known validation limits - Full `UA.slnx` `net48` and `net10.0` local validation remains blocked by pre-existing `NETSDK1005` and dependency-version failures in unmodified fuzz/sample projects; the corresponding checklist items intentionally stay open. - The TRX-driven test verdict added for the intermittent at-exit host stall is proven by `CiTestVerdictTests`; the stall itself has not recurred since. - `nightly.yml` has not yet been run against a full-scope Azure run for tuple-level parity — see below. ## Operational follow-up This remains a preparation PR targeting `master`. It does **not** authorize a release. Release sequence: 1. Merge this PR. 2. Create canonical `release/2.0`, advance `master` to `2.1.0-preview.{height}`, and open a separate `2.0.0` version PR against `release/2.0`. 3. Follow [`docs/ReleaseProcess.md`](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/docs/ReleaseProcess.md) for candidate dry-run, environment approval, promotion, tag/release finalization, and next-patch preview setup. CI migration steps still needing administrator access are tracked in [`docs/DeveloperGuide.md#migration-status`](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/docs/DeveloperGuide.md#migration-status): proving `nightly.yml` parity on a trusted SHA with the private fuzz corpus provisioned, turning off definition 14's service-side PR override, retiring the Azure full-scope schedules and push trigger, and retiring the duplicate `azure-pipelines-preview.yml` publisher. > **Before cutting `release/2.0`:** the `Release` ruleset requires the Azure context for *every* `refs/heads/release/*`, but a new 2.x branch inherits `pr: none`, so that context would never report and would block every PR into the new line. Exclude the new ref from that ruleset, or add a 2.x ruleset requiring `build-and-test summary`, as part of creating the branch. --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
479 lines
21 KiB
C#
479 lines
21 KiB
C#
/* ========================================================================
|
|
* Copyright (c) 2005-2026 The OPC Foundation, Inc. All rights reserved.
|
|
*
|
|
* OPC Foundation MIT License 1.00
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person
|
|
* obtaining a copy of this software and associated documentation
|
|
* files (the "Software"), to deal in the Software without
|
|
* restriction, including without limitation the rights to use,
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following
|
|
* conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be
|
|
* included in all copies or substantial portions of the Software.
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* The complete license agreement can be found here:
|
|
* http://opcfoundation.org/License/MIT/1.00/
|
|
* ======================================================================*/
|
|
|
|
#if NET10_0
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text.Json;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
|
|
namespace Opc.Ua.Tools.Tests
|
|
{
|
|
/// <summary>
|
|
/// Contract tests for .github/scripts/get-ci-matrix.ps1, which decides what
|
|
/// every pull request and every manual full-scope run actually executes. A
|
|
/// silent regression there would not fail any build: it would quietly stop
|
|
/// running part of the suite and still report green, so the properties that
|
|
/// make the matrix trustworthy are asserted here instead.
|
|
/// </summary>
|
|
[TestFixture]
|
|
[NonParallelizable]
|
|
public sealed class CiMatrixScriptTests
|
|
{
|
|
/// <summary>
|
|
/// GitHub refuses to start a run whose matrices expand past 256 jobs.
|
|
/// The script sizes its batches to fit; this proves both scopes do.
|
|
/// </summary>
|
|
[TestCase("pr")]
|
|
[TestCase("full")]
|
|
public async Task ScopeFitsTheGitHubMatrixLimitAsync(string scope)
|
|
{
|
|
MatrixResult matrix = await RunMatrixAsync(scope).ConfigureAwait(false);
|
|
|
|
Assert.That(matrix.Tests, Is.Not.Empty);
|
|
Assert.That(matrix.Builds, Is.Not.Empty);
|
|
Assert.That(
|
|
matrix.Tests.Count + matrix.Builds.Count,
|
|
Is.LessThanOrEqualTo(256),
|
|
"The expanded matrix must fit GitHub's per-run job ceiling.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// The batch size is computed from the whole profile table so that
|
|
/// turning macOS off does not reshuffle which projects run together on
|
|
/// the remaining runners, which would make two runs incomparable.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task ExcludingMacOsKeepsTheRemainingBatchesIdenticalAsync()
|
|
{
|
|
MatrixResult withMac = await RunMatrixAsync("pr").ConfigureAwait(false);
|
|
MatrixResult withoutMac = await RunMatrixAsync("pr", excludeMacOs: true).ConfigureAwait(false);
|
|
|
|
Assert.That(withoutMac.BatchSize, Is.EqualTo(withMac.BatchSize));
|
|
Assert.That(
|
|
withoutMac.Tests.Any(entry => entry.Os == "macos"),
|
|
Is.False,
|
|
"-ExcludeMacOS must drop every macOS entry.");
|
|
|
|
Dictionary<string, string> expected = withMac.Tests
|
|
.Where(entry => entry.Os != "macos")
|
|
.ToDictionary(entry => entry.Id, entry => entry.Projects);
|
|
Dictionary<string, string> actual = withoutMac.Tests
|
|
.ToDictionary(entry => entry.Id, entry => entry.Projects);
|
|
|
|
Assert.That(actual, Is.EqualTo(expected));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Every test project on disk has to be claimed by the matrix. The
|
|
/// exclusions are the four projects other jobs own; anything else that
|
|
/// stopped being scheduled would silently stop being tested.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task EveryTestProjectIsCoveredOrExplicitlyExcludedAsync()
|
|
{
|
|
MatrixResult matrix = await RunMatrixAsync("full").ConfigureAwait(false);
|
|
|
|
HashSet<string> scheduled = matrix.Tests
|
|
.SelectMany(entry => entry.Projects.Split(';', StringSplitOptions.RemoveEmptyEntries))
|
|
.ToHashSet(StringComparer.Ordinal);
|
|
|
|
string root = FindRepositoryRoot();
|
|
string[] excluded =
|
|
[
|
|
"Opc.Ua.Aot.Tests.csproj",
|
|
"Opc.Ua.Stress.Tests.csproj",
|
|
"Opc.Ua.OneFuzz.Validator.Tests.csproj"
|
|
];
|
|
|
|
List<string> missing = [];
|
|
var options = new EnumerationOptions
|
|
{
|
|
RecurseSubdirectories = true,
|
|
IgnoreInaccessible = true
|
|
};
|
|
foreach (string path in Directory.EnumerateFiles(root, "*.Tests.csproj", options))
|
|
{
|
|
string relative = Path.GetRelativePath(root, path).Replace('\\', '/');
|
|
if (relative.Contains("/bin/", StringComparison.Ordinal) ||
|
|
relative.Contains("/obj/", StringComparison.Ordinal))
|
|
{
|
|
continue;
|
|
}
|
|
if (excluded.Contains(Path.GetFileName(path), StringComparer.Ordinal))
|
|
{
|
|
continue;
|
|
}
|
|
if (!scheduled.Contains(relative))
|
|
{
|
|
missing.Add(relative);
|
|
}
|
|
}
|
|
|
|
Assert.That(missing, Is.Empty, "These test projects are on disk but nothing schedules them.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// The fuzz projects live under fuzzing/, not tests/. An earlier
|
|
/// discovery step only swept tests/ and therefore never ran them on
|
|
/// GitHub-hosted runners; this pins the fix.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task FuzzProjectsAreScheduledAsync()
|
|
{
|
|
MatrixResult matrix = await RunMatrixAsync("pr").ConfigureAwait(false);
|
|
|
|
string[] fuzzProjects = matrix.Tests
|
|
.SelectMany(entry => entry.Projects.Split(';', StringSplitOptions.RemoveEmptyEntries))
|
|
.Where(project => project.StartsWith("fuzzing/", StringComparison.Ordinal))
|
|
.Distinct(StringComparer.Ordinal)
|
|
.ToArray();
|
|
|
|
Assert.That(fuzzProjects, Is.Not.Empty);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The tiers that lift the category filter are the only way the
|
|
/// LongRunning and durable-subscription tests ever run. They belong to
|
|
/// the full scope and must stay out of the pull-request scope.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task UnfilteredTiersRunOnlyInTheFullScopeAsync()
|
|
{
|
|
MatrixResult pr = await RunMatrixAsync("pr").ConfigureAwait(false);
|
|
MatrixResult full = await RunMatrixAsync("full").ConfigureAwait(false);
|
|
|
|
Assert.That(pr.Tests.All(entry => entry.Tier == "mainline"), Is.True);
|
|
Assert.That(full.Tests.Any(entry => entry.Tier == "long-running"), Is.True);
|
|
Assert.That(full.Tests.Any(entry => entry.Tier == "durable"), Is.True);
|
|
Assert.That(
|
|
full.Tests.Where(entry => entry.Tier != "mainline").All(entry => entry.Filter.Length == 0),
|
|
Is.True,
|
|
"A tier that exists to lift the category filter must not carry one.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// coverlet.collector ships build assets for net8.0 and newer only, so
|
|
/// attaching it to a .NET Framework test host produces a warning and no
|
|
/// report. Requesting coverage there would make the merged report look
|
|
/// complete while silently missing those legs.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task CoverageIsNeverRequestedOnANetFrameworkHostAsync()
|
|
{
|
|
MatrixResult full = await RunMatrixAsync("full").ConfigureAwait(false);
|
|
|
|
MatrixEntry[] offenders = full.Tests
|
|
.Where(entry => entry.Framework.StartsWith("net4", StringComparison.Ordinal) && entry.Coverage)
|
|
.ToArray();
|
|
|
|
Assert.That(offenders.Select(entry => entry.Id), Is.Empty);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The pull-request scope has to be the union of what the two CI systems
|
|
/// covered separately, otherwise migrating to Actions loses a leg.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task PullRequestScopeCoversBothFormerCiSystemsAsync()
|
|
{
|
|
MatrixResult pr = await RunMatrixAsync("pr").ConfigureAwait(false);
|
|
|
|
string[] profiles = pr.Tests.Select(entry => entry.Profile).Distinct(StringComparer.Ordinal).ToArray();
|
|
|
|
Assert.That(profiles, Does.Contain("windows-net48"));
|
|
Assert.That(profiles, Does.Contain("windows-net10.0"));
|
|
Assert.That(profiles, Does.Contain("linux-net10.0"));
|
|
Assert.That(profiles, Does.Contain("macos-net10.0"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// The private-fuzz-corpus job narrows the same profile table to one
|
|
/// project instead of repeating the profile list, so the narrowing has
|
|
/// to keep the profiles and drop everything else.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task OnlyProjectNarrowsTheMatrixToThatProjectAsync()
|
|
{
|
|
const string project = "fuzzing/Opc.Ua.Encoders.Fuzz.Tests/Opc.Ua.Encoders.Fuzz.Tests.csproj";
|
|
MatrixResult matrix = await RunMatrixAsync("full", onlyProject: project).ConfigureAwait(false);
|
|
|
|
Assert.That(matrix.Tests, Is.Not.Empty);
|
|
Assert.That(
|
|
matrix.Tests.All(entry => entry.Projects == project),
|
|
Is.True,
|
|
"Narrowing must not leave any other project scheduled.");
|
|
Assert.That(
|
|
matrix.Tests.All(entry => entry.Tier == "mainline"),
|
|
Is.True,
|
|
"The named tiers cover named projects and must drop out when narrowing.");
|
|
Assert.That(
|
|
matrix.Tests.Select(entry => entry.Profile).Distinct(StringComparer.Ordinal).Count(),
|
|
Is.EqualTo(matrix.Tests.Count),
|
|
"One project produces exactly one batch per profile.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// A typo in the narrowing argument must not produce an empty matrix
|
|
/// that reports success without replaying anything.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task OnlyProjectFailsWhenNothingMatchesAsync()
|
|
{
|
|
ScriptResult result = await RunScriptAsync("full", onlyProject: "does/not/Exist.Tests.csproj")
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.That(result.ExitCode, Is.Not.Zero);
|
|
Assert.That(result.Output, Does.Contain("would report success without testing anything"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// A batch job is cancelled by GitHub the moment it passes
|
|
/// timeout-minutes, and a cancelled job produces neither the executor's
|
|
/// per-project annotation nor its results. The job budget therefore has
|
|
/// to be an upper bound on everything the executor may spend: fixed
|
|
/// setup cost plus one per-project ceiling for each project in the
|
|
/// batch, never a clamped value.
|
|
/// </summary>
|
|
[TestCase("pr")]
|
|
[TestCase("full")]
|
|
public async Task JobTimeoutBoundsEveryProjectsCombinedBudgetAsync(string scope)
|
|
{
|
|
MatrixResult matrix = await RunMatrixAsync(scope).ConfigureAwait(false);
|
|
|
|
string[] underBudget = matrix.Tests
|
|
.Where(entry =>
|
|
entry.TimeoutMinutes <
|
|
entry.Projects.Split(';', StringSplitOptions.RemoveEmptyEntries).Length *
|
|
entry.PerProjectTimeout)
|
|
.Select(entry => $"{entry.Id} allows {entry.TimeoutMinutes}min for " +
|
|
$"{entry.Projects.Split(';', StringSplitOptions.RemoveEmptyEntries).Length} x " +
|
|
$"{entry.PerProjectTimeout}min")
|
|
.ToArray();
|
|
|
|
Assert.That(underBudget, Is.Empty);
|
|
Assert.That(matrix.Tests.All(entry => entry.PerProjectTimeout > 0), Is.True);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The ceiling covers the build and test together. The net48 server
|
|
/// project has a roughly five-minute clean build and a roughly
|
|
/// twenty-minute test run on hosted Windows, so a 30-minute combined
|
|
/// ceiling has no useful runner-variance margin and has killed a healthy
|
|
/// run. Every ordinary project receives the established 45-minute
|
|
/// combined ceiling.
|
|
/// </summary>
|
|
[TestCase("pr")]
|
|
[TestCase("full")]
|
|
public async Task MainlineProjectsHaveACombinedFortyFiveMinuteCeilingAsync(string scope)
|
|
{
|
|
MatrixResult matrix = await RunMatrixAsync(scope).ConfigureAwait(false);
|
|
|
|
string[] undersized = matrix.Tests
|
|
.Where(entry => entry.Tier == "mainline" && entry.PerProjectTimeout < 45)
|
|
.Select(entry => $"{entry.Id}: {entry.PerProjectTimeout}min")
|
|
.ToArray();
|
|
|
|
Assert.That(undersized, Is.Empty);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The per-project ceiling the matrix budgets once must also be spent
|
|
/// once. Handing it separately to the build and to the test would let a
|
|
/// project burn twice what its job was given, so both invocations share
|
|
/// a single stopwatch.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task ExecutorSpendsOnePerProjectBudgetAcrossBuildAndTestAsync()
|
|
{
|
|
string executor = Path.Combine(FindRepositoryRoot(), ".github", "scripts", "run-dotnet-tests.ps1");
|
|
string source = await File.ReadAllTextAsync(executor).ConfigureAwait(false);
|
|
|
|
string[] invocations = source
|
|
.Split('\n')
|
|
.Select(line => line.Trim())
|
|
.Where(line => line.Contains("= Invoke-Dotnet ", StringComparison.Ordinal))
|
|
.ToArray();
|
|
|
|
Assert.That(invocations, Has.Length.EqualTo(2), "The executor builds once and tests once per project.");
|
|
Assert.That(
|
|
invocations.All(line => line.Contains("$projectBudget $PerProjectTimeoutMinutes", StringComparison.Ordinal)),
|
|
Is.True,
|
|
$"Both invocations must share the one stopwatch: {string.Join(" | ", invocations)}");
|
|
Assert.That(
|
|
source,
|
|
Does.Contain("$projectBudget = [System.Diagnostics.Stopwatch]::StartNew()"),
|
|
"The stopwatch has to be restarted for each project rather than spanning the batch.");
|
|
}
|
|
|
|
private static async Task<MatrixResult> RunMatrixAsync(
|
|
string scope,
|
|
bool excludeMacOs = false,
|
|
string? onlyProject = null)
|
|
{
|
|
string outputPath = Path.Combine(Path.GetTempPath(), $"ci-matrix-{Guid.NewGuid():N}.txt");
|
|
try
|
|
{
|
|
ScriptResult result = await RunScriptAsync(scope, excludeMacOs, onlyProject, outputPath)
|
|
.ConfigureAwait(false);
|
|
Assert.That(result.ExitCode, Is.Zero, result.Output);
|
|
|
|
string[] lines = await File.ReadAllLinesAsync(outputPath).ConfigureAwait(false);
|
|
return new MatrixResult(
|
|
Deserialize<MatrixEntry>(lines, "tests="),
|
|
Deserialize<BuildEntry>(lines, "builds="),
|
|
int.Parse(Value(lines, "batch_size="), CultureInfo.InvariantCulture));
|
|
}
|
|
finally
|
|
{
|
|
File.Delete(outputPath);
|
|
}
|
|
}
|
|
|
|
private static List<T> Deserialize<T>(string[] lines, string prefix)
|
|
{
|
|
return JsonSerializer.Deserialize<List<T>>(Value(lines, prefix), s_json) ??
|
|
throw new InvalidOperationException($"'{prefix}' did not carry a JSON array.");
|
|
}
|
|
|
|
private static string Value(string[] lines, string prefix)
|
|
{
|
|
string? line = lines.FirstOrDefault(candidate => candidate.StartsWith(prefix, StringComparison.Ordinal));
|
|
Assert.That(line, Is.Not.Null, $"The script emitted no '{prefix}' line.");
|
|
return line![prefix.Length..].Trim();
|
|
}
|
|
|
|
private static async Task<ScriptResult> RunScriptAsync(
|
|
string scope,
|
|
bool excludeMacOs = false,
|
|
string? onlyProject = null,
|
|
string? githubOutputPath = null)
|
|
{
|
|
string root = FindRepositoryRoot();
|
|
using var process = new Process();
|
|
process.StartInfo.FileName = "pwsh";
|
|
process.StartInfo.WorkingDirectory = root;
|
|
process.StartInfo.RedirectStandardOutput = true;
|
|
process.StartInfo.RedirectStandardError = true;
|
|
PowerShellScriptOutput.ConfigureDeterministicOutput(process.StartInfo);
|
|
process.StartInfo.ArgumentList.Add("-NoProfile");
|
|
process.StartInfo.ArgumentList.Add("-File");
|
|
process.StartInfo.ArgumentList.Add(Path.Combine(root, ".github", "scripts", "get-ci-matrix.ps1"));
|
|
process.StartInfo.ArgumentList.Add("-Scope");
|
|
process.StartInfo.ArgumentList.Add(scope);
|
|
process.StartInfo.ArgumentList.Add("-RepositoryRoot");
|
|
process.StartInfo.ArgumentList.Add(root);
|
|
if (excludeMacOs)
|
|
{
|
|
process.StartInfo.ArgumentList.Add("-ExcludeMacOS");
|
|
}
|
|
if (!string.IsNullOrEmpty(onlyProject))
|
|
{
|
|
process.StartInfo.ArgumentList.Add("-OnlyProject");
|
|
process.StartInfo.ArgumentList.Add(onlyProject);
|
|
}
|
|
|
|
// The matrices only reach GITHUB_OUTPUT, so pointing it at a
|
|
// temporary file exercises the same path a workflow run takes.
|
|
if (string.IsNullOrEmpty(githubOutputPath))
|
|
{
|
|
process.StartInfo.Environment.Remove("GITHUB_OUTPUT");
|
|
}
|
|
else
|
|
{
|
|
process.StartInfo.Environment["GITHUB_OUTPUT"] = githubOutputPath;
|
|
}
|
|
|
|
Assert.That(process.Start(), Is.True);
|
|
Task<string> standardOutput = process.StandardOutput.ReadToEndAsync();
|
|
Task<string> standardError = process.StandardError.ReadToEndAsync();
|
|
using var timeout = new CancellationTokenSource(TimeSpan.FromMinutes(2));
|
|
await process.WaitForExitAsync(timeout.Token).ConfigureAwait(false);
|
|
|
|
string output = await standardOutput.ConfigureAwait(false);
|
|
string error = await standardError.ConfigureAwait(false);
|
|
return new ScriptResult(process.ExitCode, PowerShellScriptOutput.Normalize(output + error));
|
|
}
|
|
|
|
private static string FindRepositoryRoot()
|
|
{
|
|
string? current = TestContext.CurrentContext.TestDirectory;
|
|
while (!string.IsNullOrWhiteSpace(current))
|
|
{
|
|
if (File.Exists(Path.Combine(current, ".github", "scripts", "get-ci-matrix.ps1")))
|
|
{
|
|
return current;
|
|
}
|
|
current = Directory.GetParent(current)?.FullName;
|
|
}
|
|
|
|
throw new InvalidOperationException("Could not find the repository root.");
|
|
}
|
|
|
|
private sealed record ScriptResult(int ExitCode, string Output);
|
|
|
|
private sealed record MatrixResult(
|
|
IReadOnlyList<MatrixEntry> Tests,
|
|
IReadOnlyList<BuildEntry> Builds,
|
|
int BatchSize);
|
|
|
|
/// <summary>
|
|
/// One expanded test matrix entry. Deserialized by reflection, hence public.
|
|
/// </summary>
|
|
public sealed record MatrixEntry(
|
|
string Id,
|
|
string Os,
|
|
string Profile,
|
|
string Tier,
|
|
string Framework,
|
|
string Filter,
|
|
bool Coverage,
|
|
string Projects,
|
|
int PerProjectTimeout,
|
|
int TimeoutMinutes);
|
|
|
|
/// <summary>
|
|
/// One expanded solution build matrix entry.
|
|
/// </summary>
|
|
public sealed record BuildEntry(string Id, string Os, string Solution, string CustomTestTarget);
|
|
|
|
private static readonly JsonSerializerOptions s_json = new()
|
|
{
|
|
PropertyNameCaseInsensitive = true
|
|
};
|
|
}
|
|
}
|
|
#endif
|