|
| 1 | +name: Nav3 BackStackEntryMapper R8 Check |
| 2 | + |
| 3 | +# Verifies behavior of BackStackEntryMapper.SerialName from sentry-android-navigation3 in |
| 4 | +# R8-minified builds on an emulator (R8 full mode with the |
| 5 | +# compile floor, the latest stable release, and any newer release candidate of |
| 6 | +# kotlinx.serialization, from gradle/dependency-matrix.versions.toml, and R8 compat mode with the |
| 7 | +# floor). Also runs all of the module's unit tests against the newer versions. See sentry-android-integration-tests/nav3-backstack-entry-mapper-r8-check/README.md. |
| 8 | +# |
| 9 | +# Release candidate failures are warnings, except on PRs that change kotlinxSerialization-preview, |
| 10 | +# such as the weekly updater's. |
| 11 | + |
| 12 | +# Runs on every PR and every push to main, without paths filters: the relevance job decides |
| 13 | +# whether the check runs, using scripts/nav3-r8-check-relevant.sh as the only list of relevant |
| 14 | +# changes. |
| 15 | +on: |
| 16 | + push: |
| 17 | + branches: |
| 18 | + - main |
| 19 | + pull_request: |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: read |
| 23 | + |
| 24 | +# A new push only cancels a superseded PR run. On main, a run that started finishes, as the API 23 |
| 25 | +# job only runs there and would otherwise rarely complete; a newer push waits for it instead. |
| 26 | +concurrency: |
| 27 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 28 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 29 | + |
| 30 | +env: |
| 31 | + APK_DIR: "nav3-r8-check-apks" |
| 32 | + APK_ARTIFACT_NAME: "nav3-r8-check-apks" |
| 33 | + |
| 34 | +jobs: |
| 35 | + # Decides whether the changes affect the check, with scripts/nav3-r8-check-relevant.sh. The |
| 36 | + # other jobs are skipped (and report as skipped) if they don't, e.g., for PRs that don't touch |
| 37 | + # Nav3 or that only bump unrelated versions in gradle/libs.versions.toml. |
| 38 | + # |
| 39 | + # Also decides whether release candidate failures fail the check (but only on PRs that change |
| 40 | + # kotlinxSerialization-preview). |
| 41 | + relevance: |
| 42 | + name: Check relevance |
| 43 | + runs-on: ubuntu-latest |
| 44 | + outputs: |
| 45 | + relevant: ${{ steps.check.outputs.relevant }} |
| 46 | + preview-required: ${{ steps.check.outputs.preview-required }} |
| 47 | + |
| 48 | + steps: |
| 49 | + # A PR's checkout is a merge commit, whose first parent is the base branch, and a push to |
| 50 | + # main is usually one squashed commit, so two commits are usually enough to diff the changes. |
| 51 | + - name: Checkout code |
| 52 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 53 | + with: |
| 54 | + fetch-depth: 2 |
| 55 | + |
| 56 | + - name: Check whether the changes affect the check |
| 57 | + id: check |
| 58 | + env: |
| 59 | + PUSH_BEFORE: ${{ github.event.before }} |
| 60 | + run: | |
| 61 | + previewRequired=false |
| 62 | + if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then |
| 63 | + relevant="$(./scripts/nav3-r8-check-relevant.sh HEAD^1 HEAD)" |
| 64 | + if ./scripts/dependency-matrix.sh changed-roles HEAD^1 HEAD kotlinxSerialization | grep -qx preview; then |
| 65 | + previewRequired=true |
| 66 | + fi |
| 67 | + else |
| 68 | + # A push may contain several commits, so diff against the commit main pointed to before |
| 69 | + # it. If that commit can't be fetched (e.g., after a force push), run the check. |
| 70 | + if [[ -n "$PUSH_BEFORE" && ! "$PUSH_BEFORE" =~ ^0+$ ]] \ |
| 71 | + && { git cat-file -e "${PUSH_BEFORE}^{commit}" 2> /dev/null \ |
| 72 | + || git fetch --depth=1 origin "$PUSH_BEFORE"; }; then |
| 73 | + relevant="$(./scripts/nav3-r8-check-relevant.sh --any-catalog-change "$PUSH_BEFORE" HEAD)" |
| 74 | + else |
| 75 | + relevant=true |
| 76 | + fi |
| 77 | + fi |
| 78 | + if [[ "$previewRequired" == "true" ]] \ |
| 79 | + && ! ./scripts/dependency-matrix.sh extra-versions kotlinxSerialization | grep -q '^preview '; then |
| 80 | + echo "::notice::kotlinxSerialization-preview changed, but isn't newer than kotlinxSerialization-stable, so no release candidate is tested." |
| 81 | + fi |
| 82 | + echo "relevant=$relevant" >> "$GITHUB_OUTPUT" |
| 83 | + echo "preview-required=$previewRequired" >> "$GITHUB_OUTPUT" |
| 84 | + echo "Nav3 R8 check relevant: $relevant" |
| 85 | + echo "kotlinx.serialization release candidate required: $previewRequired" |
| 86 | +
|
| 87 | + # Runs separately from the APK builds, so a unit test failure doesn't hide the R8 check's results. |
| 88 | + unit-tests: |
| 89 | + name: Unit tests |
| 90 | + needs: relevance |
| 91 | + if: needs.relevance.outputs.relevant == 'true' |
| 92 | + runs-on: ubuntu-latest |
| 93 | + |
| 94 | + steps: |
| 95 | + - name: Checkout code |
| 96 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 97 | + |
| 98 | + - name: Set up Java |
| 99 | + uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0 |
| 100 | + with: |
| 101 | + distribution: 'temurin' |
| 102 | + java-version: '21' |
| 103 | + |
| 104 | + - name: Setup Gradle |
| 105 | + uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1 |
| 106 | + |
| 107 | + # Apps may ship a newer kotlinx.serialization than sentry-android-navigation3 compiles |
| 108 | + # against. The Build workflow runs the unit tests against the floor. |
| 109 | + - name: Run unit tests against newer kotlinx.serialization versions |
| 110 | + env: |
| 111 | + NAV3_PREVIEW_REQUIRED: ${{ needs.relevance.outputs.preview-required }} |
| 112 | + run: ./scripts/test-nav3-kotlinx-versions.sh |
| 113 | + |
| 114 | + build: |
| 115 | + name: Build |
| 116 | + needs: relevance |
| 117 | + if: needs.relevance.outputs.relevant == 'true' |
| 118 | + runs-on: ubuntu-latest |
| 119 | + |
| 120 | + steps: |
| 121 | + - name: Checkout code |
| 122 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 123 | + |
| 124 | + - name: Set up Java |
| 125 | + uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0 |
| 126 | + with: |
| 127 | + distribution: 'temurin' |
| 128 | + java-version: '21' |
| 129 | + |
| 130 | + - name: Setup Gradle |
| 131 | + uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1 |
| 132 | + |
| 133 | + - name: Build APKs |
| 134 | + env: |
| 135 | + NAV3_PREVIEW_REQUIRED: ${{ needs.relevance.outputs.preview-required }} |
| 136 | + run: ./scripts/test-nav3-backstack-entry-mapper-r8.sh build "${{ env.APK_DIR }}" |
| 137 | + |
| 138 | + - name: Upload APK artifact |
| 139 | + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 |
| 140 | + with: |
| 141 | + name: ${{ env.APK_ARTIFACT_NAME }} |
| 142 | + path: ${{ env.APK_DIR }} |
| 143 | + retention-days: 1 |
| 144 | + |
| 145 | + run: |
| 146 | + name: Run on API Level ${{ matrix.api-level }} |
| 147 | + needs: [relevance, build] |
| 148 | + runs-on: ubuntu-latest |
| 149 | + strategy: |
| 150 | + fail-fast: false |
| 151 | + matrix: |
| 152 | + # Tests against API 37.0 on every run. Also tests against API 23 (Nav3's minSdkVersion) when changes reach main. |
| 153 | + # The latter lets us catch issues present on the oldest Nav3 app runtime without slowing down PRs. |
| 154 | + api-level: ${{ fromJSON(github.event_name == 'push' && '[23, "37.0"]' || '["37.0"]') }} |
| 155 | + steps: |
| 156 | + - name: Checkout code |
| 157 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 158 | + |
| 159 | + - name: Enable KVM |
| 160 | + run: | |
| 161 | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules |
| 162 | + sudo udevadm control --reload-rules |
| 163 | + sudo udevadm trigger --name-match=kvm |
| 164 | +
|
| 165 | + - name: Download APK artifact |
| 166 | + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 |
| 167 | + with: |
| 168 | + name: ${{ env.APK_ARTIFACT_NAME }} |
| 169 | + path: ${{ env.APK_DIR }} |
| 170 | + |
| 171 | + # The runner ships an outdated avdmanager that writes target=android-0 into the |
| 172 | + # AVD config for minor-versioned packages (android-37.x), so the emulator clamps |
| 173 | + # to API 3 and boots misconfigured. Update cmdline-tools so avdmanager parses it. |
| 174 | + # See https://github.com/ReactiveCircus/android-emulator-runner/issues/482 |
| 175 | + - name: Update SDK cmdline-tools |
| 176 | + if: matrix.api-level == '37.0' |
| 177 | + run: | |
| 178 | + SDK="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-/usr/local/lib/android/sdk}}" |
| 179 | + yes | "$SDK/cmdline-tools/latest/bin/sdkmanager" --install "cmdline-tools;latest" > /dev/null |
| 180 | + # sdkmanager won't overwrite the preinstalled dir, so it installs to latest-2. |
| 181 | + if [ -d "$SDK/cmdline-tools/latest-2" ]; then |
| 182 | + rm -rf "$SDK/cmdline-tools/latest" |
| 183 | + mv "$SDK/cmdline-tools/latest-2" "$SDK/cmdline-tools/latest" |
| 184 | + fi |
| 185 | +
|
| 186 | + - name: Run check |
| 187 | + uses: reactivecircus/android-emulator-runner@a421e43855164a8197daf9d8d40fe71c6996bb0d # pin@v2.38.0 |
| 188 | + env: |
| 189 | + NAV3_PREVIEW_REQUIRED: ${{ needs.relevance.outputs.preview-required }} |
| 190 | + with: |
| 191 | + api-level: ${{ matrix.api-level }} |
| 192 | + # API 37 has no plain google_apis image. |
| 193 | + target: ${{ matrix.api-level == 23 && 'google_apis' || 'google_apis_ps16k' }} |
| 194 | + # Use canary for API 37, matching the critical UI tests. |
| 195 | + channel: ${{ matrix.api-level == 23 && 'stable' || 'canary' }} |
| 196 | + arch: x86_64 |
| 197 | + disable-animations: true |
| 198 | + disable-spellchecker: true |
| 199 | + emulator-options: -memory 4096 -no-window -gpu auto -noaudio -no-boot-anim -camera-back none -no-snapshot-save |
| 200 | + script: ./scripts/test-nav3-backstack-entry-mapper-r8.sh run "${{ env.APK_DIR }}" |
0 commit comments