Skip to content

Reuse gradle dependencies across all CI steps #424

Reuse gradle dependencies across all CI steps

Reuse gradle dependencies across all CI steps #424

name: Run tests and publish snapshot
on:
push:
branches: [ trunk ]
pull_request:
jobs:
prepare:
name: Prepare workspace and cache dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
lfs: true
- 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:
- 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 paparazzi screenshot tests
run: ./gradlew verifyPaparazziDebug
- name: (Fail-only) Upload paparazzi test reports
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-failures
path: |
**/build/reports/tests/*/
**/out/failures/
paparazzi/paparazzi-gradle-plugin/src/test/projects/**/build/reports/paparazzi/images/
- name: Run instrumented screenshot tests
env:
EW_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew testDebugWithEmulatorWtf
- name: (Fail-only) Bundle instrumented test reports
if: failure()
run: find . -type d '(' -name 'reports' -o -name 'test-results' ')' | zip -@ -r instrumentation-test-build-reports.zip
- name: (Fail-only) Upload instrumented test reports
if: failure()
uses: actions/upload-artifact@v4
with:
name: instrumentation-test-report
path: instrumentation-test-build-reports.zip
deploy-snapshot:
name: Deploy snapshot
runs-on: ubuntu-latest
timeout-minutes: 10
if: github.repository == 'saket/telephoto' && github.ref == 'refs/heads/trunk'
needs: [unit-tests, screenshot-tests]
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: Ensure snapshot version
run: ./gradlew throwIfVersionIsNotSnapshot
- name: Publish snapshot
run: ./gradlew clean publish --no-daemon --no-parallel --no-configuration-cache --stacktrace
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}