From eb8dd779cbe3c1446062b82cb380da2a447d1665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Sun, 7 Sep 2025 17:22:02 +0200 Subject: [PATCH] refactor: remove core mutation tests only on `main` --- .github/workflows/build.yml | 27 ++++++++++++++++++- Pipeline/Build.MutationTests.cs | 48 +++++++++++++++++++++++---------- 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 899a39d7d..6fe722f2b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -64,6 +64,31 @@ jobs: ./Artifacts/* ./TestResults/*.trx + mutation-tests-core: + name: "Mutation tests (aweXpect.Core)" + runs-on: ubuntu-latest + env: + STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} + DOTNET_NOLOGO: true + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + - name: Setup .NET SDKs + uses: actions/setup-dotnet@v4 + with: + dotnet-version: | + 8.0.x + - name: Run mutation tests + run: ./build.sh MutationTestsCore + - name: Upload artifacts + if: always() + uses: actions/upload-artifact@v4 + with: + name: MutationTestsCore + path: | + ./Artifacts/* + mutation-tests-main: name: "Mutation tests (aweXpect)" runs-on: ubuntu-latest @@ -91,7 +116,7 @@ jobs: mutation-tests-dashboard: name: "Mutation tests Dashboard" - needs: [ mutation-tests-main ] + needs: [ mutation-tests-main, mutation-tests-core ] runs-on: ubuntu-latest env: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} diff --git a/Pipeline/Build.MutationTests.cs b/Pipeline/Build.MutationTests.cs index f646ff4d8..cca34ced6 100644 --- a/Pipeline/Build.MutationTests.cs +++ b/Pipeline/Build.MutationTests.cs @@ -28,9 +28,11 @@ partial class Build Target MutationTestsCore => _ => _ .DependsOn(Compile) .OnlyWhenDynamic(() => BuildScope == BuildScope.Default) + .OnlyWhenDynamic(() => BranchName != "main") .Executes(() => { - ExecuteMutationTest(Solution.aweXpect_Core, [..FrameworkUnitTestProjects, Solution.Tests.aweXpect_Core_Tests,]); + ExecuteMutationTest(Solution.aweXpect_Core, + [..FrameworkUnitTestProjects, Solution.Tests.aweXpect_Core_Tests,]); }); Target MutationTestsMain => _ => _ @@ -38,8 +40,10 @@ partial class Build .OnlyWhenDynamic(() => BuildScope == BuildScope.Default) .Executes(() => { - ExecuteMutationTest(Solution.aweXpect, [Solution.Tests.aweXpect_Tests, Solution.Tests.aweXpect_Internal_Tests,]); + ExecuteMutationTest(Solution.aweXpect, + [Solution.Tests.aweXpect_Tests, Solution.Tests.aweXpect_Internal_Tests,]); }); + Target MutationTestsComment => _ => _ .After(MutationTestsMain) .After(MutationTestsCore) @@ -51,13 +55,13 @@ partial class Build { Log.Debug("Missing PR.txt file in artifacts"); } - + string prNumber = File.ReadAllText(ArtifactsDirectory / "aweXpect" / "PR.txt"); Log.Debug("Pull request number: {PullRequestId}", prNumber); - var mutationCommentBodies = new List(); - foreach (var file in ArtifactsDirectory.GetFiles("MutationTest_*.md", 2)) + List mutationCommentBodies = []; + foreach (AbsolutePath file in ArtifactsDirectory.GetFiles("MutationTest_*.md", 2)) { - var body = await File.ReadAllTextAsync(file); + string body = await File.ReadAllTextAsync(file); mutationCommentBodies.Add(body); } @@ -116,21 +120,36 @@ await gitHubClient.Issue.Comment.Update("aweXpect", "aweXpect", await "MutationTestsCore".DownloadArtifactTo(ArtifactsDirectory / "aweXpect.Core", GithubToken); await "MutationTestsMain".DownloadArtifactTo(ArtifactsDirectory / "aweXpect", GithubToken); - Dictionary projects = new() + Dictionary projects; + if (BranchName != "main") { + projects = new Dictionary { - Solution.aweXpect, [Solution.Tests.aweXpect_Tests, Solution.Tests.aweXpect_Internal_Tests,] - }, + { + Solution.aweXpect, [Solution.Tests.aweXpect_Tests, Solution.Tests.aweXpect_Internal_Tests,] + }, + { + Solution.aweXpect_Core, [..FrameworkUnitTestProjects, Solution.Tests.aweXpect_Core_Tests,] + }, + }; + } + else + { + projects = new Dictionary { - Solution.aweXpect_Core, [..FrameworkUnitTestProjects, Solution.Tests.aweXpect_Core_Tests,] - }, - }; + { + Solution.aweXpect, [Solution.Tests.aweXpect_Tests, Solution.Tests.aweXpect_Internal_Tests,] + }, + }; + } + string apiKey = Environment.GetEnvironmentVariable("STRYKER_DASHBOARD_API_KEY"); foreach (KeyValuePair project in projects) { string branchName = File.ReadAllText(ArtifactsDirectory / project.Key.Name / "BranchName.txt"); string reportComment = - File.ReadAllText(ArtifactsDirectory / project.Key.Name / "Stryker" / "reports" / "mutation-report.json"); + File.ReadAllText(ArtifactsDirectory / project.Key.Name / "Stryker" / "reports" / + "mutation-report.json"); using HttpClient client = new(); client.DefaultRequestHeaders.Add("X-Api-Key", apiKey); // https://stryker-mutator.io/docs/General/dashboard/#send-a-report-via-curl @@ -204,7 +223,8 @@ private void ExecuteMutationTest(Project project, Project[] testProjects) $"Stryker did not execute successfully for {project.Name}: (exit code {process.ExitCode})."); } - File.WriteAllText(ArtifactsDirectory / $"MutationTest_{project.Name}.md", CreateMutationCommentBody(project.Name)); + File.WriteAllText(ArtifactsDirectory / $"MutationTest_{project.Name}.md", + CreateMutationCommentBody(project.Name)); if (GitHubActions?.IsPullRequest == true) {