Skip to content

Commit 3f22248

Browse files
[CI] Better caching and fewer jobs run
* [CI] Runs build in macos to generate a cache for androidTest runs * Build projects before running emulator * Fixes flaky coroutines test * Moves spotless up in local tests job * Enables config cache by setting problems to warn. Fixes #1022
1 parent 5f5bd91 commit 3f22248

File tree

3 files changed

+26
-46
lines changed

3 files changed

+26
-46
lines changed

.github/workflows/Build.yaml

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,8 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
jobs:
14-
build:
15-
runs-on: ubuntu-latest
16-
timeout-minutes: 90
17-
18-
steps:
19-
- name: Checkout
20-
uses: actions/checkout@v4
21-
22-
- name: Validate Gradle Wrapper
23-
uses: gradle/wrapper-validation-action@v1
24-
25-
- name: Copy CI gradle.properties
26-
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
27-
28-
- name: Set up JDK 17
29-
uses: actions/setup-java@v3
30-
with:
31-
distribution: 'zulu'
32-
java-version: 17
33-
34-
- name: Setup Gradle
35-
uses: gradle/gradle-build-action@v2
36-
37-
- name: Check spotless
38-
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache
39-
40-
- name: Build all build type and flavor permutations
41-
run: ./gradlew assemble
42-
43-
- name: Upload build outputs (APKs)
44-
uses: actions/upload-artifact@v3
45-
with:
46-
name: APKs
47-
path: '**/build/outputs/apk/**/*.apk'
48-
49-
- name: Run local tests
50-
run: ./gradlew testDemoDebug testProdDebug :lint:test
51-
52-
test:
14+
test_and_apk:
15+
name: "Local tests and APKs"
5316
runs-on: ubuntu-latest
5417

5518
permissions:
@@ -76,6 +39,9 @@ jobs:
7639
- name: Setup Gradle
7740
uses: gradle/gradle-build-action@v2
7841

42+
- name: Check spotless
43+
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache
44+
7945
- name: Run all local screenshot tests (Roborazzi)
8046
id: screenshotsverify
8147
continue-on-error: true
@@ -106,7 +72,16 @@ jobs:
10672
# Run local tests after screenshot tests to avoid wrong UP-TO-DATE. TODO: Ignore screenshots.
10773
- name: Run local tests
10874
if: always()
109-
run: ./gradlew testDemoDebug testProdDebug
75+
run: ./gradlew testDemoDebug testProdDebug :lint:test
76+
77+
- name: Build all build type and flavor permutations
78+
run: ./gradlew assemble
79+
80+
- name: Upload build outputs (APKs)
81+
uses: actions/upload-artifact@v3
82+
with:
83+
name: APKs
84+
path: '**/build/outputs/apk/**/*.apk'
11085

11186
- name: Upload test results (XML)
11287
if: always()
@@ -129,7 +104,6 @@ jobs:
129104
run: ./gradlew :app:checkProdReleaseBadging
130105

131106
androidTest:
132-
needs: build
133107
runs-on: macOS-latest # enables hardware acceleration in the virtual machine
134108
timeout-minutes: 55
135109
strategy:
@@ -152,8 +126,8 @@ jobs:
152126
- name: Setup Gradle
153127
uses: gradle/gradle-build-action@v2
154128

155-
- name: Build AndroidTest apps
156-
run: ./gradlew packageDemoDebug packageDemoDebugAndroidTest --daemon
129+
- name: Build projects before running emulator
130+
run: ./gradlew packageDemoDebug packageDemoDebugAndroidTest
157131

158132
- name: Run instrumentation tests
159133
uses: reactivecircus/android-emulator-runner@v2

app/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import dagger.hilt.android.testing.BindValue
4242
import dagger.hilt.android.testing.HiltAndroidRule
4343
import dagger.hilt.android.testing.HiltAndroidTest
4444
import kotlinx.coroutines.flow.first
45-
import kotlinx.coroutines.test.runTest
45+
import kotlinx.coroutines.runBlocking
4646
import org.junit.Before
4747
import org.junit.Rule
4848
import org.junit.Test
@@ -265,12 +265,14 @@ class NavigationTest {
265265
}
266266

267267
@Test
268-
fun navigationBar_multipleBackStackInterests() = runTest {
268+
fun navigationBar_multipleBackStackInterests() {
269269
composeTestRule.apply {
270270
onNodeWithText(interests).performClick()
271271

272272
// Select the last topic
273-
val topic = topicsRepository.getTopics().first().sortedBy(Topic::name).last().name
273+
val topic = runBlocking {
274+
topicsRepository.getTopics().first().sortedBy(Topic::name).last().name
275+
}
274276
onNodeWithTag("interests:topics").performScrollToNode(hasText(topic))
275277
onNodeWithText(topic).performClick()
276278

gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ org.gradle.caching=true
2323

2424
# Enable configuration caching between builds.
2525
org.gradle.configuration-cache=true
26+
# This option is set because of https://github.com/google/play-services-plugins/issues/246
27+
# to generate the Configuration Cache regardless of incompatible tasks.
28+
# See https://github.com/android/nowinandroid/issues/1022 before using it.
29+
org.gradle.configuration-cache.problems=warn
2630

2731
# AndroidX package structure to make it clearer which packages are bundled with the
2832
# Android operating system, and which are packaged with your app"s APK

0 commit comments

Comments
 (0)