-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (62 loc) · 2.15 KB
/
dotnet-ci.yml
File metadata and controls
74 lines (62 loc) · 2.15 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
name: .NET CI with Code Coverage
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build-and-test:
runs-on: ubuntu-latest
permissions:
contents: read
checks: write
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release
- name: Test
run: dotnet test --no-build --configuration Release --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./TestResults
- name: Upload coverage reports to Codecov
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v5
with:
directory: ./TestResults
fail_ci_if_error: false
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Generate Coverage Report
uses: danielpalme/ReportGenerator-GitHub-Action@5.4.2
with:
reports: 'TestResults/**/coverage.cobertura.xml'
targetdir: 'TestResults/CoverageReport'
reporttypes: 'Html;TextSummary;Cobertura;Badges'
- name: Display Coverage Summary
run: |
echo "## Code Coverage Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
cat TestResults/CoverageReport/Summary.txt >> $GITHUB_STEP_SUMMARY
- name: Upload Coverage Report as Artifact
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-report
path: TestResults/CoverageReport
retention-days: 30
- name: Check Coverage Threshold
run: |
COVERAGE=$(grep -oP 'Line coverage: \K[0-9.]+' TestResults/CoverageReport/Summary.txt)
echo "Current coverage: $COVERAGE%"
THRESHOLD=70.0
if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then
echo "❌ Coverage ($COVERAGE%) is below threshold ($THRESHOLD%)"
exit 1
else
echo "✅ Coverage ($COVERAGE%) meets threshold ($THRESHOLD%)"
fi