1+ name : Build and Test
2+
3+ on :
4+ push :
5+ branches : [ "main" ]
6+ pull_request :
7+ branches : [ "main" ]
8+ workflow_dispatch :
9+
10+ # Ensure that only the latest commit is tested for PRs
11+ concurrency :
12+ group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
13+ cancel-in-progress : true
14+
15+ permissions :
16+ contents : write # Needed for git-auto-commit-action
17+
18+ jobs :
19+ build_test_lint :
20+ name : " Build, Test, and Lint"
21+ runs-on : ubuntu-latest
22+ timeout-minutes : 60
23+
24+ steps :
25+ - name : Checkout code
26+ uses : actions/checkout@v4
27+
28+ - name : Set up JDK 17
29+ uses : actions/setup-java@v4
30+ with :
31+ java-version : ' 17'
32+ distribution : ' temurin'
33+
34+ - name : Setup Gradle
35+ uses : gradle/actions/setup-gradle@v4
36+ # Add cache-encryption-key if you set up the GRADLE_ENCRYPTION_KEY secret
37+ # with:
38+ # cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
39+
40+ - name : Grant execute permission for gradlew
41+ run : chmod +x gradlew
42+
43+ - name : Build debug APK
44+ run : ./gradlew assembleDebug --no-configuration-cache
45+
46+ - name : Apply Spotless
47+ run : ./gradlew spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache
48+
49+ - name : Commit Spotless changes
50+ uses : stefanzweifel/git-auto-commit-action@v5
51+ with :
52+ commit_message : 🤖 Apply Spotless formatting
53+ file_pattern : ' **/*.kt **/*.kts **/*.java **/*.xml'
54+
55+ - name : Verify Screenshot Tests (AndroidX)
56+ run : ./gradlew validateDebugScreenshotTest
57+
58+ - name : Run local unit tests
59+ run : ./gradlew testDebugUnitTest
60+
61+ - name : Check lint
62+ run : ./gradlew lintDebug
63+
64+ - name : Upload build outputs (APKs)
65+ if : ${{ !cancelled() }}
66+ uses : actions/upload-artifact@v4
67+ with :
68+ name : APKs
69+ path : ' **/build/outputs/apk/debug/*.apk'
70+
71+ - name : Upload JVM local test results (XML)
72+ if : ${{ !cancelled() }}
73+ uses : actions/upload-artifact@v4
74+ with :
75+ name : local-test-results
76+ path : ' **/build/test-results/test*UnitTest/TEST-*.xml'
77+
78+ - name : Upload lint reports (HTML)
79+ if : ${{ !cancelled() }}
80+ uses : actions/upload-artifact@v4
81+ with :
82+ name : lint-reports-html
83+ path : ' **/build/reports/lint-results-debug.html'
84+
85+ androidTest :
86+ name : " Instrumentation Tests (emulator)"
87+ runs-on : ubuntu-latest
88+ timeout-minutes : 60
89+ strategy :
90+ matrix :
91+ api-level : [26]
92+
93+ steps :
94+ - name : Delete unnecessary tools 🔧
95+ uses : jlumbroso/free-disk-space@v1.3.1
96+ with :
97+ android : false # Don't remove Android tools
98+ tool-cache : true # Remove image tool cache
99+ dotnet : true
100+ haskell : true
101+ swap-storage : true
102+
103+ - name : Enable KVM group perms
104+ run : |
105+ echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
106+ sudo udevadm control --reload-rules
107+ sudo udevadm trigger --name-match=kvm
108+
109+ - name : Checkout code
110+ uses : actions/checkout@v4
111+
112+ - name : Copy CI gradle.properties
113+ run : mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
114+
115+ - name : Set up JDK 17
116+ uses : actions/setup-java@v4
117+ with :
118+ java-version : ' 17'
119+ distribution : ' temurin'
120+
121+ - name : Setup Gradle
122+ uses : gradle/actions/setup-gradle@v4
123+
124+ - name : Grant execute permission for gradlew
125+ run : chmod +x gradlew
126+
127+ - name : Build
128+ run : ./gradlew assembleDebug assembleDebugAndroidTest
129+
130+ - name : Build projects and run instrumentation tests
131+ uses : reactivecircus/android-emulator-runner@v2
132+ with :
133+ api-level : ${{ matrix.api-level }}
134+ arch : x86
135+ disable-animations : true
136+ disk-size : 6000M
137+ heap-size : 600M
138+ script : ./gradlew connectedDebugAndroidTest
139+
140+
141+ - name : Upload test reports
142+ if : ${{ !cancelled() }}
143+ uses : actions/upload-artifact@v4
144+ with :
145+ name : test-reports-${{ matrix.api-level }}
146+ path : ' **/build/reports/androidTests'
0 commit comments