-
Notifications
You must be signed in to change notification settings - Fork 187
64 lines (54 loc) · 2.23 KB
/
test-coverage.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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@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