Skip to content

Commit

Permalink
[CI] Improve caching behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc2822 committed Apr 10, 2024
1 parent b88c351 commit fbfee56
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 35 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ 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
path: app/build

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
50 changes: 19 additions & 31 deletions .github/workflows/test-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit fbfee56

Please sign in to comment.