Skip to content

Commit

Permalink
generate test reports
Browse files Browse the repository at this point in the history
  • Loading branch information
Erwinvandervalk committed Feb 11, 2025
1 parent 3e20bbb commit 2c0254a
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 10 deletions.
28 changes: 18 additions & 10 deletions .github/workflow-gen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Logicality.GitHub.Actions.Workflow;
using System.ComponentModel;
using System.IO;
using System.Net.WebSockets;
using static GitHubContexts;

var contexts = Instance;
Expand Down Expand Up @@ -33,9 +34,11 @@
{
GenerateCiWorkflow(component);
GenerateReleaseWorkflow(component);
GenerateUploadTestResultsWorkflow(component);
}

GenerateUploadTestResultsWorkflow();


void GenerateCiWorkflow(Component component)
{
var workflow = new Workflow(component.CiWorkflowName);
Expand Down Expand Up @@ -175,12 +178,12 @@ git tag -a {component.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{c
WriteWorkflow(workflow, fileName);
}

void GenerateUploadTestResultsWorkflow(Component component)
void GenerateUploadTestResultsWorkflow()
{
var workflow = new Workflow(component.TestResultWorkflowName);
var workflow = new Workflow("generate-test-reports");
workflow.On
.WorkflowRun()
.Workflows(component.TestResultWorkflowName)
.Workflows(components.Select(x => x.CiWorkflowName).ToArray())
.Types("completed");

var job = workflow
Expand All @@ -194,11 +197,16 @@ void GenerateUploadTestResultsWorkflow(Component component)
checks: Permission.Write,
packages: Permission.Write);

foreach (var testProject in component.Tests)
foreach (var component in components)
{
job.StepGenerateReportFromTestArtifact(component.Name, testProject);
foreach (var testProject in component.Tests)
{
job.StepGenerateReportFromTestArtifact(component, testProject);
}
}

var fileName = $"generate-test-reports";
WriteWorkflow(workflow, fileName);
}

void WriteWorkflow(Workflow workflow, string fileName)
Expand Down Expand Up @@ -279,17 +287,17 @@ public static void StepUploadTestResultsAsArtifact(this Job job, string[] testPr
("retention-days", "5"));
}

public static void StepGenerateReportFromTestArtifact(this Job job, string componentName, string testProject)
internal static void StepGenerateReportFromTestArtifact(this Job job, Component component, string testProject)
{
var path = $"test/{testProject}";
job.Step()
.Name($"Test report - {testProject}")
.Name($"Test report - {component.Name} - {testProject}")
.Uses("dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5") // v1.9.1
.If("github.event == 'push' && (success() || failure())")
.If($"github.event.workflow_run.workflow == '{component.CiWorkflowName}'")
.With(
("artifact", "test-results"),
("name", $"Test Report - {testProject}"),
("path", $"{componentName}/{path}/TestResults/{LogFileName}"),
("path", $"{component.Name}/{path}/TestResults/{LogFileName}"),
("reporter", "dotnet-trx"),
("fail-on-error", "true"),
("fail-on-empty", "true"));
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/generate-test-reports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This was generated by tool. Edits will be overwritten.

name: generate-test-reports
on:
workflow_run:
workflows:
- 'ignore-this/ci'
- 'access-token-management/ci'
- 'identity-model/ci'
- 'identity-model-oidc-client/ci'
types:
- completed
jobs:
report:
name: report
runs-on: ubuntu-latest
permissions:
actions: read
checks: write
contents: read
packages: write
steps:
- name: Test report - ignore-this - IgnoreThis.Tests
if: github.event.workflow_run.workflow == 'ignore-this/ci'
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
with:
artifact: test-results
name: Test Report - IgnoreThis.Tests
path: ignore-this/test/IgnoreThis.Tests/TestResults/Tests.trx
reporter: dotnet-trx
fail-on-error: true
fail-on-empty: true
- name: Test report - access-token-management - AccessTokenManagement.Tests
if: github.event.workflow_run.workflow == 'access-token-management/ci'
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
with:
artifact: test-results
name: Test Report - AccessTokenManagement.Tests
path: access-token-management/test/AccessTokenManagement.Tests/TestResults/Tests.trx
reporter: dotnet-trx
fail-on-error: true
fail-on-empty: true
- name: Test report - identity-model - IdentityModel.Tests
if: github.event.workflow_run.workflow == 'identity-model/ci'
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
with:
artifact: test-results
name: Test Report - IdentityModel.Tests
path: identity-model/test/IdentityModel.Tests/TestResults/Tests.trx
reporter: dotnet-trx
fail-on-error: true
fail-on-empty: true
- name: Test report - identity-model-oidc-client - IdentityModel.OidcClient.Tests
if: github.event.workflow_run.workflow == 'identity-model-oidc-client/ci'
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
with:
artifact: test-results
name: Test Report - IdentityModel.OidcClient.Tests
path: identity-model-oidc-client/test/IdentityModel.OidcClient.Tests/TestResults/Tests.trx
reporter: dotnet-trx
fail-on-error: true
fail-on-empty: true

0 comments on commit 2c0254a

Please sign in to comment.