-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-summary.ps1
122 lines (102 loc) · 4.1 KB
/
make-summary.ps1
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
[CmdletBinding()]
param (
[Switch]$ShowGithub = $false
)
function Get-Badge($params, $label, $body, $colour, $prefix = "") {
$labelText = $label -f $params
$bodyText = ($body -f $params) -replace " ", "_"
"$prefix"
}
function Convert-Tests($test, $prefix = "") {
$params = ($test.label -replace " ", "_"), $test.failed, $test.error, $test.passed, $test.skipped
if (($test.failed + $test.error) -eq 0) {
$label = $test.label + " successful"
$text = "{0}-{3:d}_passed%2C_{4:d}_skipped"
$colour = "6F6"
} else {
$label = $test.label + " failed"
$text = "{0}-{1:d}_failed%2C{2:d}_errored%2C{3:d}_passed%2C_{4:d}_skipped"
$colour = "F66"
}
Get-Badge $params $label $text $colour $prefix
}
function Write-Tests($test, $prefix = "") {
$params = $test.label, $test.failed, $test.error, $test.passed, $test.skipped
if (($test.failed + $test.error) -eq 0) {
$message = "{0} successful: {3:d} passed, {4:d} skipped" -f $params
} else {
$message = "{0} FAILED: {1:d} failed, {2:d} errored, {3:d} passed, {4:d} skipped" -f $params
}
Write-Host "$prefix$message"
}
function Convert-Coverage($cover, $prefix = "") {
if ($cover.linesValid -gt 0) {
$linesPerc = $cover.linesCovered * 100.0 / $cover.linesValid
} else {
$linesPerc = 0.0
}
$params = $linesPerc, $cover.linesCovered, $cover.linesValid, $cover.label
Get-Badge $params "{3} Coverage" "{3}_Coverage-{0:f2}%25_covered_{1:d}_of_{2:d}" "F6F" $prefix
}
function Write-Coverage($cover, $prefix = "") {
if ($cover.linesValid -gt 0) {
$linesPerc = $cover.linesCovered * 100.0 / $cover.linesValid
} else {
$linesPerc = 0.0
}
$params = $linesPerc, $cover.linesCovered, $cover.linesValid, ($cover.label -replace "_", " ")
$message = "{3} Coverage: {0:f2}% covered {1:d} of {2:d} lines" -f $params
Write-Host "$prefix$message"
}
[PsObject]$allCoverage = @{label = "All"; linesCovered = 0; linesValid = 0 }
$coverage = Get-ChildItem coverage -Filter "Coverage*.xml" | ForEach-Object {
[xml]$coverageXml = Get-Content $_.FullName
$lines = $coverageXml.coverage
$allCoverage.linesCovered += $lines."lines-covered"
$allCoverage.linesValid += $lines."lines-valid"
$label = $_.BaseName -replace "Coverage-", "" -replace "-", " "
@{label = $label; linesCovered = [int]$lines."lines-covered"; linesValid = [int]$lines."lines-valid" }
}
[PsObject]$allTests = @{label = "All Tests"; skipped = 0; passed = 0; failed = 0; error = 0 }
$tests = Get-ChildItem . -Recurse -Filter "TestResults*.trx" | ForEach-Object {
[xml]$trx = Get-Content $_.FullName
$name = $_.Directory.Parent.Name -replace "GqlPlus\.","" -replace "\."," "
$counts = $trx.TestRun.ResultSummary.Counters
$skipped = [int]$counts.total - $counts.executed
$allTests.skipped += $skipped
$allTests.passed += $counts.passed
$allTests.failed += $counts.failed
$allTests.error += $counts.error
@{label = $name; failed = [int]$counts.failed; error = [int]$counts.error; passed = [int]$counts.passed; skipped = $skipped }
}
Write-Tests $allTests
if ($tests.Count -gt 1) {
$tests | ForEach-Object { Write-Tests $_ "- " }
}
Write-Coverage $allCoverage
if ($coverage.Count -gt 1) {
$coverage | ForEach-Object { Write-Coverage $_ "- " }
}
if ($ShowGithub) {
Write-Host (Convert-Tests $allTests)
if ($tests.Count -gt 1) {
$tests | ForEach-Object { Write-Host (Convert-Tests $_ "- ") }
}
Write-Host (Convert-Coverage $allCoverage "`n")
if ($coverage.Count -gt 1) {
$coverage | ForEach-Object { Write-Host (Convert-Coverage $_ "- ") }
}
}
if ($env:GITHUB_STEP_SUMMARY) {
Convert-Tests $allTests | Set-Content $env:GITHUB_STEP_SUMMARY
if ($tests.Count -gt 1) {
$tests | ForEach-Object { Convert-Tests $_ "- " } | Add-Content $env:GITHUB_STEP_SUMMARY
}
Convert-Coverage $allCoverage "`n" | Add-Content $env:GITHUB_STEP_SUMMARY
if ($coverage.Count -gt 1) {
$coverage | ForEach-Object { Convert-Coverage $_ "- " } | Add-Content $env:GITHUB_STEP_SUMMARY
}
}
if ($env:GITHUB_OUTPUT) {
Convert-Coverage $allCoverage "coverage_badge=" | Set-Content $env:GITHUB_OUTPUT
}