Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page Scripting test result visualizer & updated test analyzer logic. #1423

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 36 additions & 26 deletions Actions/AnalyzeTests/AnalyzeTests.ps1
Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
Param(
[Parameter(HelpMessage = "Project to analyze", Mandatory = $false)]
[string] $project = '.'
[string] $project = '.',
[Parameter(HelpMessage = "Tests to analyze", Mandatory = $false)]
[ValidateSet('normal', 'bcpt', 'pageScripting')]
[string] $testType = 'normal'
)

. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve)

. (Join-Path -Path $PSScriptRoot 'TestResultAnalyzer.ps1')

$testResultsFile = Join-Path $ENV:GITHUB_WORKSPACE "$project\TestResults.xml"
$testResultsSummaryMD, $testResultsfailuresMD, $testResultsFailuresSummaryMD = GetTestResultSummaryMD -testResultsFile $testResultsFile
$testResultsSummaryMD = ''
$testResultsfailuresMD = ''
$testResultsFailuresSummaryMD = ''

$settings = $env:Settings | ConvertFrom-Json
$bcptTestResultsFile = Join-Path $ENV:GITHUB_WORKSPACE "$project\bcptTestResults.json"
$bcptBaseLineFile = Join-Path $ENV:GITHUB_WORKSPACE "$project\bcptBaseLine.json"
$bcptThresholdsFile = Join-Path $ENV:GITHUB_WORKSPACE "$project\bcptThresholds.json"
$bcptSummaryMD = GetBcptSummaryMD `
-bcptTestResultsFile $bcptTestResultsFile `
-baseLinePath $bcptBaseLineFile `
-thresholdsPath $bcptThresholdsFile `
-bcptThresholds ($settings.bcptThresholds | ConvertTo-HashTable)
if ($testType -eq 'normal') {
$testResultsFile = Join-Path $ENV:GITHUB_WORKSPACE "$project\TestResults.xml"
$testResultsSummaryMD, $testResultsfailuresMD, $testResultsFailuresSummaryMD = GetTestResultSummaryMD -testResultsFile $testResultsFile
$testTitle = "Test results"
}
elseif ($testType -eq 'bcpt') {
$settings = $env:Settings | ConvertFrom-Json
$bcptTestResultsFile = Join-Path $ENV:GITHUB_WORKSPACE "$project\bcptTestResults.json"
$bcptBaseLineFile = Join-Path $ENV:GITHUB_WORKSPACE "$project\bcptBaseLine.json"
$bcptThresholdsFile = Join-Path $ENV:GITHUB_WORKSPACE "$project\bcptThresholds.json"
$testResultsSummaryMD = GetBcptSummaryMD `
-bcptTestResultsFile $bcptTestResultsFile `
-baseLinePath $bcptBaseLineFile `
-thresholdsPath $bcptThresholdsFile `
-bcptThresholds ($settings.bcptThresholds | ConvertTo-HashTable)
$testTitle = "Performance test results"
}
elseif ($testType -eq 'pageScripting') {
$testResultsFile = Join-Path $ENV:GITHUB_WORKSPACE "$project\PageScriptingTestResults.xml"
$testResultsSummaryMD, $testResultsfailuresMD, $testResultsFailuresSummaryMD = GetPageScriptingTestResultSummaryMD -testResultsFile $testResultsFile
$testTitle = "Page Scripting test results"
}
else {
Write-Host "::error:: Unknown test type: $testsToAnalyze"
return ''
}

# If summary fits, we will display it in the GitHub summary
if ($testResultsSummaryMD.Length -gt 65000) {
# If Test results summary is too long, we will not display it in the GitHub summary, instead we will display a message to download the test results
$testResultsSummaryMD = "<i>Test results summary size exceeds GitHub summary capacity. Download **TestResults** artifact to see details.</i>"
}
# If summary AND BCPT summary fits, we will display both in the GitHub summary
if ($testResultsSummaryMD.Length + $bcptSummaryMD.Length -gt 65000) {
# If Combined Test Results and BCPT summary exceeds GitHub summary capacity, we will not display the BCPT summary
$bcptSummaryMD = "<i>Performance test results summary size exceeds GitHub summary capacity. Download **BcptTestResults** artifact to see details.</i>"
}
# If summary AND BCPT summary AND failures summary fits, we will display all in the GitHub summary
if ($testResultsSummaryMD.Length + $testResultsfailuresMD.Length + $bcptSummaryMD.Length -gt 65000) {
# If Combined Test Results, failures and BCPT summary exceeds GitHub summary capacity, we will not display the failures details, only the failures summary
if ($testResultsSummaryMD.Length + $testResultsfailuresMD.Length -gt 65000) {
# If Combined Test Results and failures exceeds GitHub summary capacity, we will not display the failures details, only the failures summary
$testResultsfailuresMD = $testResultsFailuresSummaryMD
}

Add-Content -Encoding UTF8 -path $ENV:GITHUB_STEP_SUMMARY -value "## Test results`n`n"
Add-Content -Encoding UTF8 -path $ENV:GITHUB_STEP_SUMMARY -value "## $testTitle`n`n"
Add-Content -Encoding UTF8 -path $ENV:GITHUB_STEP_SUMMARY -value "$($testResultsSummaryMD.Replace("\n","`n"))`n`n"
Add-Content -Encoding UTF8 -path $ENV:GITHUB_STEP_SUMMARY -value "$($testResultsfailuresMD.Replace("\n","`n"))`n`n"
if ($bcptSummaryMD) {
Add-Content -Encoding UTF8 -path $ENV:GITHUB_STEP_SUMMARY -value "## Performance test results`n`n"
Add-Content -Encoding UTF8 -path $ENV:GITHUB_STEP_SUMMARY -value "$($bcptSummaryMD.Replace("\n","`n"))`n`n"
}
1 change: 1 addition & 0 deletions Actions/AnalyzeTests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ none
| :-- | :-: | :-- | :-- |
| shell | | The shell (powershell or pwsh) in which the PowerShell script in this action should run | powershell |
| project | Yes | Name of project to analyze or . if the repository is setup for single project | |
| testType | No | Which type of tests to analyze. Should be one of ('normal', 'bcpt', 'pageScripting') | normal |

## OUTPUT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the action has output. OUTPUT variables might need to be cleaned up.


Expand Down
75 changes: 74 additions & 1 deletion Actions/AnalyzeTests/TestResultAnalyzer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function GetBcptSummaryMD {

$bcpt = ReadBcptFile -bcptTestResultsFile $bcptTestResultsFile
if (-not $bcpt) {
return ''
return '<i>No test results found</i>'
}
$baseLine = ReadBcptFile -bcptTestResultsFile $baseLinePath
if ($baseLine) {
Expand Down Expand Up @@ -322,3 +322,76 @@ function GetBcptSummaryMD {

$summarySb.ToString()
}

function GetPageScriptingTestResultSummaryMD {
Param(
[string] $testResultsFile
)

$summarySb = [System.Text.StringBuilder]::new()
$failuresSb = [System.Text.StringBuilder]::new()

if (Test-Path -Path $testResultsFile -PathType Leaf) {
$testResults = [xml](Get-Content -path $testResultsFile -Encoding UTF8)
$totalTests = 0
$totalTime = 0.0
$totalFailed = 0
$totalSkipped = 0

if ($testResults.testsuites) {
$totalTests = $testResults.testsuites.tests
$totalTime = $testResults.testsuites.time
$totalFailed = $testResults.testsuites.failures
$totalSkipped = $testResults.testsuites.skipped
$totalPassed = $totalTests - $totalFailed - $totalSkipped

#Write total summary for all test suites
Write-Host "$totalTests tests, $totalPassed passed, $totalFailed failed, $totalSkipped skipped, $totalTime seconds"
$summarySb.AppendLine('|Suite|Tests|Passed|Failed|Skipped|Time|') | Out-Null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PowerShell generating Markdown is extremely hard to read.

Is there a way to define some MD templates with placeholders that could be used to generate the end-goal MD?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try see if I can come up with something that is easier to debug / code review.

$summarySb.AppendLine('|:---|---:|---:|---:|---:|---:|') | Out-Null
foreach($testsuite in $testResults.testsuites.testsuite) {
$suiteTests = $testsuite.tests
$suiteTime = $testsuite.time
$suiteFailed = $testsuite.failures
$suiteSkipped = $testsuite.skipped
$suitePassed = $suiteTests - $suiteFailed - $suiteSkipped
$summarySb.AppendLine("|$($testsuite.name)|$suiteTests|$suitePassed$statusOk|$suiteFailed$statusError|$suiteSkipped$statusSkipped|$suiteTime|") | Out-Null

if ($suiteFailed -gt 0 ) {
$failuresSb.Append("<details><summary><i>$testsuite.name, $suiteTests tests, $suitePassed passed, $suiteFailed failed, $suiteSkipped skipped, $suiteTime seconds</i></summary>") | Out-Null
foreach($testcase in $testsuite.testcase) {
$testName = Split-Path ($testcase.name -replace '\(', '' -replace '\)', '') -Leaf
if ($testcase.failure) {
Write-Host " - Error: $($testcase.failure.message)"
Write-Host " Stacktrace:"
Write-Host " $($testcase.failure."#cdata-section".Trim().Replace("`n","`n "))"
$failuresSb.Append("<details><summary><i>$($testName), Failure</i></summary>") | Out-Null
$failuresSb.Append("<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Error: $($testcase.failure.message)</i><br/>") | Out-Null
$failuresSb.Append("<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stack trace</i><br/>") | Out-Null
$failuresSb.Append("<i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $($testcase.failure."#cdata-section")</i><br/>") | Out-Null
$failuresSb.Append("</details>") | Out-Null
}
}
$failuresSb.Append("</details>") | Out-Null
}
}
}
if ($totalFailed -gt 0) {
$failuresSummaryMD = "<i>$totalFailed failing tests, download test results to see details</i>"
$failuresSb.Insert(0,"<details><summary>$failuresSummaryMD</summary>") | Out-Null
$failuresSb.Append("</details>") | Out-Null
}
else {
$failuresSummaryMD = "<i>No test failures</i>"
$failuresSb.Append($failuresSummaryMD) | Out-Null
}
}
else {
$summarySb.Append("<i>No test results found</i>") | Out-Null
$failuresSummaryMD = ''
}

$summarySb.ToString()
$failuresSb.ToString()
$failuresSummaryMD
}
7 changes: 6 additions & 1 deletion Actions/AnalyzeTests/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ inputs:
description: Project to analyze
required: false
default: '.'
testType:
description: Tests to analyze
required: false
default: 'normal'
runs:
using: composite
steps:
- name: run
shell: ${{ inputs.shell }}
env:
_project: ${{ inputs.project }}
_testType: ${{ inputs.testType }}
run: |
${{ github.action_path }}/../Invoke-AlGoAction.ps1 -ActionName "AnalyzeTests" -Action {
${{ github.action_path }}/AnalyzeTests.ps1 -project $ENV:_project
${{ github.action_path }}/AnalyzeTests.ps1 -project $ENV:_project -testType $ENV:_testType
}
branding:
icon: terminal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
shell: ${{ inputs.shell }}
project: ${{ inputs.project }}
buildMode: ${{ inputs.buildMode }}
get: useCompilerFolder,keyVaultCodesignCertificateName,doNotSignApps,doNotRunTests,artifact,generateDependencyArtifact,trustedSigning,useGitSubmodules
get: useCompilerFolder,keyVaultCodesignCertificateName,doNotSignApps,doNotRunTests,doNotRunBcptTests,doNotRunpageScriptingTests,artifact,generateDependencyArtifact,trustedSigning,useGitSubmodules

- name: Read secrets
id: ReadSecrets
Expand Down Expand Up @@ -254,6 +254,25 @@ jobs:
with:
shell: ${{ inputs.shell }}
project: ${{ inputs.project }}
testType: "normal"

- name: Analyze BCPT Test Results
id: analyzeTestResultsBCPT
if: (success() || failure()) && env.doNotRunBcptTests == 'False'
uses: microsoft/AL-Go-Actions/AnalyzeTests@main
with:
shell: ${{ inputs.shell }}
project: ${{ inputs.project }}
testType: "bcpt"

- name: Analyze Page Scripting Test Results
id: analyzeTestResultsPageScripting
if: (success() || failure()) && env.doNotRunpageScriptingTests == 'False'
uses: microsoft/AL-Go-Actions/AnalyzeTests@main
with:
shell: ${{ inputs.shell }}
project: ${{ inputs.project }}
testType: "pageScripting"

- name: Cleanup
if: always()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
shell: ${{ inputs.shell }}
project: ${{ inputs.project }}
buildMode: ${{ inputs.buildMode }}
get: useCompilerFolder,keyVaultCodesignCertificateName,doNotSignApps,doNotRunTests,artifact,generateDependencyArtifact,trustedSigning,useGitSubmodules
get: useCompilerFolder,keyVaultCodesignCertificateName,doNotSignApps,doNotRunTests,doNotRunBcptTests,doNotRunpageScriptingTests,artifact,generateDependencyArtifact,trustedSigning,useGitSubmodules

- name: Read secrets
id: ReadSecrets
Expand Down Expand Up @@ -254,6 +254,25 @@ jobs:
with:
shell: ${{ inputs.shell }}
project: ${{ inputs.project }}
testType: "normal"

- name: Analyze BCPT Test Results
id: analyzeTestResultsBCPT
if: (success() || failure()) && env.doNotRunBcptTests == 'False'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this env variable set?

I believe it needs to be included in "Read Settings", line 97.

Same for doNotRunpageScriptingTests.

uses: microsoft/AL-Go-Actions/AnalyzeTests@main
with:
shell: ${{ inputs.shell }}
project: ${{ inputs.project }}
testType: "bcpt"

- name: Analyze Page Scripting Test Results
id: analyzeTestResultsPageScripting
if: (success() || failure()) && env.doNotRunpageScriptingTests == 'False'
uses: microsoft/AL-Go-Actions/AnalyzeTests@main
with:
shell: ${{ inputs.shell }}
project: ${{ inputs.project }}
testType: "pageScripting"

- name: Cleanup
if: always()
Expand Down
Loading