-
Notifications
You must be signed in to change notification settings - Fork 4
205 lines (174 loc) · 8.17 KB
/
build-and-test-RES.Configuration.yml
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
name: Build And Test RES.Configuration
on:
push:
branches:
- "master"
paths-ignore:
- '**.md'
pull_request:
workflow_dispatch:
env:
APP_NAME: RES.Configuration
REPO_NAME: configuration
jobs:
Build_And_Test:
name: Build And Test
runs-on: windows-2019
steps:
- name: Checkout PR merged with Master
uses: actions/checkout@v3
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
with:
ref: refs/pull/${{ github.event.number }}/merge
- name: Checkout Master
uses: actions/checkout@v3
if: github.event_name != 'pull_request' && github.event_name != 'pull_request_target'
- name: Setup Node.js
uses: actions/setup-node@v3 # Needed for making badges
with:
node-version: '20.x'
- name: Install Dependencies # Needed for making badges
run: |
npm install badge-maker
- name: Use .NET Core SDK 5.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: 5.0.x
- name: Install OpenCover
run: choco install opencover.portable
- name: Install nunit-console
run: |
msiexec /i D:\a\configuration\configuration\NUnit.Console-3.15.4.msi /qn /norestart
- name: Restore RES.Configuration
run: dotnet restore RES.Configuration.sln
- name: Build RES.Configuration
run: dotnet build RES.Configuration.sln --configuration Release --no-restore
- name: Run OpenCover
shell: cmd
run: |
C:\ProgramData\chocolatey\lib\opencover.portable\tools\OpenCover.Console.exe -register:Path64 -target:"C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" -targetargs:"${{ github.workspace }}\BuiltDlls\Release\RES.Configuration.Test.dll" -output:"coverage.xml" -returntargetcode -filter:"+[RES.Configuration.Test]*" -oldStyle -register:user
# C:\ProgramData\chocolatey\lib\opencover.portable\tools\\OpenCover.Console.exe -register:Path64 -target:"C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" -targetargs:"${{ github.workspace }}\BuiltDlls\Release\RES.Configuration.Test.dll" -output:"coverage.xml" -returntargetcode -filter:"+[RES.Configuration]* -[RES.Configuration.Test]*" -oldStyle -register:user
- name: Create Test Result Summary in Markdown Format
id: get_test_results
shell: pwsh
run: |
$XMLPath = 'TestResult.xml'
$xml = [xml](Get-Content $XMLPath)
$test_run = $xml.SelectNodes('//test-run')
$total_tests = $test_run.total
$passed = $test_run.passed
$failed = $test_run.failed
$warnings = $test_run.warnings
$inconclusive = $test_run.inconclusive
$skipped = $test_run.skipped
$duration = $test_run.duration
$duration = [Math]::Round($duration, 2, [MidpointRounding]::ToEven)
echo "passed=$passed" >> $env:GITHUB_OUTPUT
echo "total_tests=$total_tests" >> $env:GITHUB_OUTPUT
'# Test Report<br>' | Out-File '${{ env.APP_NAME }}-test-results.md'
'## Summary<br>'| Out-File '${{ env.APP_NAME }}-test-results.md' -Append
$total_tests + ' tests ran in ' + $duration + ' seconds.<br>' | Out-File '${{ env.APP_NAME }}-test-results.md' -Append
'- ' + $passed + ' tests passed<br>' | Out-File '${{ env.APP_NAME }}-test-results.md' -Append
'- ' + $failed + ' tests failed<br>' | Out-File '${{ env.APP_NAME }}-test-results.md' -Append
'- ' + $skipped + ' tests skipped<br>' | Out-File '${{ env.APP_NAME }}-test-results.md' -Append
- name: Use ReportGenerator to Convert Code Coverage Results to Markdown Format
uses: danielpalme/[email protected]
with:
reports: coverage.xml
targetdir: ${{ github.workspace }}
reporttypes: MarkdownSummary
- name: Write Test and Coverage Results to Job Summary
shell: bash
run: |
mv Summary.md ${{ env.APP_NAME }}-coverage-results.md
cat ${{ env.APP_NAME }}-test-results.md >> $GITHUB_STEP_SUMMARY
echo "<br>#Code Coverage Report" >> $GITHUB_STEP_SUMMARY
cat ${{ env.APP_NAME }}-coverage-results.md >> $GITHUB_STEP_SUMMARY
- name: Extract code coverage %
id: get_coverage
shell: bash
run: |
coverage=`grep -o '**Line coverage:**[^"]*' ${{ env.APP_NAME }}-coverage-results.md`
echo $coverage
numbers=$(echo $coverage | tr -cd '[. [:digit:]]')
percent=$(echo $numbers | cut -f1 -d' ')
echo "percent=$percent" >> $GITHUB_OUTPUT
- name: Make Test Results and Code Coverage Badges
shell: pwsh
run: |
npm install -g badge-maker
badge "tests" ${{ steps.get_test_results.outputs.passed }}/${{ steps.get_test_results.outputs.total_tests }} "#4c1" "#555" > ${{ env.APP_NAME }}-test-badge.svg
if (${{ steps.get_coverage.outputs.percent }} -ge 80) {
$color="#4c1"
}elseif(${{ steps.get_coverage.outputs.percent }} -ge 50) {
$color="#dfb317"
}elseif(${{ steps.get_coverage.outputs.percent }} -ge 20) {
$color="#fe7d37"
}else{
$color="#f00"
}
badge "code coverage" "${{steps.get_coverage.outputs.percent}}%" "$color" "#555" > ${{ env.APP_NAME }}-coverage-badge.svg
- name: Upload Test and Coverage Reports and Badges to Artifacts
uses: actions/upload-artifact@v3
with:
name: reports-and-badges
path: |
${{ env.APP_NAME }}-test-results.md
${{ env.APP_NAME }}-coverage-results.md
${{ env.APP_NAME }}-test-badge.svg
${{ env.APP_NAME }}-coverage-badge.svg
- name: Create nuget package
run: |
dotnet pack RES.Configuration/RES.Configuration.csproj --configuration Release --no-restore --no-build --output ${{ github.workspace }}/artifacts
- name: Upload nuget package to Artifacts
uses: actions/upload-artifact@v3
with:
name: RES.Configuration
path: |
artifacts/*.nupkg
Upload_Reports_And_Badges_To_Repo_Wiki:
name: Upload Test and Code Coverage Reports and Badges to Repo Wiki
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' }}
needs: [ Build_And_Test ]
steps:
- name: Checkout Repo Wiki
uses: actions/checkout@v3
with:
repository: resgroup/${{ env.REPO_NAME }}.wiki
- name: Check If There is Existing Test Report
id: check_files
uses: andstor/file-existence-action@v2
with:
files: |
${{ env.APP_NAME }}-test-results.md
${{ env.APP_NAME }}-test-badge.svg
${{ env.APP_NAME }}-coverage-results.md
${{ env.APP_NAME }}-coverage-badge.svg
- name: If There are Existing Test Results and Badges, Delete Them and Sync Back With Wiki
if: steps.check_files.outputs.files_exists == 'true'
run: |
rm -f ${{ env.APP_NAME }}-test-results.md, ${{ env.APP_NAME }}-test-badge.svg, ${{ env.APP_NAME }}-coverage-results.md, ${{ env.APP_NAME }}-coverage-badge.svg
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "Add changes"
git push
- name: Download New Test and Coverage Reports and Badges From Artifacts
if: success() || failure()
uses: actions/download-artifact@v3
with:
path: ./
name: reports-and-badges
- name: Commit Changes (New Test and Coverage Reports and Badges) Back to Repo Wiki
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "Add changes"
git push
- name: Delete "reports-and-badges" from Artifacts - no longer needed
uses: GeekyEggo/[email protected]
with:
name: |
reports-and-badges