|
8 | 8 | - master |
9 | 9 |
|
10 | 10 | jobs: |
11 | | - test-and-coverage: |
| 11 | + coverage: |
12 | 12 | runs-on: ubuntu-latest |
13 | | - permissions: |
14 | | - contents: read |
15 | | - pull-requests: write |
16 | 13 |
|
17 | 14 | steps: |
18 | | - - name: Checkout Repository |
| 15 | + - name: Checkout repository |
19 | 16 | uses: actions/checkout@v4 |
20 | 17 |
|
21 | | - - name: Set up JDK 8 (Temurin) |
| 18 | + - name: Set up JDK 9 |
22 | 19 | uses: actions/setup-java@v4 |
23 | 20 | with: |
24 | | - distribution: 'temurin' |
25 | | - java-version: '8' |
26 | | - cache: maven |
| 21 | + java-version: '9' |
| 22 | + distribution: 'zulu' |
27 | 23 |
|
28 | | - - name: Ensure Tests Are Enabled in pom.xml |
| 24 | + - name: Enable tests in pom.xml |
29 | 25 | run: | |
30 | | - echo "🔧 Temporarily enabling tests in pom.xml..." |
31 | | - if [[ "$OSTYPE" == "darwin"* ]]; then |
32 | | - sed -i '' 's/<skipTests>true<\/skipTests>/<skipTests>false<\/skipTests>/g' pom.xml || true |
33 | | - else |
34 | | - sed -i 's/<skipTests>true<\/skipTests>/<skipTests>false<\/skipTests>/g' pom.xml || true |
35 | | - fi |
36 | | - echo "✅ Tests enabled." |
| 26 | + echo "🔧 Ensuring tests are enabled in pom.xml..." |
| 27 | + sed -i 's/<skipTests>true<\/skipTests>/<skipTests>false<\/skipTests>/g' pom.xml || true |
37 | 28 |
|
38 | | - - name: Run Tests and Generate JaCoCo Report |
| 29 | + - name: Run tests and generate JaCoCo report |
39 | 30 | run: mvn clean test -Dtest='Test*' jacoco:report -Dgpg.skip=true |
| 31 | + working-directory: contentstack-java |
40 | 32 |
|
41 | | - - name: Extract and Check Coverage Thresholds |
42 | | - id: coverage |
| 33 | + - name: 📊 Extract coverage from JaCoCo HTML report |
| 34 | + id: extract_coverage |
| 35 | + working-directory: contentstack-java |
43 | 36 | run: | |
44 | | - echo "Checking JaCoCo coverage thresholds..." |
| 37 | + echo "Extracting coverage summary from JaCoCo HTML report..." |
45 | 38 |
|
46 | | - if [ ! -f target/site/jacoco/jacoco.xml ]; then |
47 | | - echo "❌ JaCoCo XML report not found." |
| 39 | + if [ ! -f target/site/jacoco/index.html ]; then |
| 40 | + echo "❌ JaCoCo HTML report not found!" |
48 | 41 | exit 1 |
49 | 42 | fi |
50 | 43 |
|
51 | | - INSTRUCTION=$(grep -oPm1 '(?<=<counter type="INSTRUCTION" missed=")[0-9]+" covered="[0-9]+"' target/site/jacoco/jacoco.xml | sed 's/" covered="/ /' | awk '{printf "%.2f", ($2/($1+$2))*100}') |
52 | | - BRANCH=$(grep -oPm1 '(?<=<counter type="BRANCH" missed=")[0-9]+" covered="[0-9]+"' target/site/jacoco/jacoco.xml | sed 's/" covered="/ /' | awk '{printf "%.2f", ($2/($1+$2))*100}') |
53 | | -
|
54 | | - echo "Instruction Coverage: $INSTRUCTION%" |
55 | | - echo "Branch Coverage: $BRANCH%" |
56 | | -
|
57 | | - echo "instruction=$INSTRUCTION" >> $GITHUB_OUTPUT |
58 | | - echo "branch=$BRANCH" >> $GITHUB_OUTPUT |
59 | | -
|
60 | | - MIN_INSTRUCTION=90 |
61 | | - MIN_BRANCH=80 |
62 | | -
|
63 | | - if (( ${INSTRUCTION%.*} < MIN_INSTRUCTION )); then |
64 | | - echo "❌ Instruction coverage below $MIN_INSTRUCTION%" |
65 | | - exit 1 |
66 | | - fi |
| 44 | + INSTRUCTION=$(grep -A2 "Total" target/site/jacoco/index.html | grep -m1 "%" | sed -E 's/.*>([0-9]+\.[0-9]+)%<.*/\1/') |
| 45 | + BRANCH=$(grep -A3 "Total" target/site/jacoco/index.html | grep -m2 "%" | tail -n1 | sed -E 's/.*>([0-9]+\.[0-9]+)%<.*/\1/') |
67 | 46 |
|
68 | | - if (( ${BRANCH%.*} < MIN_BRANCH )); then |
69 | | - echo "❌ Branch coverage below $MIN_BRANCH%" |
70 | | - exit 1 |
71 | | - fi |
| 47 | + echo "📘 Instruction Coverage: ${INSTRUCTION:-0}" |
| 48 | + echo "🌿 Branch Coverage: ${BRANCH:-0}" |
72 | 49 |
|
73 | | - echo "✅ Coverage thresholds met." |
| 50 | + echo "instruction=${INSTRUCTION:-0}" >> $GITHUB_OUTPUT |
| 51 | + echo "branch=${BRANCH:-0}" >> $GITHUB_OUTPUT |
74 | 52 |
|
75 | | - - name: Comment Coverage Summary on PR |
76 | | - if: always() |
| 53 | + - name: 💬 Post coverage summary as PR comment |
77 | 54 | uses: marocchino/sticky-pull-request-comment@v2 |
78 | 55 | with: |
79 | | - header: "🧪 JaCoCo Coverage Report" |
| 56 | + header: 🧪 JaCoCo Coverage Report |
80 | 57 | message: | |
81 | 58 | **Coverage Summary** |
82 | | - - 📘 Instruction Coverage: `${{ steps.coverage.outputs.instruction }}%` |
83 | | - - 🌿 Branch Coverage: `${{ steps.coverage.outputs.branch }}%` |
84 | | -
|
85 | | - ✅ Minimum thresholds: 90% instruction, 80% branch |
| 59 | + - 📘 Instruction Coverage: `${{ steps.extract_coverage.outputs.instruction }}%` |
| 60 | + - 🌿 Branch Coverage: `${{ steps.extract_coverage.outputs.branch }}%` |
86 | 61 |
|
87 | | - - name: Upload JaCoCo HTML Report |
88 | | - if: always() |
| 62 | + - name: 📦 Upload JaCoCo HTML report as artifact |
89 | 63 | uses: actions/upload-artifact@v4 |
90 | 64 | with: |
91 | 65 | name: jacoco-report |
92 | 66 | path: target/site/jacoco/ |
| 67 | + if-no-files-found: warn |
0 commit comments