Skip to content

Commit 54af02c

Browse files
ncipollinaclaude
andauthored
Add code coverage (#8)
* Add code coverage support to PR build workflow - Add coverageThreshold and coverageReportFormats input parameters - Enhance test step to collect XPlat Code Coverage data - Integrate Codecov for coverage report uploads - Add CodeCoverageSummary action for markdown reports with badges - Include sticky PR comments for coverage visibility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove Codecov upload step from coverage workflow - Remove codecov/codecov-action@v4 step that required token - Keep GitHub-native coverage summary and PR comments - Simplifies workflow by removing external dependency 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add test reporting and artifact upload for coverage - Add dorny/test-reporter for GitHub-native test result display - Keep artifact upload as backup coverage report access - Replace problematic PR comment approach with better alternatives 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove problematic test reporter step - Remove dorny/test-reporter that also had permission issues - Keep only coverage summary and artifact upload - Simplify workflow to avoid GitHub permission problems 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Make code coverage optional based on threshold value - Add separate test step for when coverage is disabled (threshold = 0) - Update coverage-related steps to only run when threshold > 0 - Allows projects to run tests without coverage overhead when not needed 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent aa38ed3 commit 54af02c

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

.github/workflows/pr-build.yaml

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ on:
5757
required: false
5858
default: false
5959
type: boolean
60+
coverageThreshold:
61+
description: "Minimum code coverage percentage required"
62+
required: false
63+
default: 0
64+
type: number
65+
coverageReportFormats:
66+
description: "Coverage report formats (cobertura, opencover, lcov)"
67+
required: false
68+
default: "cobertura"
69+
type: string
6070
runCdk: # ✅ New input to control CDK execution
6171
description: "Determines if AWS CDK steps should be run"
6272
required: false
@@ -98,8 +108,42 @@ jobs:
98108
run: dotnet build --configuration Release --no-restore
99109

100110
- name: Test Code
101-
if: inputs.hasTests == true # ✅ Run only if hasTests is set to true
102-
run: dotnet test --no-restore
111+
if: inputs.hasTests == true && inputs.coverageThreshold == 0
112+
run: dotnet test --no-restore --configuration Release
113+
114+
- name: Test Code with Coverage
115+
if: inputs.hasTests == true && inputs.coverageThreshold > 0
116+
run: |
117+
dotnet test --no-restore \
118+
--collect:"XPlat Code Coverage" \
119+
--results-directory ./coverage \
120+
--logger trx \
121+
--configuration Release \
122+
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=${{ inputs.coverageReportFormats }}
123+
124+
- name: Code Coverage Summary
125+
if: inputs.hasTests == true && inputs.coverageThreshold > 0
126+
uses: irongut/CodeCoverageSummary@v1.3.0
127+
with:
128+
filename: coverage/**/coverage.cobertura.xml
129+
badge: true
130+
fail_below_min: ${{ inputs.coverageThreshold > 0 }}
131+
format: markdown
132+
hide_branch_rate: false
133+
hide_complexity: true
134+
indicators: true
135+
output: both
136+
thresholds: '${{ inputs.coverageThreshold }} 80'
137+
138+
- name: Upload Coverage Report as Artifact
139+
if: inputs.hasTests == true && inputs.coverageThreshold > 0
140+
uses: actions/upload-artifact@v4
141+
with:
142+
name: coverage-report
143+
path: |
144+
./coverage/**/*
145+
code-coverage-results.md
146+
retention-days: 30
103147

104148
- name: Setup Local .NET Tools
105149
if: inputs.functions != '[]'

0 commit comments

Comments
 (0)