forked from apache/lucenenet
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpublish-test-results.yml
More file actions
146 lines (138 loc) · 8.49 KB
/
Copy pathpublish-test-results.yml
File metadata and controls
146 lines (138 loc) · 8.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# Runs Publish Test Results task for a specific framework
parameters:
testProjectName: '' # The name of the test project
framework: '' # The target framework for display purposes.
vsTestPlatform: 'x64' # Target platform architecture used for test execution. Valid values are x86, x64, and ARM.
osName: '' # The name of the operating system for display purposes.
testResultsFormat: VSTest # Specify the format of the results files you want to publish. The following formats are supported: JUnit, NUnit, VSTest, XUnit, CTest
testResultsArtifactName: 'testresults' # The name of the Azure DevOps build artifact where the test results will be published. Default 'testresults'.
testResultsFileName: 'TestResults.trx' # The name of the file (not path) of the test results. Default 'TestResults.trx'.
steps:
#- pwsh: |
# function EnsureNotNullOrEmpty([string]$param, [string]$nameOfParam) {
# if ([string]::IsNullOrEmpty($param)) {
# Write-Host "##vso[task.logissue type=error;]Missing template parameter \"$nameOfParam\""
# Write-Host "##vso[task.complete result=Failed;]"
# }
# }
# EnsureNotNullOrEmpty('${{ parameters.testProjectName }}', 'testProjectName')
# EnsureNotNullOrEmpty('${{ parameters.framework }}', 'framework')
# EnsureNotNullOrEmpty('${{ parameters.vsTestPlatform }}', 'vsTestPlatform')
# EnsureNotNullOrEmpty('${{ parameters.osName }}', 'osName')
# EnsureNotNullOrEmpty('${{ parameters.testResultsFormat }}', 'testResultsFormat')
# EnsureNotNullOrEmpty('${{ parameters.testResultsArtifactName }}', 'testResultsArtifactName')
# EnsureNotNullOrEmpty('${{ parameters.testResultsFileName }}', 'testResultsFileName')
# displayName: 'Validate Template Parameters'
#- template: 'show-all-files.yml' # Uncomment for debugging
- pwsh: |
$testProjectName = "${{ parameters.testProjectName }}"
$testResultsFileName = "$(Build.ArtifactStagingDirectory)/${{ parameters.testResultsArtifactName }}/${{ parameters.osName }}/${{ parameters.framework }}/${{ parameters.vsTestPlatform }}/$testProjectName/${{ parameters.testResultsFileName }}"
$testResultsFileExists = Test-Path $testResultsFileName
if ($testResultsFileExists) {
$reader = [System.Xml.XmlReader]::Create($testResultsFileName)
try {
$countersFound = $false
$crashed = $false
$inRunInfos = $false
while ($reader.Read()) {
if ($reader.NodeType -eq [System.Xml.XmlNodeType]::Element) {
if (!$countersFound -and $reader.Name -eq 'Counters') {
$failed = $reader.GetAttribute('failed')
$passed = $reader.GetAttribute('passed')
$ignored = (([int]$reader.GetAttribute('total')) - ([int]$reader.GetAttribute('executed'))).ToString()
$testResults = "Tests failed: $failed, passed: $passed, ignored: $ignored"
Write-Host "##vso[task.setvariable variable=TestResults;]$testResults"
# Report a running total of failures
$totalFailures = ([int]$env:TOTALFAILURES + [int]$failed).ToString()
Write-Host "##vso[task.setvariable variable=TotalFailures;]$totalFailures"
$countersFound = $true
}
# Report a crash of the test runner
if ($reader.Name -eq 'RunInfos') {
$inRunInfos = $true
}
if ($inRunInfos -and !$crashed -and $reader.Name -eq 'Text') {
$innerXml = $reader.ReadInnerXml()
# Test for specific error messages - we may need to adjust this, as needed
if ($innerXml -and ($innerXml.Contains('Test host process crashed') `
-or $innerXml.Contains('Could not load file or assembly') `
-or $innerXml.Contains("Could not find `'dotnet.exe`' host") `
-or $innerXml.Contains('No test is available') `
-or $innerXml.Contains('exited with error'))) {
Write-Host "##vso[task.setvariable variable=HostCrashed;]true"
# Report all of the test projects that crashed
$crashedRuns = "$env:CRASHEDRUNS,$testProjectName".TrimStart(',')
Write-Host "##vso[task.setvariable variable=CrashedRuns;]$crashedRuns"
$crashed = $true
}
if ($innerXml -and ($innerXml.Contains('[ERROR]'))) {
Write-Host "##vso[task.setvariable variable=StdOutFailure;]true"
# Report all of the test projects that had stdout failures
$stdOutFailureRuns = "$env:STDOUTFAILURERUNS,$testProjectName".TrimStart(',')
Write-Host "##vso[task.setvariable variable=StdOutFailureRuns;]$stdOutFailureRuns"
$crashed = $true
}
}
}
if ($reader.NodeType -eq [System.Xml.XmlNodeType]::EndElement -and $reader.Name -eq 'RunInfos') {
$inRunInfos = $false
}
}
} finally {
$reader.Dispose()
}
} else {
Write-Host "WARNING: File not found: $testResultsFileName"
}
Write-Host "##vso[task.setvariable variable=TestResultsFileExists;]$testResultsFileExists"
displayName: 'Parse Test Results File'
- pwsh: |
$testProjectName = "${{ parameters.testProjectName }}"
$testStdErrFileName = "$(Build.ArtifactStagingDirectory)/${{ parameters.testResultsArtifactName }}/${{ parameters.osName }}/${{ parameters.framework }}/${{ parameters.vsTestPlatform }}/$testProjectName/dotnet-test-error.log"
$testStdErrFileExists = Test-Path $testStdErrFileName
if ($testStdErrFileExists) {
$fileLength = (Get-Item $testStdErrFileName).Length
if ($fileLength -gt 0) {
$stream = [System.IO.StreamReader]::new($testStdErrFileName)
try {
while (-not $stream.EndOfStream) {
$line = $stream.ReadLine()
if ($line -match "Test Run Failed" -or $line -match "\[ERROR\]") {
Write-Host "##vso[task.setvariable variable=StdErrFailure;]true"
# Report all of the test projects that had stderr failures
$stdErrFailureRuns = "$env:STDERRFAILURERUNS,$testProjectName".TrimStart(',')
Write-Host "##vso[task.setvariable variable=StdErrFailureRuns;]$stdErrFailureRuns"
break # No need to continue reading after detecting a failure
}
}
} finally {
$stream.Dispose()
}
}
} else {
Write-Host "WARNING: File not found: $testStdErrFileName"
}
displayName: 'Parse StdErr File'
- task: PublishTestResults@2
displayName: 'Publish Test Results ${{ parameters.testProjectName }},${{ parameters.framework }},${{ parameters.vsTestPlatform }}'
inputs:
testResultsFormat: ${{ parameters.testResultsFormat }}
testResultsFiles: '$(Build.ArtifactStagingDirectory)/${{ parameters.testResultsArtifactName }}/${{ parameters.osName }}/${{ parameters.framework }}/${{ parameters.vsTestPlatform }}/${{ parameters.testProjectName }}/${{ parameters.testResultsFileName }}'
testRunTitle: '${{ parameters.testProjectName }} - ${{ parameters.framework }} - ${{ parameters.vsTestPlatform }} - ${{ parameters.osName }} | $(TestResults)'
condition: and(succeeded(), eq(variables['TestResultsFileExists'], 'true'))