Skip to content

Commit 88da4c7

Browse files
committed
ci(nav3): Keep the SerialName mapper's compatibility coverage current
Run the R8 check and the module's unit tests in CI against the kotlinx.serialization floor, the latest stable release, and any newer release candidate. The versions live in gradle/dependency-matrix.versions.toml: Dependabot bumps the stable one, and a weekly job in update-deps.yml bumps the release candidate. Release candidate failures only fail PRs that change it. The workflow runs on every PR and push to main, and scripts/nav3-r8-check-relevant.sh decides whether the changes can affect the check. The R8 check's README describes what to do when a bump fails.
1 parent ba7a24b commit 88da4c7

12 files changed

Lines changed: 618 additions & 29 deletions

File tree

‎.github/dependabot.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ updates:
99
- package-ecosystem: "gradle"
1010
# The separate sample and test builds read this build's version catalog, so one directory
1111
# covers them. Listing them too opens one PR per directory for the same bump.
12+
#
13+
# Also bumps the <matrix>-stable versions in gradle/dependency-matrix.versions.toml. Don't add
14+
# ignore rules for those modules (see the rules at the top of that file).
1215
directory: "/"
1316
registries:
1417
- gradle-plugin-portal
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
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 }}"

‎.github/workflows/update-deps.yml‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
name: Update Dependencies
22

33
on:
4-
# Run every day.
54
schedule:
5+
# Run every day.
66
- cron: '0 3 * * *'
7-
# And on on every PR merge so we get the updated dependencies ASAP, and to make sure the changelog doesn't conflict.
7+
# Run weekly (select btw daily or weekly via `if:`).
8+
- cron: '0 4 * * 1'
9+
# Also trigger on pushes to main (individual jobs decide whether to run). E.g., lets us get updated
10+
# dependencies ASAP and make sure the changelog doesn't conflict.
811
push:
912
branches:
1013
- main
@@ -15,11 +18,29 @@ permissions:
1518
actions: write
1619

1720
jobs:
21+
# Update the Sentry Native SDK dependency daily and on pushes to main.
1822
native:
23+
if: github.event.schedule != '0 4 * * 1'
1924
runs-on: ubuntu-latest
2025
steps:
2126
- uses: getsentry/github-workflows/updater@36529d71129a14967bea1fb81bcaf2a5943cf877 # v3
2227
with:
2328
path: scripts/update-sentry-native-ndk.sh
2429
name: Native SDK
2530
ssh-key: ${{ secrets.CI_DEPLOY_KEY }}
31+
32+
# Update weekly the kotlinx-serialization-core release candidate used by the Nav3 R8 check and
33+
# unit tests. (Dependabot separately bumps the latest stable / non-preview release.)
34+
nav3-kotlinx-serialization-preview:
35+
if: github.event.schedule == '0 4 * * 1'
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: getsentry/github-workflows/updater@36529d71129a14967bea1fb81bcaf2a5943cf877 # v3
39+
with:
40+
path: scripts/update-kotlinx-serialization-preview.sh
41+
name: Nav3 kotlinx.serialization RC check
42+
# Release candidates only. kotlinx.serialization publishes no alpha or beta releases.
43+
pattern: '^v?(?<version>[0-9.]+-RC[0-9]*)$'
44+
# Only the Nav3 tests use this version; the SDK's dependency doesn't change.
45+
changelog-entry: false
46+
ssh-key: ${{ secrets.CI_DEPLOY_KEY }}

‎gradle/dependency-matrix.versions.toml‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,39 @@
44
# Kept apart from libs.versions.toml so that each matrix's tests can run on PRs that change its
55
# versions, without also running on every unrelated dependency bump.
66
#
7-
# Each matrix <name> has a <name>-floor version key: the oldest version we support, which we
8-
# compile and test against. Only changed by hand, in a reviewed change. No library entry references
9-
# it, so Dependabot never bumps it. Builds apply it explicitly (e.g., `version { strictly(...) }`)
10-
# instead.
7+
# Each matrix <name> has up to three version keys, named by role:
118
#
12-
# Never give a floor key a library entry with `version.ref`, and never protect it with a Dependabot
13-
# `ignore` rule: ignore rules match a dependency's group and name, so they would also stop
14-
# Dependabot from bumping other versions of the same module.
9+
# - <name>-floor: the oldest version we support, which we compile and test against. Only changed
10+
# by hand, in a reviewed change. No library entry references it, so Dependabot never bumps it.
11+
# Builds apply it explicitly (e.g., `version { strictly(...) }`) instead.
12+
# - <name>-stable: the latest stable release. Bumped by Dependabot through the <name>-stableTracker
13+
# library entry, which references it and is used by no build.
14+
# - <name>-preview: the latest pre-release, which is tested only while it's newer than
15+
# <name>-stable. Bumped by a weekly updater job in .github/workflows/update-deps.yml. No library
16+
# entry references it, so Dependabot never bumps it.
17+
#
18+
# Rules for adding a matrix:
19+
#
20+
# - Never give the floor or preview keys a library entry with `version.ref`, and never protect them
21+
# with a Dependabot `ignore` rule: ignore rules match a dependency's group and name, so they would
22+
# also stop Dependabot from bumping <name>-stable.
23+
# - A stableTracker entry mustn't share its module with any entry or build file declaration that
24+
# Dependabot also updates (e.g., in libs.versions.toml). Dependabot merges declarations of one
25+
# module and bumps them all to one version. If they would collide, track a sibling artifact
26+
# instead (e.g., `-jvm`).
27+
#
28+
# scripts/dependency-matrix.sh reads and writes these keys for CI and the updater jobs.
1529

1630
[versions]
1731
# The oldest kotlinx.serialization version sentry-android-navigation3 supports, which it compiles and
1832
# tests against. Before changing it, read the rules under "Version floor" in
1933
# sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/internal/backstack/kotlinx/README.md.
2034
kotlinxSerialization-floor = "1.7.3"
35+
kotlinxSerialization-stable = "1.13.0"
36+
# kotlinx.serialization publishes release candidates (-RC), but no alpha or beta releases.
37+
kotlinxSerialization-preview = "1.12.0-RC"
2138

2239
[libraries]
2340
# Applied with the floor version by the builds that use it.
2441
kotlinxSerialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core" }
42+
kotlinxSerialization-stableTracker = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinxSerialization-stable" }

‎scripts/dependency-matrix.sh‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env bash
2+
# Reads and writes the role keys in gradle/dependency-matrix.versions.toml (<matrix>-floor,
3+
# <matrix>-stable, and <matrix>-preview; see that file's header) for CI jobs and updater scripts.
4+
#
5+
# Usage:
6+
# dependency-matrix.sh get MATRIX ROLE
7+
# Prints the version of MATRIX's ROLE.
8+
# dependency-matrix.sh set MATRIX ROLE VERSION
9+
# Sets the version of MATRIX's ROLE.
10+
# dependency-matrix.sh extra-versions MATRIX
11+
# Prints the versions to test besides the floor, one "ROLE VERSION" line each: the stable
12+
# version, then the preview version if it's newer than the stable one.
13+
# dependency-matrix.sh changed-roles BASE HEAD MATRIX
14+
# Prints the roles of MATRIX whose versions changed between commits BASE and HEAD.
15+
set -euo pipefail
16+
17+
cd "$(dirname "$0")/../"
18+
catalog="gradle/dependency-matrix.versions.toml"
19+
20+
usage() {
21+
sed -n '5,14p' "$0" | sed 's/^# \{0,1\}//'
22+
exit 1
23+
}
24+
25+
key() {
26+
echo "${1:?Missing MATRIX}-${2:?Missing ROLE}"
27+
}
28+
29+
get() {
30+
local key version
31+
key="$(key "$@")"
32+
version="$(KEY="$key" perl -ne 'print "$1\n" if m/^\Q$ENV{KEY}\E\s*=\s*"([^"]+)"/' "$catalog")"
33+
if [[ -z "$version" ]]; then
34+
echo "No version for $key in $catalog" >&2
35+
exit 1
36+
fi
37+
echo "$version"
38+
}
39+
40+
set_version() {
41+
local key
42+
key="$(key "$1" "$2")"
43+
local version="${3:?Missing VERSION}"
44+
get "$1" "$2" > /dev/null
45+
KEY="$key" VERSION="$version" perl -pi -e 's/^(\Q$ENV{KEY}\E\s*=\s*")[^"]+(")/${1}$ENV{VERSION}${2}/' "$catalog"
46+
}
47+
48+
# Whether pre-release version $1 is newer than stable version $2. A pre-release precedes the release
49+
# of its base version (1.12.0-RC < 1.12.0), so only its base version is compared. Comparing the full
50+
# versions with `sort -V` would rank 1.12.0-RC above 1.12.0.
51+
is_newer_preview() {
52+
local base="${1%%-*}"
53+
[[ "$base" != "$2" && "$(printf '%s\n%s\n' "$base" "$2" | sort -V | tail -n 1)" == "$base" ]]
54+
}
55+
56+
extra_versions() {
57+
local stable preview
58+
stable="$(get "${1:?Missing MATRIX}" stable)"
59+
preview="$(get "$1" preview)"
60+
echo "stable $stable"
61+
if is_newer_preview "$preview" "$stable"; then
62+
echo "preview $preview"
63+
fi
64+
}
65+
66+
changed_roles() {
67+
local base="${1:?Missing BASE}" head="${2:?Missing HEAD}" matrix="${3:?Missing MATRIX}"
68+
git diff --unified=0 "$base" "$head" -- "$catalog" \
69+
| MATRIX="$matrix" perl -ne 'print "$1\n" if m/^[-+]\Q$ENV{MATRIX}\E-(\w+)\s*=\s*"/' \
70+
| sort -u
71+
}
72+
73+
case "${1:-}" in
74+
get) get "${2:-}" "${3:-}" ;;
75+
set) set_version "${2:-}" "${3:-}" "${4:-}" ;;
76+
extra-versions) extra_versions "${2:-}" ;;
77+
changed-roles) changed_roles "${2:-}" "${3:-}" "${4:-}" ;;
78+
*) usage ;;
79+
esac

0 commit comments

Comments
 (0)