mirror of
https://github.com/bitfireAT/davx5-ose.git
synced 2025-12-23 15:07:51 -05:00
[CI] Add gradle remote build cache (bitfireAT/davx5#752)
* [CI] Add gradle remote build cache * Update workflow * Don't cache local build cache; pre-populate configuration cache * Allow configuration caching of tasks * Free some disk space before running instrumented tests; cache whole .android (not only .android/avd) * Allow branches to update configuration cache * Use dry run to pre-populate configuration cache * Test runs: don't cache * Fix remote build cache configuration for non-CI builds * Add comment
This commit is contained in:
68
.github/workflows/test-dev.yml
vendored
68
.github/workflows/test-dev.yml
vendored
@@ -9,10 +9,14 @@ concurrency:
|
|||||||
group: test-dev-${{ github.ref }}
|
group: test-dev-${{ github.ref }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
env:
|
||||||
|
GRADLE_BUILDCACHE_URL: ${{ secrets.gradle_buildcache_url }}
|
||||||
|
GRADLE_BUILDCACHE_USERNAME: ${{ secrets.gradle_buildcache_username }}
|
||||||
|
GRADLE_BUILDCACHE_PASSWORD: ${{ secrets.gradle_buildcache_password }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
compile:
|
compile:
|
||||||
name: Compile for build cache
|
name: Compile
|
||||||
if: github.ref == 'refs/heads/main-ose'
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
@@ -22,16 +26,26 @@ jobs:
|
|||||||
java-version: 21
|
java-version: 21
|
||||||
|
|
||||||
# See https://community.gradle.org/github-actions/docs/setup-gradle/ for more information
|
# See https://community.gradle.org/github-actions/docs/setup-gradle/ for more information
|
||||||
- uses: gradle/actions/setup-gradle@v5 # creates build cache
|
- uses: gradle/actions/setup-gradle@v5
|
||||||
with:
|
with:
|
||||||
cache-encryption-key: ${{ secrets.gradle_encryption_key }}
|
cache-encryption-key: ${{ secrets.gradle_encryption_key }}
|
||||||
dependency-graph: generate-and-submit # submit Github Dependency Graph info
|
cache-read-only: false # allow branches to update their configuration cache
|
||||||
|
dependency-graph: generate-and-submit # submit Github Dependency Graph info
|
||||||
|
gradle-home-cache-excludes: caches/build-cache-1 # don't cache local build cache because we use a remote cache
|
||||||
|
|
||||||
- run: ./gradlew --build-cache --configuration-cache app:compileOseDebugSource
|
- name: Populate configuration cache
|
||||||
|
run: |
|
||||||
|
./gradlew --configuration-cache --dry-run \
|
||||||
|
app:compileOseDebugSource \
|
||||||
|
app:lintOseDebug \
|
||||||
|
app:testOseDebugUnitTest \
|
||||||
|
app:virtualOseDebugAndroidTest
|
||||||
|
|
||||||
test:
|
- name: Compile
|
||||||
|
run: ./gradlew --build-cache --configuration-cache app:compileOseDebugSource
|
||||||
|
|
||||||
|
unit_tests:
|
||||||
needs: compile
|
needs: compile
|
||||||
if: ${{ !cancelled() }} # even if compile didn't run (because not on main branch)
|
|
||||||
name: Lint and unit tests
|
name: Lint and unit tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -45,14 +59,13 @@ jobs:
|
|||||||
cache-encryption-key: ${{ secrets.gradle_encryption_key }}
|
cache-encryption-key: ${{ secrets.gradle_encryption_key }}
|
||||||
cache-read-only: true
|
cache-read-only: true
|
||||||
|
|
||||||
- name: Run lint
|
- name: Lint checks
|
||||||
run: ./gradlew --build-cache --configuration-cache app:lintOseDebug
|
run: ./gradlew --build-cache --configuration-cache app:lintOseDebug
|
||||||
- name: Run unit tests
|
- name: Unit tests
|
||||||
run: ./gradlew --build-cache --configuration-cache app:testOseDebugUnitTest
|
run: ./gradlew --build-cache --configuration-cache app:testOseDebugUnitTest
|
||||||
|
|
||||||
test_on_emulator:
|
instrumented_tests:
|
||||||
needs: compile
|
needs: compile
|
||||||
if: ${{ !cancelled() }} # even if compile didn't run (because not on main branch)
|
|
||||||
name: Instrumented tests
|
name: Instrumented tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -72,19 +85,28 @@ jobs:
|
|||||||
sudo udevadm control --reload-rules
|
sudo udevadm control --reload-rules
|
||||||
sudo udevadm trigger --name-match=kvm
|
sudo udevadm trigger --name-match=kvm
|
||||||
|
|
||||||
- name: Restore cached AVD
|
- name: Restore Android environment
|
||||||
id: restore-avd
|
id: restore-android
|
||||||
uses: actions/cache/restore@v5
|
uses: actions/cache/restore@v5
|
||||||
with:
|
with:
|
||||||
path: ~/.config/.android/avd
|
path: ~/.config/.android
|
||||||
key: avd-${{ hashFiles('app/build.gradle.kts') }} # gradle-managed devices are defined there
|
key: android-${{ hashFiles('app/build.gradle.kts') }} # gradle-managed devices are defined there
|
||||||
|
|
||||||
- name: Run device tests
|
# gradle and Android SDK often take more space than what is available on the default runner.
|
||||||
run: ./gradlew --build-cache --configuration-cache app:virtualCheck
|
# We try to free a few GB here to make gradle-managed devices more reliable.
|
||||||
|
- name: Free some disk space
|
||||||
- name: Cache AVD
|
uses: jlumbroso/free-disk-space@main
|
||||||
uses: actions/cache/save@v5
|
|
||||||
if: steps.restore-avd.outputs.cache-hit != 'true'
|
|
||||||
with:
|
with:
|
||||||
path: ~/.config/.android/avd
|
android: false # we need the Android SDK
|
||||||
key: avd-${{ hashFiles('app/build.gradle.kts') }} # gradle-managed devices are defined there
|
large-packages: false # apt takes too long
|
||||||
|
swap-storage: false # gradle needs much memory
|
||||||
|
|
||||||
|
- name: Instrumented tests
|
||||||
|
run: ./gradlew --build-cache --configuration-cache app:virtualOseDebugAndroidTest
|
||||||
|
|
||||||
|
- name: Cache Android environment
|
||||||
|
uses: actions/cache/save@v5
|
||||||
|
if: steps.restore-android.outputs.cache-hit != 'true'
|
||||||
|
with:
|
||||||
|
path: ~/.config/.android
|
||||||
|
key: android-${{ hashFiles('app/build.gradle.kts') }} # gradle-managed devices are defined there
|
||||||
|
|||||||
@@ -19,4 +19,18 @@ dependencyResolutionManagement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use remote build cache, if configured
|
||||||
|
if (System.getenv("GRADLE_BUILDCACHE_URL") != null) {
|
||||||
|
buildCache {
|
||||||
|
remote<HttpBuildCache> {
|
||||||
|
url = uri(System.getenv("GRADLE_BUILDCACHE_URL"))
|
||||||
|
credentials {
|
||||||
|
username = System.getenv("GRADLE_BUILDCACHE_USERNAME")
|
||||||
|
password = System.getenv("GRADLE_BUILDCACHE_PASSWORD")
|
||||||
|
}
|
||||||
|
isPush = true // read/write
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
include(":app")
|
include(":app")
|
||||||
|
|||||||
Reference in New Issue
Block a user