From cef626b332d8d0d55b189150e680c4f0d1bea03f Mon Sep 17 00:00:00 2001 From: Saket Narayan Date: Fri, 6 Dec 2024 14:09:04 -0500 Subject: [PATCH] Reuse gradle dependencies across all CI steps --- .../workflows/test_and_release_snapshot.yml | 86 +++++++++++++------ 1 file changed, 62 insertions(+), 24 deletions(-) diff --git a/.github/workflows/test_and_release_snapshot.yml b/.github/workflows/test_and_release_snapshot.yml index e7cca14d..4b4ee773 100644 --- a/.github/workflows/test_and_release_snapshot.yml +++ b/.github/workflows/test_and_release_snapshot.yml @@ -6,38 +6,78 @@ on: pull_request: jobs: - unit-tests: - name: Unit tests - runs-on: macos-latest + prepare: + name: Prepare workspace and cache dependencies + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: lfs: true - - uses: gradle/wrapper-validation-action@v1 - uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: 17 - uses: gradle/actions/setup-gradle@v4 + - name: Cache Gradle dependencies + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + gradle-${{ runner.os }} + + - name: Upload prepared workspace + uses: actions/upload-artifact@v4 + with: + name: workspace + path: . + + - uses: gradle/actions/setup-gradle@v4 + - uses: oNaiPs/secrets-to-env-action@v1 + with: + secrets: ${{ toJSON(secrets) }} + + unit-tests: + name: Unit tests + runs-on: macos-latest + needs: prepare + + steps: + - name: Download prepared workspace + uses: actions/download-artifact@v4 + with: + name: workspace + - name: Cache Gradle dependencies + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - name: Run unit tests and friends run: ./gradlew check screenshot-tests: name: Android screenshot tests runs-on: ubuntu-latest + needs: prepare steps: - - uses: actions/checkout@v4 + - name: Download prepared workspace + uses: actions/download-artifact@v4 with: - lfs: true - - uses: gradle/wrapper-validation-action@v1 - - uses: actions/setup-java@v4 + name: workspace + - name: Cache Gradle dependencies + uses: actions/cache@v3 with: - distribution: 'zulu' - java-version: 17 - - uses: gradle/actions/setup-gradle@v4 + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - name: Run paparazzi screenshot tests run: ./gradlew verifyPaparazziDebug @@ -52,13 +92,8 @@ jobs: **/out/failures/ paparazzi/paparazzi-gradle-plugin/src/test/projects/**/build/reports/paparazzi/images/ - - uses: oNaiPs/secrets-to-env-action@v1 - with: - secrets: ${{ toJSON(secrets) }} - - name: Run instrumented screenshot tests env: - # https://docs.emulator.wtf/github/tokenless EW_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: ./gradlew testDebugWithEmulatorWtf @@ -79,18 +114,21 @@ jobs: timeout-minutes: 10 if: github.repository == 'saket/telephoto' && github.ref == 'refs/heads/trunk' needs: [unit-tests, screenshot-tests] + steps: - - uses: actions/checkout@v3 - - uses: gradle/wrapper-validation-action@v1 - - uses: actions/setup-java@v3 + - name: Download prepared workspace + uses: actions/download-artifact@v4 with: - distribution: 'zulu' - java-version: 17 - - uses: gradle/gradle-build-action@v2.4.2 - + name: workspace + - name: Cache Gradle dependencies + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - name: Ensure snapshot version run: ./gradlew throwIfVersionIsNotSnapshot - - name: Publish snapshot run: ./gradlew clean publish --no-daemon --no-parallel --no-configuration-cache --stacktrace env: