Skip to content

Commit 9d81deb

Browse files
abdulraqeeb33AR Abdul Azeez
andauthored
chore: adding test coverage (#2381)
* adding test coverage * jacoco and diff * using custom diff * coverage with checkout * diff cover in one workflow --------- Co-authored-by: AR Abdul Azeez <abdul@onesignal.com>
1 parent a507911 commit 9d81deb

File tree

4 files changed

+371
-13
lines changed

4 files changed

+371
-13
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
runs:
2+
using: composite
3+
steps:
4+
- name: Checkout (full history)
5+
uses: actions/checkout@v4
6+
with:
7+
fetch-depth: 0
8+
9+
- name: Setup Java
10+
uses: actions/setup-java@v4
11+
with:
12+
java-version: '17'
13+
distribution: 'temurin'
14+
15+
- name: Setup Android SDK
16+
uses: android-actions/setup-android@v3
17+
with:
18+
cmdline-tools-version: '10406996'
19+
log-accepted-android-sdk-licenses: false
20+
21+
- name: Cache Gradle
22+
uses: actions/cache@v4
23+
with:
24+
path: |
25+
~/.gradle/caches
26+
~/.gradle/wrapper
27+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', '**/gradle/libs.versions.toml') }}
28+
restore-keys: |
29+
${{ runner.os }}-gradle-
30+

.github/workflows/ci.yml

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,57 @@ on:
44
pull_request:
55
branches: "**"
66

7+
env:
8+
DIFF_COVERAGE_THRESHOLD: '80'
9+
710
jobs:
811
build:
912
runs-on: ubuntu-24.04
1013
steps:
11-
- uses: actions/checkout@v4
12-
- name: "[Setup] Java"
13-
uses: actions/setup-java@v4
14-
with:
15-
java-version: '17'
16-
distribution: 'temurin'
17-
- name: "[Setup] Android"
18-
uses: android-actions/setup-android@v3
19-
with:
20-
cmdline-tools-version: 10406996
21-
log-accepted-android-sdk-licenses: false
22-
- name: "[Test] Linting"
14+
- name: "[Checkout] Repo"
15+
uses: actions/checkout@v4
16+
- name: "[Setup] Project"
17+
uses: ./.github/actions/project-setup
18+
- name: "[Code Formatting] Spotless"
2319
working-directory: OneSignalSDK
2420
run: |
2521
./gradlew spotlessCheck --console=plain
26-
- name: "[Test] Detekt"
22+
- name: "[Static Code Analysis] Detekt"
2723
working-directory: OneSignalSDK
2824
run: |
2925
./gradlew detekt --console=plain
3026
- name: "[Test] SDK Unit Tests"
3127
working-directory: OneSignalSDK
3228
run: |
3329
./gradlew testReleaseUnitTest --console=plain --continue
30+
- name: "[Coverage] Generate JaCoCo merged XML"
31+
working-directory: OneSignalSDK
32+
run: |
33+
./gradlew jacocoTestReportAll jacocoMergedReport --console=plain --continue
34+
- name: "[Setup] Python"
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version: '3.x'
38+
- name: "[Diff Coverage] Install diff-cover"
39+
run: |
40+
python -m pip install --upgrade pip diff-cover
41+
- name: "[Diff Coverage] Check and HTML report"
42+
working-directory: OneSignalSDK
43+
run: |
44+
REPORT=build/reports/jacoco/merged/jacocoMergedReport.xml
45+
test -f "$REPORT" || { echo "Merged JaCoCo report not found at $REPORT" >&2; exit 1; }
46+
python -m diff_cover.diff_cover_tool "$REPORT" \
47+
--compare-branch=origin/main \
48+
--fail-under=$DIFF_COVERAGE_THRESHOLD
49+
python -m diff_cover.diff_cover_tool "$REPORT" \
50+
--compare-branch=origin/main \
51+
--html-report diff_coverage.html || true
52+
- name: Upload diff coverage HTML
53+
if: always()
54+
uses: actions/upload-artifact@v4
55+
with:
56+
name: diff-coverage-report
57+
path: OneSignalSDK/diff_coverage.html
3458
- name: Unit tests results
3559
if: failure()
3660
uses: actions/upload-artifact@v4

OneSignalSDK/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,6 @@ gradle.projectsEvaluated {
107107
description = 'Creates/updates Detekt baselines for all modules.'
108108
}
109109
}
110+
111+
// Apply JaCoCo configuration from separate file
112+
apply from: 'jacoco.gradle'

0 commit comments

Comments
 (0)