Skip to content

Commit

Permalink
perf(ci): use gradle-build-action w/main cache only on all workflows
Browse files Browse the repository at this point in the history
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: gradle/gradle-build-action#113 (comment)
  • Loading branch information
mikehardy authored and oyeraghib committed Apr 30, 2022
1 parent b3d8d55 commit fc9b2e7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
28 changes: 13 additions & 15 deletions .github/workflows/lint.yml
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests_emulator.yml
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/tests_unit.yml
Expand Up @@ -60,22 +60,26 @@ 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
with:
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
Expand Down

0 comments on commit fc9b2e7

Please sign in to comment.