From dd08415c849e77ea41db81e3d5a9eae763c6f55a Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Wed, 10 Apr 2024 12:36:52 +0200 Subject: [PATCH] [CI] Improve caching behavior --- .github/workflows/codeql.yml | 10 +++---- .github/workflows/test-dev.yml | 50 +++++++++++++--------------------- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f9593017..0ac158e3 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -36,14 +36,14 @@ jobs: - uses: gradle/actions/setup-gradle@v3 with: cache-encryption-key: ${{ secrets.gradle_encryption_key }} + cache-read-only: true # gradle user home cache is generated by test jobs - - name: Use app/build and gradle configuration cache + - name: Use incremental build cache uses: actions/cache/restore@v4 with: - key: app_build-tests-without-emulator - path: | - .gradle/configuration-cache - app/build + key: incremental-build-tests + restore-keys: incremental-build-tests # restore cache from main branch + path: app/build # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/test-dev.yml b/.github/workflows/test-dev.yml index fdb31c46..36e7f180 100644 --- a/.github/workflows/test-dev.yml +++ b/.github/workflows/test-dev.yml @@ -24,29 +24,19 @@ jobs: - uses: gradle/actions/setup-gradle@v3 with: cache-encryption-key: ${{ secrets.gradle_encryption_key }} - cache-write-only: ${{ env.is_main_branch }} # otherwise build cache will grow larger and larger + cache-read-only: true # gradle user home cache is generated by test_on_emulator - - name: Create app/build and gradle configuration cache - if: ${{ env.is_main_branch }} - uses: actions/cache@v4 - with: - key: app_build-tests-without-emulator-${{ github.run_id }} - path: | - .gradle/configuration-cache - app/build - - name: Use app/build and gradle configuration cache - if: ${{ !env.is_main_branch }} + - name: Use incremental build cache uses: actions/cache/restore@v4 with: - key: app_build-tests-without-emulator - restore-keys: app_build-tests-without-emulator- # restore cache from main branch - path: | - .gradle/configuration-cache - app/build + key: incremental-build-tests + restore-keys: incremental-build-tests # restore cache from main branch + path: app/build - name: Run lint and unit tests - run: ./gradlew --build-cache --configuration-cache --configuration-cache-problems=warn app:check + run: ./gradlew --build-cache --configuration-cache --configuration-cache-problems=warn --no-daemon app:check + # generates the build caches because it uses more gradle dependencies test_on_emulator: name: Tests with emulator runs-on: ubuntu-latest @@ -59,22 +49,14 @@ jobs: - uses: gradle/actions/setup-gradle@v3 with: cache-encryption-key: ${{ secrets.gradle_encryption_key }} - cache-write-only: ${{ env.is_main_branch }} # otherwise build cache will grow larger and larger - - - name: Create app/build and gradle configuration cache - if: ${{ env.is_main_branch }} - uses: actions/cache@v4 - with: - key: app_build-tests-with-emulator-${{ github.run_id }} - path: | - .gradle/configuration-cache - app/build - - name: Use app/build and gradle configuration cache + gradle-home-cache-cleanup: true # avoid ever-growing gradle user home cache + + - name: Use incremental build cache if: ${{ !env.is_main_branch }} uses: actions/cache/restore@v4 with: - key: app_build-tests-with-emulator - restore-keys: app_build-tests-with-emulator- # restore cache from main branch + key: incremental-build-tests + restore-keys: incremental-build-tests # restore cache from main branch path: | .gradle/configuration-cache app/build @@ -92,5 +74,11 @@ jobs: key: avd-${{ hashFiles('app/build.gradle.kts') }} # gradle-managed devices are defined there - name: Run device tests - run: ./gradlew --build-cache --configuration-cache --configuration-cache-problems=warn app:virtualCheck + run: ./gradlew --build-cache --configuration-cache --configuration-cache-problems=warn --no-daemon app:virtualCheck + - name: Create incremental build cache + if: ${{ env.is_main_branch }} + uses: actions/cache/save@v4 + with: + key: incremental-build-tests-${{ github.run_id }} + path: app/build