Skip to content

Commit f4563d5

Browse files
authored
Enhance CI workflow: Add module tests, coverage reports, and improve … (#69)
* Enhance CI workflow: Add module tests, coverage reports, and improve test result handling * Test
1 parent 35e6174 commit f4563d5

File tree

1 file changed

+90
-4
lines changed

1 file changed

+90
-4
lines changed

.github/workflows/dotnet.yml

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
name: .NET
22

33
on:
4+
workflow_dispatch:
45
pull_request:
56
branches:
67
- 'main'
78
- 'develop'
9+
- 'release/**'
10+
- 'hotfix/**'
811
push:
912
branches:
1013
- 'main'
1114
- 'develop'
15+
- 'release/**'
16+
- 'hotfix/**'
1217

1318
permissions:
1419
contents: read
@@ -17,6 +22,7 @@ env:
1722
BUILD_CONFIGURATION: "Release"
1823
SOLUTION_PATH: source/AAS.TwinEngine.DataEngine.sln
1924
TEST_PROJECT: source/AAS.TwinEngine.DataEngine.UnitTests/AAS.TwinEngine.DataEngine.UnitTests.csproj
25+
MODULE_TEST_PROJECT: source/AAS.TwinEngine.DataEngine.ModuleTests/AAS.TwinEngine.DataEngine.ModuleTests.csproj
2026

2127
jobs:
2228

@@ -25,6 +31,7 @@ jobs:
2531
runs-on: ubuntu-latest
2632

2733
permissions:
34+
contents: read
2835
checks: write
2936
pull-requests: write
3037

@@ -44,12 +51,91 @@ jobs:
4451
run: dotnet build ${{ env.SOLUTION_PATH }} --configuration ${{ env.BUILD_CONFIGURATION }} --no-restore
4552

4653
- name: Run Unit Tests
47-
run: dotnet test ${{ env.TEST_PROJECT }} --configuration Release --no-build --logger "trx;LogFileName=test_results.trx"
54+
run: dotnet test ${{ env.TEST_PROJECT }} --configuration Release --no-build --logger "trx;LogFileName=unit_test_results.trx" --collect:"XPlat Code Coverage" --settings source/coverlet.runsettings
55+
56+
# - name: Run Module Tests
57+
# run: dotnet test ${{ env.MODULE_TEST_PROJECT }} --configuration Release --no-build --logger "trx;LogFileName=module_test_results.trx" --collect:"XPlat Code Coverage" --settings source/coverlet.runsettings
4858

49-
# https://github.com/dorny/test-reporter
5059
- name: Publish Test Results
5160
uses: dorny/test-reporter@fe45e9537387dac839af0d33ba56eed8e24189e8 # v2.3.0
61+
id: test-results
62+
if: github.event.pull_request.head.repo.fork == false
5263
with:
53-
name: Unit Tests
54-
path: "**/test_results.trx"
64+
name: Test Results (Unit & Module)
65+
path: "**/*_test_results.trx"
5566
reporter: dotnet-trx
67+
68+
- name: Combine Reports (Test Results)
69+
if: github.event.pull_request.head.repo.fork == false
70+
run: |
71+
echo "# Test & Coverage Report" > results.md
72+
echo "" >> results.md
73+
echo "## Test Results Summary" >> results.md
74+
echo "" >> results.md
75+
echo "| Metric | Count |" >> results.md
76+
echo "|--------|-------|" >> results.md
77+
echo "| ✅ Passed | ${{ steps.test-results.outputs.passed }} |" >> results.md
78+
echo "| ❌ Failed | ${{ steps.test-results.outputs.failed }} |" >> results.md
79+
echo "| ⏭️ Skipped | ${{ steps.test-results.outputs.skipped }} |" >> results.md
80+
echo "" >> results.md
81+
echo "[View Detailed Test Results](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> results.md
82+
echo "" >> results.md
83+
echo "---" >> results.md
84+
echo "" >> results.md
85+
86+
- name: Code Coverage Report - Unit Tests
87+
if: github.event.pull_request.head.repo.fork == false
88+
uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0
89+
with:
90+
filename: "source/AAS.TwinEngine.DataEngine.UnitTests/TestResults/*/coverage.cobertura.xml"
91+
badge: false
92+
fail_below_min: true
93+
format: markdown
94+
hide_branch_rate: false
95+
hide_complexity: false
96+
indicators: true
97+
output: both
98+
thresholds: "80 80"
99+
100+
- name: Combine Reports (Unit Test Coverage Results)
101+
if: github.event.pull_request.head.repo.fork == false
102+
run: |
103+
echo "## Code Coverage" >> results.md
104+
echo "" >> results.md
105+
echo "### Unit Tests Coverage" >> results.md
106+
cat code-coverage-results.md >> results.md
107+
echo "" >> results.md
108+
109+
- name: Code Coverage Report - Module Tests
110+
if: github.event.pull_request.head.repo.fork == false
111+
uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0
112+
with:
113+
filename: "source/AAS.TwinEngine.DataEngine.ModuleTests/TestResults/*/coverage.cobertura.xml"
114+
badge: false
115+
fail_below_min: false
116+
format: markdown
117+
hide_branch_rate: false
118+
hide_complexity: false
119+
indicators: true
120+
output: both
121+
122+
- name: Combine Reports (Module Test Coverage Results)
123+
if: github.event.pull_request.head.repo.fork == false
124+
run: |
125+
echo "### Module Tests Coverage" >> results.md
126+
cat code-coverage-results.md >> results.md
127+
128+
129+
- name: Add PR Comment
130+
if: github.event.pull_request.head.repo.fork == false
131+
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 # v2.9.0
132+
with:
133+
recreate: true
134+
path: results.md
135+
136+
- name: Upload TRX as artifact (Fork PR fallback)
137+
if: github.event.pull_request.head.repo.fork == true
138+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
139+
with:
140+
name: test-results
141+
path: "**/*_test_results.trx"

0 commit comments

Comments
 (0)