Skip to content

Commit

Permalink
Switched the unit test reporting to a dedicated marketplace action.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisdoomen committed Oct 13, 2024
1 parent ed22799 commit 3e5ba22
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
42 changes: 38 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: build
name: Build

on: [push, pull_request]

jobs:
build:

name: "Build, Test, Analyze and Publish"
runs-on: windows-latest

env:
Expand Down Expand Up @@ -49,11 +49,16 @@ jobs:
file: TestResults/reports/lcov.info

- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v4
with:
path: ./Artifacts/*
only-unit-tests:
name: windows-artifacts
path: |
./Artifacts/*
./TestResults/*.trx
only-unit-tests:
name: "Run Unit Tests Only"
strategy:
matrix:
os: [ubuntu-24.04, macos-15]
Expand All @@ -75,3 +80,32 @@ jobs:
- name: Run NUKE
run: ./build.sh UnitTests

- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: ${{ runner.os }}-artifacts
path: |
./TestResults/*.trx
publish-test-results:
name: "Publish Tests Results"
needs: [ build, only-unit-tests ]
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
if: always()

steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
comment_mode: always
files: "artifacts/**/**/*.trx"
28 changes: 0 additions & 28 deletions Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ class Build : NukeBuild
.CombineWith(cc => cc
.SetProjectFile(project)
.AddLoggers($"trx;LogFileName={project.Name}.trx")), completeOnFailure: true);
ReportTestOutcome(globFilters: $"*{project.Name}.trx");
});

Project[] Projects =>
Expand Down Expand Up @@ -211,36 +209,12 @@ class Build : NukeBuild
)
), completeOnFailure: true
);
ReportTestOutcome(globFilters: $"*[!*{net47}].trx");
});

Target UnitTests => _ => _
.DependsOn(UnitTestsNet47)
.DependsOn(UnitTestsNet6OrGreater);

static string[] Outcomes(AbsolutePath path)
=> XmlTasks.XmlPeek(
path,
"/xn:TestRun/xn:Results/xn:UnitTestResult/@outcome",
("xn", "http://microsoft.com/schemas/VisualStudio/TeamTest/2010")).ToArray();

void ReportTestOutcome(params string[] globFilters)
{
var resultFiles = TestResultsDirectory.GlobFiles(globFilters);
var outcomes = resultFiles.SelectMany(Outcomes).ToList();
var passedTests = outcomes.Count(outcome => outcome is "Passed");
var failedTests = outcomes.Count(outcome => outcome is "Failed");
var skippedTests = outcomes.Count(outcome => outcome is "NotExecuted");

ReportSummary(_ => _
.When(failedTests > 0, c => c
.AddPair("Failed", failedTests.ToString()))
.AddPair("Passed", passedTests.ToString())
.When(skippedTests > 0, c => c
.AddPair("Skipped", skippedTests.ToString())));
}

Target CodeCoverage => _ => _
.DependsOn(TestFrameworks)
.DependsOn(UnitTests)
Expand Down Expand Up @@ -298,8 +272,6 @@ from framework in supportedFrameworks
.SetProjectFile(v.project)
.SetFramework(v.framework)
.AddLoggers($"trx;LogFileName={v.project.Name}_{v.framework}.trx")), completeOnFailure: true);
ReportTestOutcome(projects.Select(p => $"*{p.Name}*.trx").ToArray());
});

Target Pack => _ => _
Expand Down

0 comments on commit 3e5ba22

Please sign in to comment.