From e134a88b7adc40609e405369aa9ee5b46649a071 Mon Sep 17 00:00:00 2001 From: lihenggui <350699171@qq.com> Date: Fri, 10 Nov 2023 22:17:40 -0800 Subject: [PATCH 1/3] [CI] Better caching and fewer jobs run --- .github/workflows/Build.yaml | 117 ++++++++++++++--------------------- gradle.properties | 4 ++ 2 files changed, 51 insertions(+), 70 deletions(-) diff --git a/.github/workflows/Build.yaml b/.github/workflows/Build.yaml index 2899cfa546..9b9f968b52 100644 --- a/.github/workflows/Build.yaml +++ b/.github/workflows/Build.yaml @@ -28,23 +28,22 @@ concurrency: cancel-in-progress: true jobs: - build: + test_and_apk: + name: "Local tests and APKs" runs-on: self-hosted - timeout-minutes: 120 + + permissions: + contents: write + + timeout-minutes: 60 steps: - name: Checkout uses: actions/checkout@v4 - with: - submodules: 'true' - fetch-depth: 0 - 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: Write sign info if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && github.repository == 'lihenggui/Blocker' run: | @@ -56,6 +55,9 @@ jobs: echo ${{ secrets.KEYSTORE }} | base64 --decode > ${{ github.workspace }}/key.jks fi + - 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: @@ -71,6 +73,38 @@ jobs: - 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 + run: ./gradlew verifyRoborazziFossDebug + + - name: Prevent pushing new screenshots if this is a fork + id: checkfork + continue-on-error: false + if: steps.screenshotsverify.outcome == 'failure' && github.event.pull_request.head.repo.full_name != github.repository + run: | + echo "::error::Screenshot tests failed, please create a PR in your fork first." && exit 1 + + # Runs if previous job failed + - name: Generate new screenshots if verification failed and it's a PR + id: screenshotsrecord + if: steps.screenshotsverify.outcome == 'failure' && github.event_name == 'pull_request' + run: | + ./gradlew recordRoborazziFossDebug + + - name: Push new screenshots if available + uses: stefanzweifel/git-auto-commit-action@v5 + if: steps.screenshotsrecord.outcome == 'success' + with: + file_pattern: '*/*.png' + disable_globbing: true + commit_message: "🤖 Updates screenshots" + + # Run local tests after screenshot tests to avoid wrong UP-TO-DATE. TODO: Ignore screenshots. + - name: Run local tests + if: always() + run: ./gradlew testFossDebug testMarketDebug :lint:test + - name: Build all build type and flavor permutations run: ./gradlew assemble @@ -88,10 +122,10 @@ jobs: name: Market-APK path: ${{ github.workspace }}/app-compose/build/outputs/apk/market/release - - name: Upload build outputs (Raw-APKs) + - name: Upload build outputs (APKs) uses: actions/upload-artifact@v3 with: - name: Raw-APKs + name: APKs path: '**/build/outputs/apk/**/*.apk' - name: Upload mappings @@ -116,65 +150,6 @@ jobs: with: apk-path: ${{ steps.apk-path.outputs.foss_path }} - test: - runs-on: self-hosted - - permissions: - contents: write - - timeout-minutes: 60 - - 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.9.0 - - - name: Run all local screenshot tests (Roborazzi) - id: screenshotsverify - continue-on-error: true - run: ./gradlew verifyRoborazziFossDebug - - - name: Prevent pushing new screenshots if this is a fork - id: checkfork - continue-on-error: false - if: steps.screenshotsverify.outcome == 'failure' && github.event.pull_request.head.repo.full_name != github.repository - run: | - echo "::error::Screenshot tests failed, please create a PR in your fork first." && exit 1 - - # Runs if previous job failed - - name: Generate new screenshots if verification failed and it's a PR - id: screenshotsrecord - if: steps.screenshotsverify.outcome == 'failure' && github.event_name == 'pull_request' - run: | - ./gradlew recordRoborazziFossDebug - - - name: Push new screenshots if available - uses: stefanzweifel/git-auto-commit-action@v5 - if: steps.screenshotsrecord.outcome == 'success' - with: - file_pattern: '*/*.png' - disable_globbing: true - commit_message: "🤖 Updates screenshots" - - # Run local tests after screenshot tests to avoid wrong UP-TO-DATE. TODO: Ignore screenshots. - - name: Run local tests - if: always() - run: ./gradlew testFossDebug testMarketDebug :lint:test - - name: Upload test results (XML) if: always() uses: actions/upload-artifact@v3 @@ -195,7 +170,6 @@ jobs: run: ./gradlew :app-compose:checkMarketReleaseBadging androidTest: - needs: build runs-on: self-hosted timeout-minutes: 90 strategy: @@ -221,6 +195,9 @@ jobs: - name: Setup Gradle uses: gradle/gradle-build-action@v2.9.0 + - name: Build projects before running emulator + run: ./gradlew packageFossDebug packageFossDebugAndroidTest + - name: Run instrumentation tests uses: reactivecircus/android-emulator-runner@v2 with: diff --git a/gradle.properties b/gradle.properties index 8cb31f0c48..d1d75c8ea0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,6 +18,10 @@ org.gradle.configureondemand=false 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 # https://developer.android.com/topic/libraries/support-library/androidx-rn From dd1f8bcc2ccb20f6fb81bbdcda2ec60c46b83bd7 Mon Sep 17 00:00:00 2001 From: lihenggui <350699171@qq.com> Date: Fri, 10 Nov 2023 22:27:51 -0800 Subject: [PATCH 2/3] Add constrains for running AndroidTests --- .github/workflows/Build.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/Build.yaml b/.github/workflows/Build.yaml index 9b9f968b52..7466859c34 100644 --- a/.github/workflows/Build.yaml +++ b/.github/workflows/Build.yaml @@ -40,6 +40,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + submodules: 'true' + fetch-depth: 0 - name: Validate Gradle Wrapper uses: gradle/wrapper-validation-action@v1 @@ -170,6 +173,7 @@ jobs: run: ./gradlew :app-compose:checkMarketReleaseBadging androidTest: + needs: build runs-on: self-hosted timeout-minutes: 90 strategy: From e081c4e0eb458b1ef4ea95be7a97d48184af18f5 Mon Sep 17 00:00:00 2001 From: lihenggui <350699171@qq.com> Date: Fri, 10 Nov 2023 22:32:16 -0800 Subject: [PATCH 3/3] Fix errors in the androidTest part --- .github/workflows/Build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Build.yaml b/.github/workflows/Build.yaml index 7466859c34..9ab7321e2c 100644 --- a/.github/workflows/Build.yaml +++ b/.github/workflows/Build.yaml @@ -173,7 +173,7 @@ jobs: run: ./gradlew :app-compose:checkMarketReleaseBadging androidTest: - needs: build + needs: test_and_apk runs-on: self-hosted timeout-minutes: 90 strategy: