Skip to content

Commit 5149c0e

Browse files
RobinPicardrlouf
authored andcommitted
Run coverage check on target branch instead of always main
1 parent 832483a commit 5149c0e

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

.github/workflows/tests.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,30 @@ jobs:
8787
with:
8888
name: coverage-data
8989

90-
- name: Fetch main for coverage diff
90+
- name: Determine base branch for comparison
91+
id: base-branch
9192
run: |
92-
git fetch --no-tags --prune origin main
93+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
94+
# For PRs, use the remote tracking branch
95+
COMPARE_BRANCH="origin/${{ github.base_ref }}"
96+
echo "COMPARE_BRANCH=$COMPARE_BRANCH" >> $GITHUB_ENV
97+
else
98+
# For push events, compare against the parent commit
99+
COMPARE_BRANCH="${{ github.event.before }}"
100+
echo "COMPARE_BRANCH=$COMPARE_BRANCH" >> $GITHUB_ENV
101+
fi
102+
echo "Using $COMPARE_BRANCH for coverage comparison"
103+
104+
- name: Fetch base branch for coverage diff
105+
run: |
106+
git fetch --no-tags --prune origin ${COMPARE_BRANCH#origin/}
93107
94108
- name: Combine coverage & fail if it's <100%.
95109
run: |
96110
python -m coverage combine
97111
python -m coverage html --skip-covered --skip-empty
98112
python -m coverage xml
99-
diff-cover coverage.xml --markdown-report=coverage.md --fail-under=100 || (cat coverage.md >> $GITHUB_STEP_SUMMARY && exit 1)
113+
diff-cover coverage.xml --compare-branch=$COMPARE_BRANCH --markdown-report=coverage.md --fail-under=100 || (cat coverage.md >> $GITHUB_STEP_SUMMARY && exit 1)
100114
101115
- name: Upload HTML report if check failed.
102116
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)