Skip to content

Commit 6de1d93

Browse files
authored
Add coverage report (#857)
* Add GitHub Actions workflow for code coverage reporting This commit introduces a new workflow in the GitHub Actions configuration to automate code coverage reporting for pull requests. The workflow includes steps for setting up the JDK, caching dependencies, running tests with coverage, and conditionally adding coverage reports to pull requests based on coverage checks. It also allows for coverage overrides through PR comments, ensuring flexibility in coverage enforcement. * Update GitHub Actions workflow to include permissions for pull requests and issues This commit enhances the existing code coverage workflow by adding specific permissions for reading contents, and writing to pull requests and issues. These changes aim to improve the workflow's functionality and ensure proper access control during automated processes. * Update coverage report workflow to use COVERAGE_TOKEN and set minimum coverage thresholds This commit modifies the GitHub Actions workflow for code coverage reporting by replacing the GITHUB_TOKEN with COVERAGE_TOKEN for authentication. Additionally, it sets the minimum overall coverage requirement to 85% for both the main report and the skipped report, enhancing the enforcement of coverage standards. * debug * Refactor coverage report workflow to use GITHUB_TOKEN for authentication This commit updates the GitHub Actions workflow for code coverage reporting by changing the authentication method from COVERAGE_TOKEN to GITHUB_TOKEN. Additionally, it modifies the event trigger from pull_request to pull_request_target, streamlining the workflow and enhancing security by utilizing the appropriate token for the context. * add ref and repo
1 parent b9df4a3 commit 6de1d93

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Code Coverage
2+
3+
permissions:
4+
contents: read
5+
pull-requests: write
6+
issues: write
7+
8+
on:
9+
pull_request_target:
10+
11+
jobs:
12+
coverage:
13+
runs-on:
14+
group: databricks-protected-runner-group
15+
labels: linux-ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0 # Needed for coverage comparison
21+
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
22+
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
23+
24+
- name: Set up JDK
25+
uses: actions/setup-java@v4
26+
with:
27+
java-version: '21'
28+
distribution: 'adopt'
29+
30+
- name: Cache dependencies
31+
uses: actions/cache@v4
32+
with:
33+
path: ~/.m2
34+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
35+
restore-keys: |
36+
${{ runner.os }}-m2-
37+
38+
- name: Run tests with coverage
39+
run: mvn clean test jacoco:report
40+
41+
- name: Check for coverage override
42+
id: override
43+
run: |
44+
OVERRIDE_COMMENT=$(echo "${{ github.event.pull_request.body }}" | grep -E "SKIP_COVERAGE_CHECK\s*=" || echo "")
45+
if [ -n "$OVERRIDE_COMMENT" ]; then
46+
echo "override=true" >> $GITHUB_OUTPUT
47+
REASON=$(echo "$OVERRIDE_COMMENT" | sed -E 's/.*SKIP_COVERAGE_CHECK\s*=\s*(.+)/\1/')
48+
echo "reason=$REASON" >> $GITHUB_OUTPUT
49+
echo "Coverage override found in PR description: $REASON"
50+
else
51+
echo "override=false" >> $GITHUB_OUTPUT
52+
echo "No coverage override found"
53+
fi
54+
55+
- name: Add coverage to PR (with strict checks)
56+
if: steps.override.outputs.override == 'false'
57+
id: jacoco
58+
uses: madrapps/[email protected]
59+
with:
60+
paths: |
61+
${{ github.workspace }}/target/site/jacoco/jacoco.xml
62+
token: ${{ secrets.GITHUB_TOKEN }}
63+
min-coverage-overall: 85
64+
title: '📊 Code Coverage Report'
65+
update-comment: true
66+
pass-emoji: ':green_circle:'
67+
fail-emoji: ':red_circle:'
68+
69+
- name: Add coverage to PR (with override)
70+
if: steps.override.outputs.override == 'true'
71+
id: jacoco-override
72+
uses: madrapps/[email protected]
73+
with:
74+
paths: |
75+
${{ github.workspace }}/target/site/jacoco/jacoco.xml
76+
token: ${{ secrets.GITHUB_TOKEN }}
77+
min-coverage-overall: 85
78+
min-coverage-changed-files: 0
79+
title: '📊 Code Coverage Report (SKIPPED: ${{ steps.override.outputs.reason }})'
80+
update-comment: true
81+
pass-emoji: ':green_circle:'
82+
fail-emoji: ':red_circle:'
83+
84+
- name: Coverage enforcement summary
85+
run: |
86+
if [ "${{ steps.override.outputs.override }}" == "true" ]; then
87+
echo "⚠️ Coverage checks bypassed: ${{ steps.override.outputs.reason }}"
88+
echo "Please ensure this override is justified and temporary"
89+
else
90+
echo "✅ Coverage checks enforced - minimum 85% required"
91+
fi

0 commit comments

Comments
 (0)