|
| 1 | +name: Kotlin CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master] |
| 6 | + pull_request: |
| 7 | + |
| 8 | +env: |
| 9 | + # Must use $HOME here, NOT a tilde, because of the order in which bash does expansion: |
| 10 | + # Tilde happens before variables, so will be used literally, whereas $HOME will be |
| 11 | + # recursively expanded. |
| 12 | + GRADLE_CACHE_PATH: $HOME/.gradle/caches |
| 13 | + |
| 14 | +jobs: |
| 15 | + assemble: |
| 16 | + name: Assemble |
| 17 | + runs-on: ubuntu-latest |
| 18 | + timeout-minutes: 15 |
| 19 | + steps: |
| 20 | + # These setup steps should be common across all jobs in this workflow. |
| 21 | + - uses: actions/checkout@v2 |
| 22 | + - uses: gradle/wrapper-validation-action@v1 |
| 23 | + - name: set up JDK 1.8 |
| 24 | + uses: actions/setup-java@v1 |
| 25 | + with: |
| 26 | + java-version: 1.8 |
| 27 | + |
| 28 | + ## Caching |
| 29 | + - name: Cache gradle dependencies |
| 30 | + uses: actions/cache@v1 |
| 31 | + with: |
| 32 | + path: ${{ env.GRADLE_CACHE_PATH }} |
| 33 | + # Include the SHA in the hash so this step always adds a cache entry. If we didn't use the SHA, the artifacts |
| 34 | + # would only get cached once for each build config hash. |
| 35 | + # Don't use ${{ runner.os }} in the key so we don't re-assemble for UI tests. |
| 36 | + key: gradle-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/buildSrc/**') }}-${{ github.sha }} |
| 37 | + # The first time a SHA is assembled, we still want to load dependencies from the cache. |
| 38 | + # Note that none of jobs dependent on this one need restore keys, since they'll always have an exact hit. |
| 39 | + restore-keys: | |
| 40 | + gradle-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/buildSrc/**') }}- |
| 41 | +
|
| 42 | + # We want to keep the dependencies from the cache, but clear out the build cache which contains the actual |
| 43 | + # compiled artifacts from this project. This ensures we don't run into any issues with stale cache entries, |
| 44 | + # and that the resulting cache we upload for the other jobs won't waste any space on stale binaries. |
| 45 | + # A simpler approach would be simply to delete the build-cache before uploading the cache archive, however |
| 46 | + # if we did that in this job it would defeat the purpose of sharing that directory with dependent jobs, |
| 47 | + # and there's no way to modify the cache after the job that created it finishes. |
| 48 | + - name: Clean gradle build cache to assemble fresh |
| 49 | + run: | |
| 50 | + ls -lhrt $GRADLE_CACHE_PATH || true |
| 51 | + rm -rf $GRADLE_CACHE_PATH/build-cache-1 |
| 52 | + ls -lhrt $GRADLE_CACHE_PATH || true |
| 53 | +
|
| 54 | + ## Actual task |
| 55 | + - name: Assemble with gradle |
| 56 | + run: ./gradlew assemble --build-cache --no-daemon --stacktrace |
| 57 | + |
| 58 | + # Runs all check tasks in parallel. |
| 59 | + check: |
| 60 | + name: Check |
| 61 | + needs: assemble |
| 62 | + runs-on: ubuntu-latest |
| 63 | + timeout-minutes: 10 |
| 64 | + strategy: |
| 65 | + # Run all checks, even if some fail. |
| 66 | + fail-fast: false |
| 67 | + matrix: |
| 68 | + gradle-task: |
| 69 | + # Unit tests |
| 70 | + - test |
| 71 | + # Binary compatibility |
| 72 | + - apiCheck |
| 73 | + - lint |
| 74 | + - ktlintCheck |
| 75 | + - detekt |
| 76 | + # Build the JMH benchmarks to verify, but don't run them. |
| 77 | + - jmhJar |
| 78 | + steps: |
| 79 | + - uses: actions/checkout@v2 |
| 80 | + - name: set up JDK 1.8 |
| 81 | + uses: actions/setup-java@v1 |
| 82 | + with: |
| 83 | + java-version: 1.8 |
| 84 | + |
| 85 | + ## Caching |
| 86 | + - name: Cache build artifacts |
| 87 | + uses: actions/cache@v1 |
| 88 | + with: |
| 89 | + path: ${{ env.GRADLE_CACHE_PATH }} |
| 90 | + # Don't set restore-keys so cache is always only valid for the current build config. |
| 91 | + # Also don't use ${{ runner.os }} in the key so we don't re-assemble for UI tests. |
| 92 | + key: gradle-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/buildSrc/**') }}-${{ github.sha }} |
| 93 | + |
| 94 | + ## Actual task |
| 95 | + - name: Check with Gradle |
| 96 | + run: ./gradlew ${{ matrix.gradle-task }} --build-cache --no-daemon --stacktrace |
| 97 | + |
| 98 | + instrumentation-tests: |
| 99 | + name: Instrumentation tests |
| 100 | + needs: assemble |
| 101 | + runs-on: macos-latest |
| 102 | + timeout-minutes: 20 |
| 103 | + strategy: |
| 104 | + # Allow tests to continue on other devices if they fail on one device. |
| 105 | + fail-fast: false |
| 106 | + matrix: |
| 107 | + api-level: |
| 108 | + # Tests are failing on APIs <24. |
| 109 | + #- 21 |
| 110 | + #- 23 |
| 111 | + - 24 |
| 112 | + - 29 |
| 113 | + steps: |
| 114 | + - uses: actions/checkout@v2 |
| 115 | + - name: set up JDK 1.8 |
| 116 | + uses: actions/setup-java@v1 |
| 117 | + with: |
| 118 | + java-version: 1.8 |
| 119 | + |
| 120 | + ## Caching |
| 121 | + - name: Cache build artifacts |
| 122 | + uses: actions/cache@v1 |
| 123 | + with: |
| 124 | + path: ${{ env.GRADLE_CACHE_PATH }} |
| 125 | + # Don't set restore-keys so cache is always only valid for the current build config. |
| 126 | + # Also don't use ${{ runner.os }} in the key so we don't re-assemble for UI tests. |
| 127 | + key: gradle-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/buildSrc/**') }}-${{ github.sha }} |
| 128 | + |
| 129 | + ## Actual task |
| 130 | + - name: Instrumentation Tests |
| 131 | + uses: reactivecircus/android-emulator-runner@v2 |
| 132 | + with: |
| 133 | + api-level: ${{ matrix.api-level }} |
| 134 | + arch: x86_64 |
| 135 | + script: ./gradlew connectedCheck --build-cache --no-daemon --stacktrace |
0 commit comments