|
1 | 1 | name: CI |
2 | 2 |
|
3 | | -on: [push, pull_request] |
| 3 | +on: |
| 4 | + # Only run push on main |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + paths-ignore: |
| 9 | + - '**/*.md' |
| 10 | + # Always run on PRs |
| 11 | + pull_request: |
| 12 | + branches: [ main ] |
| 13 | + merge_group: |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: 'ci-${{ github.event.merge_group.head_ref || github.head_ref }}-${{ github.workflow }}' |
| 17 | + cancel-in-progress: true |
4 | 18 |
|
5 | 19 | jobs: |
6 | 20 | build: |
7 | | - name: JDK ${{ matrix.java_version }} |
8 | 21 | runs-on: macOS-latest |
9 | | - strategy: |
10 | | - fail-fast: false |
11 | | - matrix: |
12 | | - java_version: [11] |
| 22 | + env: |
| 23 | + api-level: "18" |
13 | 24 | steps: |
14 | 25 | - name: Checkout |
15 | 26 | uses: actions/checkout@v1 |
| 27 | + |
16 | 28 | - name: Gradle Wrapper Validation |
17 | 29 | uses: gradle/wrapper-validation-action@v1 |
18 | | - - name: Install JDK ${{ matrix.java_version }} |
| 30 | + |
| 31 | + - name: Install JDK |
19 | 32 | uses: actions/setup-java@v2 |
20 | 33 | with: |
21 | 34 | distribution: 'zulu' |
22 | | - java-version: ${{ matrix.java_version }} |
23 | | - - name: Install Android SDK |
24 | | - uses: malinskiy/action-android/install-sdk@release/0.1.2 |
25 | | - - run: sdkmanager platform-tools |
26 | | - # TODO Caching disabled for now due to the size of Gradle's cache rendering this super slow |
27 | | -# - name: Cache build .gradle dir |
28 | | -# uses: actions/cache@v1.0.1 |
29 | | -# with: |
30 | | -# path: .gradle |
31 | | -# key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} |
32 | | -# restore-keys: | |
33 | | -# ${{ runner.os }}-gradle- |
34 | | -# - name: Cache user .gradle dir |
35 | | -# uses: actions/cache@v1.0.1 |
36 | | -# with: |
37 | | -# path: ~/.gradle |
38 | | -# key: ${{ runner.os }}-gradleuser-${{ hashFiles('**/*.gradle') }} |
39 | | -# restore-keys: | |
40 | | -# ${{ runner.os }}-gradleuser- |
41 | | - - name: Configure Gradle |
42 | | - # Initial gradle configuration, install dependencies, etc |
43 | | - run: ./gradlew help |
44 | | - - name: Spot check |
45 | | - # Run spotless first to fail fast on spotless issues |
46 | | - run: ./gradlew spotlessCheck --stacktrace |
47 | | - - name: Build project |
48 | | - run: ./gradlew assemble --stacktrace |
| 35 | + java-version: '17' |
| 36 | + |
| 37 | + - name: Gradle cache |
| 38 | + uses: gradle/gradle-build-action@v2 |
| 39 | + |
49 | 40 | # TODO split test and instrumentation into parallel builds |
50 | | - - name: Run tests |
51 | | - run: ./gradlew test --stacktrace |
| 41 | + - name: Build and run unit tests |
| 42 | + id: gradle |
| 43 | + uses: gradle/gradle-build-action@v2 |
| 44 | + with: |
| 45 | + arguments: check |
| 46 | + |
| 47 | + - name: AVD cache |
| 48 | + uses: actions/cache@v3 |
| 49 | + id: avd-cache |
| 50 | + with: |
| 51 | + path: | |
| 52 | + ~/.android/avd/* |
| 53 | + ~/.android/adb* |
| 54 | + key: avd-${{ env.api-level }} |
| 55 | + |
| 56 | + - name: Create AVD and generate snapshot for caching |
| 57 | + if: steps.avd-cache.outputs.cache-hit != 'true' |
| 58 | + uses: reactivecircus/android-emulator-runner@v2 |
| 59 | + with: |
| 60 | + api-level: ${{ env.api-level }} |
| 61 | + force-avd-creation: false |
| 62 | + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 63 | + disable-animations: false |
| 64 | + script: echo "Generated AVD snapshot for caching." |
| 65 | + |
52 | 66 | - name: Run instrumentation tests |
53 | | - uses: malinskiy/action-android/emulator-run-cmd@release/0.1.2 |
| 67 | + uses: reactivecircus/android-emulator-runner@v2 |
54 | 68 | with: |
55 | | - cmd: ./gradlew connectedCheck --stacktrace |
56 | | - api: 18 |
57 | | - tag: default |
58 | | - abi: x86 |
59 | | - - name: Reclaim memory |
60 | | - run: ./gradlew --stop && jps|grep -E 'KotlinCompileDaemon|GradleDaemon'| awk '{print $1}'| xargs kill -9 |
61 | | - - name: Final checks |
62 | | - run: ./gradlew check --stacktrace |
| 69 | + api-level: ${{ env.api-level }} |
| 70 | + force-avd-creation: false |
| 71 | + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 72 | + disable-animations: true |
| 73 | + script: ./gradlew connectedCheck |
| 74 | + |
| 75 | + - name: (Fail-only) Upload build reports |
| 76 | + if: failure() |
| 77 | + uses: actions/upload-artifact@v3 |
| 78 | + with: |
| 79 | + name: reports |
| 80 | + path: | |
| 81 | + **/build/reports/** |
| 82 | +
|
63 | 83 | - name: Upload snapshot (main only) |
| 84 | + if: success() && github.ref == 'refs/heads/main' && github.event_name != 'pull_request' |
64 | 85 | run: ./gradlew publish -PmavenCentralUsername="${{ secrets.SonatypeUsername }}" -PmavenCentralPassword="${{ secrets.SonatypePassword }}" |
65 | | - if: success() && github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && matrix.java_version == '11' |
|
0 commit comments