Add unit test coverage report and enforcement #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v2 | |
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 |