Skip to content

Commit

Permalink
adding support for overriding TRX XSL stylesheet
Browse files Browse the repository at this point in the history
  • Loading branch information
ebekker committed Jan 5, 2021
1 parent daddeba commit 6e6bc7c
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 6 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ jobs:
gist_badge_label: 'XUnit Tests: %Counters_passed%/%Counters_total%'
gist_token: ${{ secrets.GIST_TOKEN }}

- name: use this action, xunit project dir, ALTERNATE XSL
if: ${{ !cancelled() }}
id: testAction3a2
uses: ./
with:
project_path: tests/samples.xunit/AssertExamples
report_name: tests_1_xunit_altxsl-${{ matrix.os }}
report_title: Sample XUnit Tests (Alt XSL) (${{ matrix.os }})
github_token: ${{ secrets.GITHUB_TOKEN }}
gist_name: dotnet-tests-report_xunit_altxsl-${{ matrix.os }}.md
gist_badge_label: 'XUnit Tests (Alt XSL): %Counters_passed%/%Counters_total%'
gist_token: ${{ secrets.GIST_TOKEN }}
trx_xsl_path: trx-report/trx2md-alt-sample.xsl

- name: use this action, nunit project dir
if: ${{ !cancelled() }}
id: testAction3b
Expand Down Expand Up @@ -106,6 +120,12 @@ jobs:
Write-ActionInfo ' * passed_count = ${{ steps.testAction3a.outputs.passed_count }}'
Write-ActionInfo ' * failed_count = ${{ steps.testAction3a.outputs.failed_count }}'
Write-ActionInfo ''
Write-ActionInfo ' xUnit (XSL Alt):'
Write-ActionInfo ' * result_value = ${{ steps.testAction3a2.outputs.result_value }}'
Write-ActionInfo ' * total_count = ${{ steps.testAction3a2.outputs.total_count }}'
Write-ActionInfo ' * passed_count = ${{ steps.testAction3a2.outputs.passed_count }}'
Write-ActionInfo ' * failed_count = ${{ steps.testAction3a2.outputs.failed_count }}'
Write-ActionInfo ''
Write-ActionInfo ' NUnit:'
Write-ActionInfo ' * result_value = ${{ steps.testAction3b.outputs.result_value }}'
Write-ActionInfo ' * total_count = ${{ steps.testAction3b.outputs.total_count }}'
Expand Down
25 changes: 22 additions & 3 deletions action.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ $inputs = @{
gist_badge_message = Get-ActionInput gist_badge_message
gist_token = Get-ActionInput gist_token -Required
set_check_status_from_test_outcome = Get-ActionInput set_check_status_from_test_outcome
trx_xsl_path = Get-ActionInput trx_xsl_path
}

$tmpDir = Join-Path $PWD _TMP
Expand All @@ -41,6 +42,7 @@ New-Item -Name $tmpDir -ItemType "directory" -Force
function Build-MarkdownReport {
$script:report_name = $inputs.report_name
$script:report_title = $inputs.report_title
$script:trx_xsl_path = $inputs.trx_xsl_path

if (-not $script:report_name) {
$script:report_name = "TEST_RESULTS_$([datetime]::Now.ToString('yyyyMMdd_hhmmss'))"
Expand All @@ -50,11 +52,28 @@ function Build-MarkdownReport {
}

$script:test_report_path = Join-Path $tmpDir test-results.md
& "$PSScriptRoot/trx-report/trx2md.ps1" -Verbose `
-trxFile $script:test_results_path `
-mdFile $script:test_report_path -xslParams @{
$trx2mdParams = @{
trxFile = $script:test_results_path
mdFile = $script:test_report_path
xslParams = @{
reportTitle = $script:report_title
}
}
if ($script:trx_xsl_path) {
$script:trx_xsl_path = "$(Resolve-Path $script:trx_xsl_path)"
Write-ActionInfo "Override TRX XSL Path Provided"
Write-ActionInfo " resolved as: $($script:trx_xsl_path)"

if (Test-Path $script:trx_xsl_path) {
## If XSL path is provided and exists, override the default
$trx2mdParams.xslFile = $script:trx_xsl_path
}
else {
Write-ActionWarning "Could not find TRX XSL at resolved path; IGNORING"
}
}
& "$PSScriptRoot/trx-report/trx2md.ps1" @trx2mdParams -Verbose

}

function Publish-ToCheckRun {
Expand Down
9 changes: 7 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ inputs:
gist_name:
description: |
If this value is specifed, the Test Results Report will be
If this value is specified, the Test Results Report will be
attached as a version of a Gist under the name of this input.
The `gist_token` input is also required to use this feature.
Expand Down Expand Up @@ -115,7 +115,12 @@ inputs:
description: |
If set to true, GitHub check status will be set to 'failure'
if at least one test fails. If all tests pass then check status will
be set to 'success'
be set to 'success'.
trx_xsl_path:
description: |
If specified, will override the default XSL transformation stylesheet
used to convert TRX input file to a Markdown report.
Expand Down
89 changes: 89 additions & 0 deletions trx-report/trx2md-alt-sample.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns:dt="urn:schemas-microsoft-com:datatypes"
xmlns:trxfn="urn:trxfn"
xmlns:trx="http://microsoft.com/schemas/VisualStudio/TeamTest/2010"
>

<xsl:output method="text"/>
<xsl:strip-space elements="*"/>

<xsl:param name="reportTitle" select="/trx:TestRun/@name" />

<xsl:template match="/">
<xsl:variable name="startTime" select="/trx:TestRun/trx:Times/@start" as="xs:date" />
<xsl:variable name="finishTime" select="/trx:TestRun/trx:Times/@finish" as="xs:date" />
# Test Results - <xsl:value-of select="$reportTitle" />

* Duration: <xsl:value-of select="trxfn:DiffSeconds($startTime, $finishTime)" /> seconds
* Outcome: <xsl:value-of select="/trx:TestRun/trx:ResultSummary/@outcome"
/> | Total Tests: <xsl:value-of select="/trx:TestRun/trx:ResultSummary/trx:Counters/@total"
/> | Passed: <xsl:value-of select="/trx:TestRun/trx:ResultSummary/trx:Counters/@passed"
/> | Failed: <xsl:value-of select="/trx:TestRun/trx:ResultSummary/trx:Counters/@failed" />

## Tests:

<xsl:apply-templates select="/trx:TestRun/trx:TestDefinitions"/>
</xsl:template>

<xsl:template match="trx:UnitTest">
<xsl:variable name="testId"
select="@id" />
<xsl:variable name="testResult"
select="/trx:TestRun/trx:Results/trx:UnitTestResult[@testId=$testId]" />
<xsl:variable name="testOutcomeIcon">
<xsl:choose>
<xsl:when test="$testResult/@outcome = 'Passed'">:heavy_check_mark:</xsl:when>
<xsl:when test="$testResult/@outcome = 'Failed'">:x:</xsl:when>
<xsl:when test="$testResult/@outcome = 'NotExecuted'">:radio_button:</xsl:when>
<xsl:otherwise>:grey_question:</xsl:otherwise>
</xsl:choose>
</xsl:variable>

&lt;details&gt;
&lt;summary&gt;
<xsl:value-of select="$testOutcomeIcon" />
<xsl:text> </xsl:text>
<xsl:value-of select="@name" />
&lt;/summary&gt;

| | |
|-|-|
| **Name:** | `<xsl:value-of select="@name" />`
| **Code Base:** | `<xsl:value-of select="trx:TestMethod/@codeBase" />`
| **Outcome:** | `<xsl:value-of select="$testResult/@outcome" />` <xsl:value-of select="$testOutcomeIcon" />
| **Computer Name:** | `<xsl:value-of select="$testResult/@computerName" />`
| **Duration:** | `<xsl:value-of select="$testResult/@duration" />`


<xsl:if test="$testResult/@outcome = 'Failed'">

&lt;details&gt;
&lt;summary&gt;Error Message:&lt;/summary&gt;

```text
<xsl:value-of select="$testResult/trx:Output/trx:ErrorInfo/trx:Message" />
```
&lt;/details&gt;

&lt;details&gt;
&lt;summary&gt;Error Stack Trace:&lt;/summary&gt;

```text
<xsl:value-of select="$testResult/trx:Output/trx:ErrorInfo/trx:StackTrace" />
```
&lt;/details&gt;

</xsl:if>

-----

&lt;/details&gt;

</xsl:template>

</xsl:stylesheet>
1 change: 0 additions & 1 deletion trx-report/trx2md.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ if (-not $xslFile) {
elseif ($xslFile -notmatch '^[/\\]') {
$xslFile = [System.IO.Path]::Combine($PWD, $xslFile)
Write-Verbose "Resolving XSL file relative to current directory: $xslFile"

}

class TrxFn {
Expand Down

0 comments on commit 6e6bc7c

Please sign in to comment.