Skip to content

Commit

Permalink
Publish test results with the dorny/test-reporter GitHub action
Browse files Browse the repository at this point in the history
So that test results are available at a glance in the GitHub action run page.

Also give a proper name to the trx files in order to understand the test results, see microsoft/vstest#1876 (comment)
  • Loading branch information
0xced committed Jan 24, 2024
1 parent c914b28 commit cb90a98
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .cake-scripts/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal sealed class BuildParameters
public NuGetCredentials NuGetCredentials { get; private set; }
public BuildProjects Projects { get; private set; }
public BuildPaths Paths { get; private set; }
public DotNetMSBuildSettings MSBuildSettings { get; private set; }

public static BuildParameters Instance(ICakeContext context)
{
Expand Down Expand Up @@ -58,7 +59,8 @@ internal sealed class BuildParameters
SonarQubeCredentials = SonarQubeCredentials.GetSonarQubeCredentials(context),
NuGetCredentials = NuGetCredentials.GetNuGetCredentials(context),
Projects = BuildProjects.Instance(context, solutionFilePath),
Paths = BuildPaths.Instance(context, buildInformation.Version)
Paths = BuildPaths.Instance(context, buildInformation.Version),
MSBuildSettings = new DotNetMSBuildSettings()
};
}
}
11 changes: 11 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:

runs-on: ${{ matrix.os }}

permissions:
checks: write

steps:
- name: Checkout Repository
uses: actions/checkout@v3
Expand Down Expand Up @@ -71,6 +74,14 @@ jobs:
name: ${{ matrix.os }}
path: test-results

- name: Publish Test Results
uses: dorny/test-reporter@v1
if: always()
with:
name: Test Results (${{ matrix.os }})
path: test-results/*.trx
reporter: dotnet-trx

publish:
if: ${{ contains(fromJson('["develop", "main"]'), github.ref_name) }}

Expand Down
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Task("Tests")
NoRestore = true,
NoBuild = true,
Collectors = new[] { "XPlat Code Coverage;Format=opencover" },
Loggers = new[] { "trx" },
MSBuildSettings = param.MSBuildSettings.WithProperty("UseTrxLogger", "true"),
Filter = param.TestFilter,
ResultsDirectory = param.Paths.Directories.TestResultsDirectoryPath,
ArgumentCustomization = args => args
Expand Down
6 changes: 6 additions & 0 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@
<PropertyGroup>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
<ItemGroup>
<VSTestLogger Include="trx%3BLogFileName=$(MSBuildProjectName).trx" Condition="$(UseTrxLogger) == 'true'" />
</ItemGroup>
<PropertyGroup>
<VSTestLogger>@(VSTestLogger)</VSTestLogger>
</PropertyGroup>
</Project>

0 comments on commit cb90a98

Please sign in to comment.