Skip to content

Commit

Permalink
[CI] Better caching and fewer jobs run
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
JoseAlcerreca committed Nov 10, 2023
1 parent 5f5bd91 commit 3f22248
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 46 deletions.
60 changes: 17 additions & 43 deletions .github/workflows/Build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,8 @@ concurrency:
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 90

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1

- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Check spotless
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache

- name: Build all build type and flavor permutations
run: ./gradlew assemble

- name: Upload build outputs (APKs)
uses: actions/upload-artifact@v3
with:
name: APKs
path: '**/build/outputs/apk/**/*.apk'

- name: Run local tests
run: ./gradlew testDemoDebug testProdDebug :lint:test

test:
test_and_apk:
name: "Local tests and APKs"
runs-on: ubuntu-latest

permissions:
Expand All @@ -76,6 +39,9 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Check spotless
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache

- name: Run all local screenshot tests (Roborazzi)
id: screenshotsverify
continue-on-error: true
Expand Down Expand Up @@ -106,7 +72,16 @@ jobs:
# Run local tests after screenshot tests to avoid wrong UP-TO-DATE. TODO: Ignore screenshots.
- name: Run local tests
if: always()
run: ./gradlew testDemoDebug testProdDebug
run: ./gradlew testDemoDebug testProdDebug :lint:test

- name: Build all build type and flavor permutations
run: ./gradlew assemble

- name: Upload build outputs (APKs)
uses: actions/upload-artifact@v3
with:
name: APKs
path: '**/build/outputs/apk/**/*.apk'

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

androidTest:
needs: build
runs-on: macOS-latest # enables hardware acceleration in the virtual machine
timeout-minutes: 55
strategy:
Expand All @@ -152,8 +126,8 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Build AndroidTest apps
run: ./gradlew packageDemoDebug packageDemoDebugAndroidTest --daemon
- name: Build projects before running emulator
run: ./gradlew packageDemoDebug packageDemoDebugAndroidTest

- name: Run instrumentation tests
uses: reactivecircus/android-emulator-runner@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import dagger.hilt.android.testing.BindValue
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -265,12 +265,14 @@ class NavigationTest {
}

@Test
fun navigationBar_multipleBackStackInterests() = runTest {
fun navigationBar_multipleBackStackInterests() {
composeTestRule.apply {
onNodeWithText(interests).performClick()

// Select the last topic
val topic = topicsRepository.getTopics().first().sortedBy(Topic::name).last().name
val topic = runBlocking {
topicsRepository.getTopics().first().sortedBy(Topic::name).last().name
}
onNodeWithTag("interests:topics").performScrollToNode(hasText(topic))
onNodeWithText(topic).performClick()

Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ org.gradle.caching=true

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

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

0 comments on commit 3f22248

Please sign in to comment.