Skip to content

Commit eae6509

Browse files
authored
AAP-56029 Collect test coverage from everything in the matrix (#865)
## Description Collect coverage from all jobs in the tox / test matrix. ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update - [x] Test update - [ ] Refactoring (no functional changes) - [ ] Development environment change - [ ] Configuration change ## Self-Review Checklist - [ ] I have performed a self-review of my code - [ ] I have added relevant comments to complex code sections - [ ] I have updated documentation where needed - [ ] I have considered the security impact of these changes - [ ] I have considered performance implications - [ ] I have thought about error handling and edge cases - [ ] I have tested the changes in my local environment ## Testing Instructions This, itself, modifies testing. Not even testing, collection of coverage of tests. Not even changing whether coverage is collected, but how thoroughly coverage is collected, making it more thorough. ### Prerequisites none ### Steps to Test This is _about_ testing. ### Expected Results coverage for entire matrix collected ## Additional Context Created because it came up in #855, and separated out because that is a highly-blocking issue that we should not scope creep. ### Required Actions - [ ] Requires documentation updates - [ ] Requires downstream repository changes - [ ] Requires infrastructure/deployment changes - [ ] Requires coordination with other teams - [ ] Blocked by PR/MR: #XXX ### Screenshots/Logs See results of CI for this PR <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Collects coverage from all tox matrix jobs, uploads per-env artifacts, aggregates them in Sonar workflows, and passes coverage paths to SonarCloud for PR and branch analyses. > > - **CI (`.github/workflows/ci.yml`)**: > - Inject PR number into `coverage.xml` only when `matrix.tests.env != 'check'` and file exists. > - Upload coverage artifact per env as `coverage-${{ matrix.tests.env }}` (instead of single `coverage`). > - **SonarCloud (`.github/workflows/sonar-pr.yml`)**: > - Download all coverage artifacts with pattern `coverage-*` for both PR and branch analyses. > - Discover all `coverage.xml` files, set `COVERAGE_PATHS`, and validate presence for PR analysis. > - Extract PR number from the first discovered `coverage.xml`. > - Pass `-Dsonar.python.coverage.reportPaths=${{ env.COVERAGE_PATHS }}` to SonarCloud (conditionally for branch analysis). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit f7baba0. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent ddb69a1 commit eae6509

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

β€Ž.github/workflows/ci.ymlβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ jobs:
5656
tox --colored yes -e ${{ matrix.tests.env }}
5757
5858
- name: Inject PR number into coverage.xml
59-
if: matrix.tests.sonar
59+
if: matrix.tests.env != 'check' && hashFiles('coverage.xml') != ''
6060
run: sed -i '2i <!-- PR ${{ github.event.number }} -->' coverage.xml
6161

6262
- name: Upload coverage as artifact
6363
uses: actions/upload-artifact@v4
64-
if: matrix.tests.sonar
64+
if: matrix.tests.env != 'check' && hashFiles('coverage.xml') != ''
6565
with:
66-
name: coverage
66+
name: coverage-${{ matrix.tests.env }}
6767
path: coverage.xml
6868

6969
- name: Upload jUnit XML test results

β€Ž.github/workflows/sonar-pr.ymlβ€Ž

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ jobs:
4444
with:
4545
show-progress: false
4646

47-
# Download coverage artifact from CI workflow
48-
- name: Download coverage artifact
47+
# Download all individual coverage artifacts from CI workflow
48+
- name: Download coverage artifacts
4949
uses: dawidd6/action-download-artifact@246dbf436b23d7c49e21a7ab8204ca9ecd1fe615
5050
with:
5151
github_token: ${{ secrets.GITHUB_TOKEN }}
5252
workflow: CI
5353
run_id: ${{ github.event.workflow_run.id }}
54-
name: coverage
54+
pattern: coverage-*
5555

5656
# Extract PR metadata from workflow_run event
5757
- name: Set PR metadata and prepare for analysis
@@ -61,14 +61,20 @@ jobs:
6161
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
6262
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6363
run: |
64+
# Find all downloaded coverage XML files (artifacts are extracted into subdirectories)
65+
coverage_files=$(find ./coverage-* -name "coverage.xml" -type f 2>/dev/null | tr '\n' ',' | sed 's/,$//')
66+
echo "Found coverage files: $coverage_files"
67+
echo "COVERAGE_PATHS=$coverage_files" >> $GITHUB_ENV
68+
6469
echo "πŸ” SonarCloud Analysis Decision Summary"
6570
echo "========================================"
6671
echo "β”œβ”€β”€ CI Event: βœ… Pull Request"
6772
echo "β”œβ”€β”€ Repo: $REPO_NAME"
6873
69-
# Extract PR number from coverage.xml
70-
if [ -f coverage.xml ]; then
71-
PR_NUMBER=$(grep -m 1 '<!-- PR' coverage.xml | awk '{print $3}' || echo "")
74+
# Extract PR number from first coverage.xml file found
75+
first_coverage=$(find ./coverage-* -name "coverage.xml" -type f 2>/dev/null | head -1)
76+
if [ -f "$first_coverage" ]; then
77+
PR_NUMBER=$(grep -m 1 '<!-- PR' "$first_coverage" | awk '{print $3}' || echo "")
7278
else
7379
PR_NUMBER=""
7480
fi
@@ -93,6 +99,14 @@ jobs:
9399
echo "β”œβ”€β”€ Coverage Data: βœ… Available"
94100
echo "└── Result: βœ… Running SonarCloud PR analysis"
95101
102+
# Validate coverage paths
103+
if [ -z "$coverage_files" ]; then
104+
echo "##[error]❌ FATAL: No coverage files found"
105+
echo "##[error]This job requires coverage data to run analysis."
106+
echo "##[error]The CI workflow should have uploaded coverage artifacts."
107+
exit 1
108+
fi
109+
96110
# Export to GitHub env for later steps
97111
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
98112
echo "PR_BASE=$PR_BASE" >> $GITHUB_ENV
@@ -118,6 +132,7 @@ jobs:
118132
-Dsonar.pullrequest.key=${{ env.PR_NUMBER }}
119133
-Dsonar.pullrequest.branch=${{ env.PR_HEAD }}
120134
-Dsonar.pullrequest.base=${{ env.PR_BASE }}
135+
-Dsonar.python.coverage.reportPaths=${{ env.COVERAGE_PATHS }}
121136
122137
sonar-branch-analysis:
123138
name: SonarCloud Branch Analysis
@@ -132,33 +147,39 @@ jobs:
132147
with:
133148
show-progress: false
134149

135-
# Download coverage artifact from CI workflow (optional for branch pushes)
136-
- name: Download coverage artifact
150+
# Download all individual coverage artifacts from CI workflow (optional for branch pushes)
151+
- name: Download coverage artifacts
137152
continue-on-error: true
138153
uses: dawidd6/action-download-artifact@246dbf436b23d7c49e21a7ab8204ca9ecd1fe615
139154
with:
140155
github_token: ${{ secrets.GITHUB_TOKEN }}
141156
workflow: CI
142157
run_id: ${{ github.event.workflow_run.id }}
143-
name: coverage
158+
pattern: coverage-*
144159

145160
- name: Print SonarCloud Analysis Summary
146161
env:
147162
BRANCH_NAME: ${{ github.event.workflow_run.head_branch }}
148163
REPO_NAME: ${{ github.event.repository.full_name }}
149164
run: |
165+
# Find all downloaded coverage XML files (artifacts are extracted into subdirectories)
166+
coverage_files=$(find ./coverage-* -name "coverage.xml" -type f 2>/dev/null | tr '\n' ',' | sed 's/,$//')
167+
echo "Found coverage files: $coverage_files"
168+
echo "COVERAGE_PATHS=$coverage_files" >> $GITHUB_ENV
169+
150170
echo "πŸ” SonarCloud Analysis Summary"
151171
echo "=============================="
152172
echo "β”œβ”€β”€ CI Event: βœ… Push (via workflow_run)"
153173
echo "β”œβ”€β”€ Repo: $REPO_NAME"
154174
echo "β”œβ”€β”€ Branch: $BRANCH_NAME"
155-
156-
if [ -f coverage.xml ]; then
175+
echo "β”œβ”€β”€ Coverage Files: ${coverage_files:-none}"
176+
177+
if [ -n "$coverage_files" ]; then
157178
echo "β”œβ”€β”€ Coverage Data: βœ… Available"
158179
else
159180
echo "β”œβ”€β”€ Coverage Data: ⚠️ Not available (analysis will proceed without coverage)"
160181
fi
161-
182+
162183
echo "└── Result: βœ… Running SonarCloud branch analysis"
163184
164185
- name: SonarCloud Scan
@@ -170,3 +191,4 @@ jobs:
170191
args: >
171192
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
172193
-Dsonar.branch.name=${{ github.event.workflow_run.head_branch }}
194+
${{ env.COVERAGE_PATHS && format('-Dsonar.python.coverage.reportPaths={0}', env.COVERAGE_PATHS) || '' }}

0 commit comments

Comments
Β (0)