diff --git a/eng/testing/select-affected-tests.cs b/eng/testing/select-affected-tests.cs index 412c9ccc0..3a1d52026 100644 --- a/eng/testing/select-affected-tests.cs +++ b/eng/testing/select-affected-tests.cs @@ -172,6 +172,13 @@ public static async Task MainAsync(string[] args) continue; } + if (TryGetExampleTests(filePath, projectPaths, nodeToTests, out var exampleName, out var impactedExampleTests)) + { + selected.UnionWith(impactedExampleTests); + reasons.Add($"Selected {impactedExampleTests.Count} tests because {filePath} belongs to example {exampleName}."); + continue; + } + if (filePath.StartsWith("src/", StringComparison.Ordinal) || filePath.StartsWith("tests/", StringComparison.Ordinal) || filePath.StartsWith("examples/", StringComparison.Ordinal) || @@ -571,6 +578,42 @@ private static bool TryGetTypeScriptAppHostTests( return false; } + private static bool TryGetExampleTests( + string filePath, + List projectPaths, + Dictionary> nodeToTests, + out string exampleName, + out HashSet tests) + { + tests = []; + exampleName = string.Empty; + + if (!filePath.StartsWith("examples/", StringComparison.Ordinal)) + { + return false; + } + + var segments = filePath.Split('/', StringSplitOptions.RemoveEmptyEntries); + if (segments.Length < 2) + { + return false; + } + + exampleName = segments[1]; + var examplePrefix = $"examples/{exampleName}/"; + var exampleProjects = projectPaths.Where(projectPath => projectPath.StartsWith(examplePrefix, StringComparison.Ordinal)); + + foreach (var projectPath in exampleProjects) + { + if (nodeToTests.TryGetValue(projectPath, out var impacted)) + { + tests.UnionWith(impacted); + } + } + + return tests.Count > 0; + } + private static Dictionary ParseStringConstants(string contents) { var constants = new Dictionary(StringComparer.Ordinal);