diff --git a/.github/scripts/gradle-version-cache-detector.js b/.github/scripts/gradle-cache-detector.js similarity index 78% rename from .github/scripts/gradle-version-cache-detector.js rename to .github/scripts/gradle-cache-detector.js index 01e30226..68f6b21a 100644 --- a/.github/scripts/gradle-version-cache-detector.js +++ b/.github/scripts/gradle-cache-detector.js @@ -34,14 +34,16 @@ async function extractGradleVersion() { } function cacheGradleFiles(gradleVersion, core) { - const cacheKey = `${process.platform}-gradle-${gradleVersion}`; - const cachePaths = [ + const gradleCachePaths = [ '~/.gradle/caches', '~/.gradle/wrapper', '~/.gradle/configuration-cache', `~/.gradle/${gradleVersion}` ]; - core.setOutput('cache-key', cacheKey); - core.setOutput('cache-paths', cachePaths.join('\n')); + core.setOutput('gradle-version', gradleVersion); + core.setOutput('gradle-cache-key', `${process.platform}-gradle-${gradleVersion}`); + core.setOutput('gradle-cache-paths', gradleCachePaths.join('\n')); + core.setOutput('build-cache-key', `${process.platform}-build-${gradleVersion}`); + core.setOutput('build-cache-paths', `**/build`); } diff --git a/.github/workflows/ui-test.yml b/.github/workflows/ui-test.yml index 6d94cd35..38d51a7d 100644 --- a/.github/workflows/ui-test.yml +++ b/.github/workflows/ui-test.yml @@ -16,21 +16,26 @@ jobs: with: distribution: 'corretto' java-version: '17' - - name: 🔍 Detect Gradle Version And Cache + - name: 🔍 Detect Cache Key And Paths id: gradle-cache uses: actions/github-script@v7 with: script: | - const gradleCacheDetectorScriptPath = '/./.github/scripts/gradle-version-cache-detector.js' - const gradleCacheDetectorScript = require(`${process.env.GITHUB_WORKSPACE}${gradleCacheDetectorScriptPath}`) - await gradleCacheDetectorScript({core}); - - name: Fetch gradle cache - uses: actions/cache@v4 + const cacheDetectorScriptPath = '/./.github/scripts/gradle-cache-detector.js' + const cacheDetectorScript = require(`${process.env.GITHUB_WORKSPACE}${cacheDetectorScriptPath}`) + await cacheDetectorScript({core}); + - name: 🐘 Fetch gradle cache + uses: actions/cache/restore@v4 with: - path: ${{ steps.gradle-cache.outputs['cache-paths'] }} - key: ${{ steps.gradle-cache.outputs['cache-key'] }} - - name: Fetch AVD Cache - uses: actions/cache@v4 + path: ${{ steps.gradle-cache.outputs['gradle-cache-paths'] }} + key: ${{ steps.gradle-cache.outputs['gradle-cache-key'] }} + - name: 🐘 Fetch build cache + uses: actions/cache/restore@v4 + with: + path: ${{ steps.gradle-cache.outputs['build-cache-paths'] }} + key: ${{ steps.gradle-cache.outputs['build-cache-key'] }} + - name: 📱 Fetch AVD Cache + uses: actions/cache/restore@v4 id: avd-cache with: path: | @@ -42,20 +47,6 @@ jobs: echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules sudo udevadm control --reload-rules sudo udevadm trigger --name-match=kvm - - name: 📱 Create AVD and generate snapshot for caching - if: steps.avd-cache.outputs.cache-hit != 'true' - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: ${{ env.androidApiVersion }} - target: aosp_atd - channel: stable - arch: x86_64 - ram-size: 4096M - disk-size: 2048M - force-avd-creation: false - disable-animations: true - emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none - script: echo "Generated AVD snapshot for caching." - name: 🤖 Run Ui Tests uses: reactivecircus/android-emulator-runner@v2 with: diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 4c7af8ee..311ea179 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -14,19 +14,24 @@ jobs: with: distribution: 'corretto' java-version: '17' - - name: 🔍 Detect Gradle Version And Cache + - name: 🔍 Detect Cache Key And Paths id: gradle-cache uses: actions/github-script@v7 with: script: | - const gradleCacheDetectorScriptPath = '/./.github/scripts/gradle-version-cache-detector.js' - const gradleCacheDetectorScript = require(`${process.env.GITHUB_WORKSPACE}${gradleCacheDetectorScriptPath}`) - await gradleCacheDetectorScript({core}); - - name: Fetch gradle cache - uses: actions/cache@v4 + const cacheDetectorScriptPath = '/./.github/scripts/gradle-cache-detector.js' + const cacheDetectorScript = require(`${process.env.GITHUB_WORKSPACE}${cacheDetectorScriptPath}`) + await cacheDetectorScript({core}); + - name: 🐘 Fetch gradle cache + uses: actions/cache/restore@v4 with: - path: ${{ steps.gradle-cache.outputs['cache-paths'] }} - key: ${{ steps.gradle-cache.outputs['cache-key'] }} + path: ${{ steps.gradle-cache.outputs['gradle-cache-paths'] }} + key: ${{ steps.gradle-cache.outputs['gradle-cache-key'] }} + - name: 🐘 Fetch build cache + uses: actions/cache/restore@v4 + with: + path: ${{ steps.gradle-cache.outputs['build-cache-paths'] }} + key: ${{ steps.gradle-cache.outputs['build-cache-key'] }} - name: Run unit tests run: ./gradlew testDebugUnitTest --continue - name: Publish Unit Test Results diff --git a/.github/workflows/update-caches.yml b/.github/workflows/update-caches.yml index 92b5b71f..2a6bc0c6 100644 --- a/.github/workflows/update-caches.yml +++ b/.github/workflows/update-caches.yml @@ -33,19 +33,14 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} BRANCH: ${{ github.ref_name }} - - name: 🔍 Detect Gradle Version And Cache + - name: 🔍 Detect Cache Key And Paths id: gradle-cache uses: actions/github-script@v7 with: script: | - const gradleCacheDetectorScriptPath = '/./.github/scripts/gradle-version-cache-detector.js' - const gradleCacheDetectorScript = require(`${process.env.GITHUB_WORKSPACE}${gradleCacheDetectorScriptPath}`) - await gradleCacheDetectorScript({core}); - - name: Fetch gradle cache - uses: actions/cache@v4 - with: - path: ${{ steps.gradle-cache.outputs['cache-paths'] }} - key: ${{ steps.gradle-cache.outputs['cache-key'] }} + const cacheDetectorScriptPath = '/./.github/scripts/gradle-cache-detector.js' + const cacheDetectorScript = require(`${process.env.GITHUB_WORKSPACE}${cacheDetectorScriptPath}`) + await cacheDetectorScript({core}); - name: Enable KVM group permissions for emulator hardware acceleration run: | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules @@ -66,14 +61,23 @@ jobs: script: echo "Generated AVD snapshot for caching." - name: 🚧 Build run: gradle assembleDebug --configuration-cache - - name: 💾 Save AVD Cache + - name: 💾 📱 Save AVD Cache uses: actions/cache/save@v4 - if: always() with: path: | ~/.android/avd/* ~/.android/adb* key: ${{ runner.os }}-avd-${{ env.androidApiVersion }} + - name: 💾 🐘 Save Gradle Cache + uses: actions/cache/save@v4 + with: + path: ${{ steps.gradle-cache.outputs['gradle-cache-paths'] }} + key: ${{ steps.gradle-cache.outputs['gradle-cache-key'] }} + - name: 💾 🐘 Save Gradle Build Cache + uses: actions/cache/save/@v4 + with: + path: ${{ steps.gradle-cache.outputs['build-cache-paths'] }} + key: ${{ steps.gradle-cache.outputs['build-cache-key'] }} - name: 💌 Send email report uses: actions/github-script@v7 env: