Skip to content

Commit 0a9c55f

Browse files
committed
Attempt 1 at adding comparisons
1 parent bf82040 commit 0a9c55f

2 files changed

Lines changed: 47 additions & 14 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Schema: https://json.schemastore.org/github-action.json
2+
# This action compares coverage on a PR against a baseline stored on a branch.
3+
# it against the current coverage.xml, posting a comparison comment on the PR.
4+
name: 'Coverage Diff'
5+
description: 'Compare PR coverage against a baseline branch and post a summary comment on the PR'
6+
inputs:
7+
baseline-branch:
8+
description: 'Branch containing the baseline coverage.xml'
9+
default: 'coverage-info'
10+
required: false
11+
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: Fetch baseline coverage
16+
id: fetch_baseline
17+
shell: bash
18+
run: |
19+
if git fetch origin ${{ inputs.baseline-branch }} 2>/dev/null; then
20+
git show origin/${{ inputs.baseline-branch }}:coverage.xml > /tmp/base-coverage.xml
21+
echo "baseline_found=true" >> $GITHUB_OUTPUT
22+
else
23+
echo "baseline_found=false" >> $GITHUB_OUTPUT
24+
echo "::warning:: Baseline branch '${{ inputs.baseline-branch }}' not found"
25+
fi
26+
27+
- name: Run coverage diff
28+
if: ${{ steps.fetch_baseline.outputs.baseline_found == 'true' }}
29+
shell: bash
30+
env:
31+
GH_TOKEN: ${{ github.token }}
32+
run: |
33+
pip install pycobertura --quiet
34+
DIFF_OUTPUT=$(pycobertura diff /tmp/base-coverage.xml coverage.xml --no-source --format markdown || true)
35+
COMMENT_BODY=$(cat <<EOF
36+
## 📊 Coverage Diff
37+
${DIFF_OUTPUT}
38+
Base: \`${{ inputs.baseline-branch }}\` · PR: \`${{ github.head_ref }}\`
39+
EOF
40+
)
41+
echo "$COMMENT_BODY" >> $GITHUB_STEP_SUMMARY
42+
echo "$COMMENT_BODY" > /tmp/coverage-comment.md
43+
gh pr comment ${{ github.event.pull_request.number }} --body-file /tmp/coverage-comment.md

.github/workflows/ci_workflow.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ jobs:
5252
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
5353
run: genbadge coverage -i coverage.xml -o coverage-badge.svg
5454

55-
<<<<<<< HEAD
5655
- name: Push badge to coverage-info branch
5756
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
5857
env:
@@ -78,18 +77,9 @@ jobs:
7877
7978
git commit -m "Update coverage badge [skip ci]"
8079
git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" coverage-info
81-
=======
82-
- name: Push badge and summary to coverage-info branch
83-
if: ${{ env.COVERAGE == 'true' && github.event_name != 'pull_request' }}
84-
uses: peaceiris/actions-gh-pages@v4
85-
with:
86-
github_token: ${{ secrets.GITHUB_TOKEN }}
87-
publish_branch: coverage-info
88-
publish_dir: .
89-
include_files: coverage-badge.svg, coverage.xml
90-
commit_message: "Update coverage badge [skip ci]"
9180
9281
- name: Coverage diff on PR
93-
if: ${{ env.COVERAGE == 'true' && github.event_name == 'pull_request' }}
94-
run: echo "TODO"
95-
>>>>>>> cd008e2 (Outline steps I think are necessary for coverage diffs)
82+
83+
if: ${{ env.COVERAGE == 'true' && github.event_name == 'pull_request' && github.base_ref == 'main'}}
84+
uses: ./.github/jobs/coverage_diff
85+

0 commit comments

Comments
 (0)