From 3f22248cb7342f5eb0a17097ba5817343a5604f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Alc=C3=A9rreca?= Date: Fri, 10 Nov 2023 15:49:25 +0100 Subject: [PATCH] [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 --- .github/workflows/Build.yaml | 60 ++++++------------- .../apps/nowinandroid/ui/NavigationTest.kt | 8 ++- gradle.properties | 4 ++ 3 files changed, 26 insertions(+), 46 deletions(-) diff --git a/.github/workflows/Build.yaml b/.github/workflows/Build.yaml index ccea5dc4f..dec4dedcc 100644 --- a/.github/workflows/Build.yaml +++ b/.github/workflows/Build.yaml @@ -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: @@ -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 @@ -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() @@ -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: @@ -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 diff --git a/app/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt b/app/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt index e1eab4796..5861cda58 100644 --- a/app/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt +++ b/app/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt @@ -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 @@ -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() diff --git a/gradle.properties b/gradle.properties index c4159cfea..c0acfeb02 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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