From fc9b2e72686e28337fc28ef9e89496b8d284c9a4 Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Mon, 25 Apr 2022 11:51:04 -0500 Subject: [PATCH] perf(ci): use gradle-build-action w/main cache only on all workflows This should optimize LRU cache eviction so main and branches always have reasonably fresh gradle caches and main does not ever get evicted, since branches have independent caches and would otherwise fill up 10GB cache limit Note that `--daemon` is specified as the default for this action is no daemon, that is correct for long-lived runners to avoid cross-build contamination, but on GitHub Hosted Runners (which we use) we are clean each run, so this is a small optimization to share gradle between steps: https://github.com/gradle/gradle-build-action/issues/113#issuecomment-1003204780 --- .github/workflows/lint.yml | 28 +++++++++++++--------------- .github/workflows/tests_emulator.yml | 4 ++-- .github/workflows/tests_unit.yml | 16 ++++++++++------ 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ed7f50887443..f8b5c240df49 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -54,11 +54,13 @@ jobs: run: java -fullversion 2>&1 | grep '11.0' shell: bash - - name: Gradle Cache - uses: actions/cache@v3 + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}-v1 + # Only write to the cache for builds on the 'main' branches, stops branches evicting main cache + # Builds on other branches will only read from main branch cache writes + # Comment this and the with: above out for performance testing on a branch + cache-read-only: ${{ github.ref != 'refs/heads/main' }} - name: Warm Gradle Cache # This makes sure we fetch gradle network resources with a retry @@ -67,19 +69,15 @@ jobs: timeout_minutes: 10 retry_wait_seconds: 60 max_attempts: 3 - command: ./gradlew :AnkiDroid:compilePlayDebugJavaWithJavac compileLint lint-rules:compileTestJava + command: ./gradlew :AnkiDroid:compilePlayDebugJavaWithJavac compileLint lint-rules:compileTestJava --daemon - name: Run Lint Debug - # "lint" is run under the 'Amazon' flavor, so slow in CI - # "lintPlayRelease" doesn't test androidTest - # "lintPlayDebug" doesn't test the API - run: ./gradlew lintPlayDebug :api:lintDebug - - - name: Test Lint Rules - run: ./gradlew lint-rules:test - - - name: Ktlint Check - run: ./gradlew ktlintCheck + uses: gradle/gradle-build-action@v2 + with: + # "lint" is run under the 'Amazon' flavor, so slow in CI + # "lintPlayRelease" doesn't test androidTest + # "lintPlayDebug" doesn't test the API + arguments: lintPlayDebug :api:lintDebug ktLintCheck lint-rules:test --daemon - name: Prettify code uses: creyD/prettier_action@v4.2 diff --git a/.github/workflows/tests_emulator.yml b/.github/workflows/tests_emulator.yml index 7c014045e8b4..2f2aa8a052c5 100644 --- a/.github/workflows/tests_emulator.yml +++ b/.github/workflows/tests_emulator.yml @@ -74,7 +74,7 @@ jobs: timeout_minutes: 15 retry_wait_seconds: 60 max_attempts: 3 - command: ./gradlew packagePlayDebug packagePlayDebugAndroidTest + command: ./gradlew packagePlayDebug packagePlayDebugAndroidTest --daemon # This appears to be 'Cache Size: ~1230 MB (1290026823 B)' based on watching action logs # Repo limit is 10GB; branch caches are independent; branches may read default branch cache. @@ -141,7 +141,7 @@ jobs: disable-animations: true script: | $ANDROID_HOME/platform-tools/adb logcat '*:D' > adb-log.txt & - ./gradlew uninstallAll jacocoAndroidTestReport + ./gradlew uninstallAll jacocoAndroidTestReport --daemon - name: Compress Emulator Log if: always() diff --git a/.github/workflows/tests_unit.yml b/.github/workflows/tests_unit.yml index 4fa38c7b1554..848db13c7d5b 100644 --- a/.github/workflows/tests_unit.yml +++ b/.github/workflows/tests_unit.yml @@ -60,11 +60,13 @@ jobs: run: java -fullversion 2>&1 | grep '11.0' shell: bash - - name: Gradle Cache - uses: actions/cache@v3 + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}-v2 + # Only write to the cache for builds on the 'main' branches, stops branches evicting main cache + # Builds on other branches will only read from main branch cache writes + # Comment this and the with: above out for performance testing on a branch + cache-read-only: ${{ github.ref != 'refs/heads/main' }} - name: Gradle Dependency Download uses: nick-invision/retry@v2 @@ -72,10 +74,12 @@ jobs: timeout_minutes: 10 retry_wait_seconds: 60 max_attempts: 3 - command: ./gradlew robolectricSdkDownload + command: ./gradlew robolectricSdkDownload --daemon - name: Run Unit Tests - run: ./gradlew jacocoUnitTestReport + uses: gradle/gradle-build-action@v2 + with: + arguments: jacocoUnitTestReport --daemon - name: Submit Coverage # This can fail on timeouts etc, wrap with retry