Repository navigation
162 lines (147 loc) · 5.31 KB
/
Copy pathcode-coverage.yml
File metadata and controls
162 lines (147 loc) · 5.31 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Code Coverage
# Automatic coverage runs once, inside Build and Validate, on pull requests and
# pushes. This workflow remains for an explicit manual rerun and does not
# subscribe to push, so master does not run the suite twice.
# Coverage is collected only for test projects that already reference
# coverlet.collector. Today that is BackFiller's test project.
on:
workflow_dispatch:
permissions:
contents: read
actions: write
concurrency:
group: coverage-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
coverage:
name: Test and Code Coverage
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- name: Checkout
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Setup .NET SDK (repo pin)
uses: actions/setup-dotnet@v6
with:
global-json-file: global.json
- name: Restore solution
run: dotnet restore VectorNNTPD.slnx -p:Platform=x64
- name: Build solution
run: dotnet build VectorNNTPD.slnx --configuration Release -p:Platform=x64 --no-restore
- name: Test solution with coverage where the collector is already referenced
timeout-minutes: 25
shell: bash
run: |
set -euo pipefail
failed=0
while IFS= read -r proj; do
if ! grep -q '<IsTestProject>true</IsTestProject>' "$proj"; then
continue
fi
name="$(basename "$proj" .csproj)"
echo "Testing $name"
if grep -q 'coverlet.collector' "$proj"; then
if ! dotnet test "$proj" \
--configuration Release \
-p:Platform=x64 \
--no-build \
--no-restore \
--collect:"XPlat Code Coverage" \
--results-directory ./TestResults \
--logger "trx;LogFileName=${name}.trx"; then
echo "Tests failed: $name"
failed=1
fi
else
if ! dotnet test "$proj" \
--configuration Release \
-p:Platform=x64 \
--no-build \
--no-restore \
--results-directory ./TestResults \
--logger "trx;LogFileName=${name}.trx"; then
echo "Tests failed: $name"
failed=1
fi
fi
done < <(find src tests -name '*.csproj' | sort)
exit "$failed"
- name: Verify every test project reported results
if: always()
shell: bash
run: |
set -euo pipefail
test_count=0
coverlet_count=0
while IFS= read -r proj; do
if grep -q '<IsTestProject>true</IsTestProject>' "$proj"; then
test_count=$((test_count + 1))
if grep -q 'coverlet.collector' "$proj"; then
coverlet_count=$((coverlet_count + 1))
fi
fi
done < <(find src tests -name '*.csproj' | sort)
trx_count=0
cov_count=0
if [ -d TestResults ]; then
trx_count="$(find TestResults -name '*.trx' | wc -l | tr -d '[:space:]')"
cov_count="$(find TestResults -name 'coverage.cobertura.xml' | wc -l | tr -d '[:space:]')"
fi
echo "test projects=$test_count coverlet projects=$coverlet_count trx=$trx_count coverage=$cov_count"
if [ "$trx_count" -lt "$test_count" ]; then
echo "Expected at least one TRX file per test project."
exit 1
fi
if [ "$coverlet_count" -eq 0 ]; then
echo "No test project references coverlet.collector, so coverage cannot be collected."
exit 1
fi
if [ "$cov_count" -lt "$coverlet_count" ]; then
echo "Expected at least one Cobertura file per test project that references coverlet.collector."
exit 1
fi
- name: Generate coverage report
if: always()
shell: bash
run: |
set -euo pipefail
dotnet tool install --global dotnet-reportgenerator-globaltool
reportgenerator \
"-reports:TestResults/**/coverage.cobertura.xml" \
"-targetdir:TestResults/CoverageReport" \
"-reporttypes:Html;Cobertura;TextSummary"
- name: Add coverage summary
if: always()
shell: bash
run: |
set -euo pipefail
if [[ ! -f TestResults/CoverageReport/Summary.txt ]]; then
echo "Coverage summary was not produced."
exit 1
fi
cat TestResults/CoverageReport/Summary.txt
{
echo "## Code Coverage"
echo
echo '```text'
cat TestResults/CoverageReport/Summary.txt
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v7
with:
name: code-coverage-report
path: TestResults/CoverageReport/
if-no-files-found: error
retention-days: 14
- name: Upload test results
if: always()
uses: actions/upload-artifact@v7
with:
name: test-results
path: TestResults/**/*.trx
if-no-files-found: error
retention-days: 14