@@ -82,28 +82,17 @@ jobs:
8282 - name : Generate coverage summary for PR comparison
8383 if : github.event_name == 'pull_request'
8484 run : |
85- # Merge LCOV files for summary
86- cat coverage-raw/*.info > coverage-raw/pr-combined.info
87-
88- # Generate JSON summary for comparison
89- cargo tarpaulin \
85+ # Extract PR coverage percentage using the same method as main branch
86+ PR_COVERAGE=$(cargo tarpaulin \
9087 --package oo7 \
9188 --lib \
9289 --no-default-features \
9390 --features "tracing,tokio,native_crypto" \
9491 --ignore-panics \
95- --out Json \
96- --output-dir coverage-raw \
97- --skip-clean
98-
99- # Extract coverage percentage
100- python3 -c "
101- import json
102- with open('coverage-raw/tarpaulin-report.json', 'r') as f:
103- data = json.load(f)
104- coverage = data['files'][''] # This might need adjustment based on actual structure
105- print(f'PR_COVERAGE={coverage:.2f}')
106- " >> $GITHUB_ENV || echo "PR_COVERAGE=0.00" >> $GITHUB_ENV
92+ --skip-clean 2>&1 | grep "% coverage" | grep -o '[0-9]\+\.[0-9]\+' | head -1 || echo "0.00")
93+
94+ echo "PR_COVERAGE=$PR_COVERAGE" >> $GITHUB_ENV
95+ echo "PR coverage: $PR_COVERAGE%"
10796
10897 - name : Install grcov for merging coverage
10998 uses : taiki-e/install-action@v2
@@ -157,10 +146,50 @@ jobs:
157146
158147 - name : Get main branch coverage for comparison
159148 if : github.event_name == 'pull_request'
149+ uses : actions/github-script@v7
150+ with :
151+ script : |
152+ // Find the latest successful coverage run on main that has the baseline artifact
153+ const { data: runs } = await github.rest.actions.listWorkflowRuns({
154+ owner: context.repo.owner,
155+ repo: context.repo.repo,
156+ workflow_id: 'coverage.yml',
157+ status: 'completed',
158+ conclusion: 'success',
159+ branch: 'main',
160+ per_page: 10
161+ });
162+
163+ for (const run of runs.workflow_runs) {
164+ try {
165+ const { data: artifacts } = await github.rest.actions.listWorkflowRunArtifacts({
166+ owner: context.repo.owner,
167+ repo: context.repo.repo,
168+ run_id: run.id
169+ });
170+
171+ const baselineArtifact = artifacts.artifacts.find(a => a.name === 'coverage-baseline');
172+ if (baselineArtifact) {
173+ core.exportVariable('BASELINE_RUN_ID', run.id.toString());
174+ console.log(`Found baseline artifact in run ${run.id}`);
175+ return;
176+ }
177+ } catch (error) {
178+ console.log(`Error checking run ${run.id}: ${error.message}`);
179+ }
180+ }
181+
182+ console.log('No baseline artifact found in recent main branch runs');
183+ core.exportVariable('BASELINE_RUN_ID', '');
184+
185+ - name : Download baseline artifact
186+ if : github.event_name == 'pull_request' && env.BASELINE_RUN_ID != ''
160187 uses : actions/download-artifact@v4
161188 with :
162189 name : coverage-baseline
163190 path : coverage-baseline/
191+ github-token : ${{ secrets.GITHUB_TOKEN }}
192+ run-id : ${{ env.BASELINE_RUN_ID }}
164193 continue-on-error : true
165194
166195 - name : Set main coverage for comparison
0 commit comments