Skip to content

Commit

Permalink
add github workflow for test coverage report check and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
1fanwang committed Sep 16, 2024
1 parent 60c29e0 commit 5896141
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/test-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Test and Coverage

on:
pull_request:
branches:
- '**'

jobs:
test-and-coverage:
runs-on: ubuntu-latest

steps:
- name: 1. Check out code
uses: actions/checkout@v2
with:
fetch-depth: '0'

- name: 2. Set up Java
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: 3. Build and Test with Coverage
run: ./gradlew clean build jacocoRootReport --no-daemon

- name: 4. Upload JaCoCo Report
uses: actions/upload-artifact@v4
with:
name: jacoco-report
path: build/reports/jacoco/test/jacocoTestReport.xml

- name: 5. Parse Coverage Results
id: coverage
run: |
thresholds=$(grep -oP '(?<=<counter type="INSTRUCTION" missed="\d+" covered=")\d+(?=")' build/reports/jacoco/test/jacocoTestReport.xml)
echo "THRESHOLDS=$thresholds" >> $GITHUB_ENV
violations=0
for module in coral-common coral-coralservice coral-hive coral-spark coral-trino coral-schema coral-pig coral-incremental coral-spark-plan coral-visualization; do
coverage=$(grep -A 1 "<package name=\"$module\"" build/reports/jacoco/test/jacocoTestReport.xml | tail -1 | awk '{print $3}')
threshold=$(grep "$module" <<< "$THRESHOLDS" | awk '{print $2}')
if [[ "$coverage" -lt "$threshold" ]]; then
violations=$((violations + 1))
echo "$module did not meet coverage requirement: $coverage (required: $threshold)"
else
echo "$module met coverage requirement: $coverage (required: $threshold)"
fi
done
echo "VIOLATIONS=$violations" >> $GITHUB_ENV
- name: 6. Post PR Comment with Coverage Report
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
token: ${{ secrets.GITHUB_TOKEN }}
header: "JaCoCo Test Coverage Report"
message: |
## Coverage Status by Module:
{{ steps.coverage.outputs }}
${{ env.VIOLATIONS }} modules failed to meet coverage thresholds.
- name: 7. Fail if Coverage Violations Exist
if: env.VIOLATIONS != 0
run: exit 1

0 comments on commit 5896141

Please sign in to comment.