Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 206 additions & 35 deletions .github/workflows/debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,46 +133,42 @@ jobs:

echo "Jira ticket $JIRA_TICKET exists"

build_apk:
name: Build Universal APK
# The checks run here, on a second runner at the same time as build_apk, instead of before the
# assemble (ADFA-6958). build_apk publishes nothing until this job has passed (its step "Wait
# for the checks to pass"), so "Build Universal APK", the check branch protection requires,
# still fails when a check fails.
# Each machine hosts three runners, so this job often shares one with a build job. --max-workers=2
# keeps it to two of the machine's cores; it is off the critical path, so its own time matters less.
checks:
# build_apk's CHECKS_JOB repeats this name; change both together.
name: Run checks (API, unit tests, Spotless)
runs-on: self-hosted
timeout-minutes: 60
timeout-minutes: 30
needs: [ check_changes, validate_branch ]
if: needs.check_changes.outputs.must_build == 'true'
env:
INCLUDE_LLAMA_ASSETS: "false"
# Passed as -Dorg.gradle.jvmargs, which replaces that line in gradle.properties, so it repeats
# the line's other flags. These checks need far less heap than the APK build's 8 GB each for
# Gradle and Kotlin. Three runners share each machine (the one measured has 30 GB and no
# swap), and Gradle and Kotlin processes have been killed there when builds overlapped
# (ADFA-7325). If a check runs out of memory, raise the limit here. Gradle's message points
# at org.gradle.jvmargs in gradle.properties, which this value overrides; Kotlin's points at
# kotlin.daemon.jvmargs, which would override this value in every job.
CHECKS_JVMARGS: >-
-Xmx3g -Dkotlin.daemon.jvm.options=-Xmx2g -XX:+HeapDumpOnOutOfMemoryError
--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED
--add-opens java.base/java.io=ALL-UNNAMED

steps:

- name: Cancel previous runs
uses: styfle/cancel-workflow-action@0.12.1
with:
access_token: ${{ github.token }}

- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0

- name: Validate branch name length
run: |
BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
BRANCH_LENGTH=${#BRANCH_NAME}
echo "Branch name: $BRANCH_NAME"
echo "Branch name length: $BRANCH_LENGTH characters"

if [ $BRANCH_LENGTH -gt 80 ]; then
echo "ERROR: Branch name exceeds the 80 character limit ($BRANCH_LENGTH characters)"
echo "This causes Google Cloud authentication to fail due to subject mapping limits."
echo "Please rename your branch to 80 characters or fewer and try again."
exit 1
fi

echo "Branch name length is valid ($BRANCH_LENGTH ≤ 80 characters)"

- name: Check if Nix is installed
id: check_nix
run: |
if command -v nix >/dev/null 2>&1; then
echo "nix is installed"
Expand All @@ -195,21 +191,21 @@ jobs:

- name: Verify plugin-api binary compatibility
run: |
flox activate -d flox/base -- ./gradlew :plugin-api:apiCheck --no-daemon
flox activate -d flox/base -- ./gradlew :plugin-api:apiCheck --no-daemon --max-workers=2 "-Dorg.gradle.jvmargs=$CHECKS_JVMARGS"

# testDebugUnitTest, not testV8DebugUnitTest: :plugin-api declares no product flavors, so the
# v8 task every other module has does not exist here. Named as its own step rather than left
# to jacocoAggregateReport, which is not on the PR path at all.
- name: Run plugin-api unit tests
run: |
flox activate -d flox/base -- ./gradlew :plugin-api:testDebugUnitTest --no-daemon
flox activate -d flox/base -- ./gradlew :plugin-api:testDebugUnitTest --no-daemon --max-workers=2 "-Dorg.gradle.jvmargs=$CHECKS_JVMARGS"

# The SQLite debugger's Kotlin tests (EventDecoder, McpProtocol, McpHttp, DatabaseTools). Its own
# workflow, test-sqlite-debugger.yml, runs only test.sh (the C and JNI tests) on ubuntu-latest. Like
# :plugin-api it has no product flavors, so the task is testDebugUnitTest.
- name: Run sqlite-debugger unit tests
run: |
flox activate -d flox/base -- ./gradlew :subprojects:sqlite-debugger:testDebugUnitTest --no-daemon
flox activate -d flox/base -- ./gradlew :subprojects:sqlite-debugger:testDebugUnitTest --no-daemon --max-workers=2 "-Dorg.gradle.jvmargs=$CHECKS_JVMARGS"

# Combined with a compile task on purpose: spotlessCheck alone never pulls a
# source-tree-writing task into the graph, so the implicit-dependency failure ADFA-5244 fixed
Expand All @@ -220,36 +216,180 @@ jobs:
# Two tasks, so two possible causes: the message must not name one of them. Blaming
# Spotless for a compile error is the exact misdiagnosis this step exists to catch.
set +e
flox activate -d flox/base -- ./gradlew :common:compileV8DebugKotlin spotlessCheck --no-daemon
flox activate -d flox/base -- ./gradlew :common:compileV8DebugKotlin spotlessCheck --no-daemon --max-workers=2 "-Dorg.gradle.jvmargs=$CHECKS_JVMARGS"
status=$?
set -e
if [ "$status" -ne 0 ]; then
echo "::error::Gradle failed on ':common:compileV8DebugKotlin spotlessCheck'. If the output above shows formatting violations, run './gradlew spotlessApply' locally and commit the result; if it shows a compile error, spotlessApply will not help. The Gradle output says which."
exit "$status"
fi

- name: Cleanup google-services.json
if: always()
run: |
rm -f app/google-services.json
echo "google-services.json cleaned up successfully"

build_apk:
name: Build Universal APK
runs-on: self-hosted
# "Wait for the checks to pass" gives up 5 minutes before this timeout; change both together.
Comment thread
hal-eisen-adfa marked this conversation as resolved.
Resolved
timeout-minutes: 60
needs: [ check_changes, validate_branch ]
Comment thread
hal-eisen-adfa marked this conversation as resolved.
Resolved
if: needs.check_changes.outputs.must_build == 'true'
env:
INCLUDE_LLAMA_ASSETS: "false"
# The checks job's name, which the abort in "Assemble Universal APK" and "Wait for the checks
# to pass" look up. A mismatch disables the abort without a message, and the wait fails only
# at its deadline.
CHECKS_JOB: Run checks (API, unit tests, Spotless)

steps:

# For "Wait for the checks to pass", which must give up before this job's timeout.
- name: Record the job start time
run: echo "JOB_STARTED_AT=$(date +%s)" >> "$GITHUB_ENV"

- name: Cancel previous runs
uses: styfle/cancel-workflow-action@0.12.1
with:
access_token: ${{ github.token }}

- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0

- name: Validate branch name length
run: |
BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
BRANCH_LENGTH=${#BRANCH_NAME}
echo "Branch name: $BRANCH_NAME"
echo "Branch name length: $BRANCH_LENGTH characters"

if [ $BRANCH_LENGTH -gt 80 ]; then
echo "ERROR: Branch name exceeds the 80 character limit ($BRANCH_LENGTH characters)"
echo "This causes Google Cloud authentication to fail due to subject mapping limits."
echo "Please rename your branch to 80 characters or fewer and try again."
exit 1
fi

echo "Branch name length is valid ($BRANCH_LENGTH ≤ 80 characters)"

- name: Check if Nix is installed
id: check_nix
run: |
if command -v nix >/dev/null 2>&1; then
echo "nix is installed"
echo "nix_installed=true" >> $GITHUB_ENV
else
echo "nix is not installed"
echo "nix_installed=false" >> $GITHUB_ENV
fi

- name: Install Flox
if: env.nix_installed == 'false'
uses: flox/install-flox-action@v2

- name: Create google-services.json
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: |
echo "$GOOGLE_SERVICES_JSON" > app/google-services.json
echo "google-services.json created successfully"

# advzip runs only for stage builds; see the assemble step.
- name: Install advancecomp (advzip, used by recompressApk)
if: github.ref_name == 'stage'
run: |
command -v advzip || { sudo apt-get update && sudo apt-get install -y advancecomp; }

# For "Assemble Universal APK", which polls the checks job, and for the publish steps.
- name: Install jq
run: command -v jq || { sudo apt-get update && sudo apt-get install -y jq; }

# The checks job starts with this one and normally ends within minutes. If it fails, this build
# can no longer be published, so it is stopped instead of holding a self-hosted runner for the
# rest of its ten minutes (ADFA-6958). "Wait for the checks to pass" below still decides whether
# to publish when the build finishes first.
- name: Assemble Universal APK
env:
GH_TOKEN: ${{ github.token }}
run: |
set -o pipefail
# advzip (in recompressApk) only for stage, the debug builds most testers install. Elsewhere
# it costs 200-300 s to save about 3.7% of the APK (ADFA-6957).
advzip=()
if [ "$GITHUB_REF_NAME" = stage ]; then advzip=(-Padvzip); fi
flox activate -d flox/base -- ./gradlew :app:assembleV8Debug --no-daemon "${advzip[@]}" 2>&1 | tee "$RUNNER_TEMP/assemble.log"

# Stops a process and everything below it: TERM, then up to 30 s for them to exit, then KILL
# for any left (not waited for; KILL cannot be ignored). So the step never ends with Gradle
# still running. Gradle's single-use daemon is a child of its client, so this reaches it
# too. A zombie counts as gone.
descendants() {
local child
for child in $(pgrep -P "$1"); do echo "$child"; descendants "$child"; done
}
running() {
local state
state=$(ps -o stat= -p "$1" 2>/dev/null) || return 1
[ -n "$state" ] && [ "${state#Z}" = "$state" ]
}
kill_tree() {
local pids p alive
pids="$1 $(descendants "$1")"
for p in $pids; do kill -TERM "$p" 2>/dev/null || true; done
for _ in $(seq 30); do
alive=false
for p in $pids; do if running "$p"; then alive=true; fi; done
$alive || return 0
sleep 1
done
for p in $pids; do kill -KILL "$p" 2>/dev/null || true; done
}

(
set -o pipefail
flox activate -d flox/base -- ./gradlew :app:assembleV8Debug --no-daemon "${advzip[@]}" 2>&1 | tee "$RUNNER_TEMP/assemble.log"
) &
build=$!
# A cancelled or timed-out job must not leave the build running.
trap 'kill_tree "$build"' EXIT INT TERM

url="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/jobs?filter=latest&per_page=100"
watching=true
while kill -0 "$build" 2>/dev/null; do
if $watching; then
# filter=latest: after "Re-run failed jobs", the newest attempt of the checks job counts.
state=$(curl -fsS --max-time 30 -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" "$url" \
| jq -r --arg name "$CHECKS_JOB" '.jobs[] | select(.name == $name) | "\(.status) \(.conclusion)"') || state=""
case "$state" in
"completed success") watching=false ;;
completed\ *)
echo "::error::The job '$CHECKS_JOB' ended with '${state#completed }' while this build was still running, so the build was stopped and nothing will be published. Its log shows which check failed. To retry, use \"Re-run failed jobs\"."
kill_tree "$build"
wait "$build" 2>/dev/null || true
Comment thread
hal-eisen-adfa marked this conversation as resolved.
Resolved
# The build is reaped; without this the EXIT trap would signal its pid again.
trap - EXIT INT TERM
exit 1
;;
esac
fi
# Look again in 30 s, but notice the build ending within a second.
for _ in $(seq 30); do kill -0 "$build" 2>/dev/null || break; sleep 1; done
done
status=0
wait "$build" || status=$?
trap - EXIT INT TERM
[ "$status" -eq 0 ] || exit "$status"

# D8 logs this (non-fatal) once per class when the pinned R8 is older than the Kotlin
# metadata version, burying every real diagnostic. See the `r8` pin in libs.versions.toml.
if grep -q "Unexpected error during rewriting of Kotlin metadata" "$RUNNER_TEMP/assemble.log"; then
echo "::error::D8 could not rewrite Kotlin metadata. Most likely the R8 pinned in gradle/libs.versions.toml is older than the Kotlin metadata version (bump 'r8'), or the pin no longer takes effect on the build classpath. See ADFA-6822."
exit 1
fi


- name: Find APK file
id: find_apk
run: |
Expand All @@ -270,9 +410,6 @@ jobs:
fi
echo "BUILD_TYPE=$BUILD_TYPE" >> $GITHUB_ENV

- name: Install jq
run: command -v jq || { sudo apt-get update && sudo apt-get install -y jq; }

- name: Get PR and Commit Information
id: pr_info
run: |
Expand Down Expand Up @@ -342,6 +479,40 @@ jobs:
echo "JIRA_TITLE=$JIRA_TITLE" >> $GITHUB_OUTPUT
echo "JIRA_URL=$JIRA_URL" >> $GITHUB_OUTPUT

# Publish nothing until the checks job has passed. It started with this job and is much
# shorter, so this normally returns at once. filter=latest: after "Re-run failed jobs", the
# checks job's newest attempt counts, not the failed one. It gives up 5 minutes before this
# job's 60-minute timeout, which leaves time for the publish steps: a timeout during them
# could upload to App Tester without the Jira and Slack steps.
- name: Wait for the checks to pass
env:
GH_TOKEN: ${{ github.token }}
run: |
url="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/jobs?filter=latest&per_page=100"
deadline=$((JOB_STARTED_AT + (60 - 5) * 60))
while :; do
state=$(curl -fsS --max-time 30 -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" "$url" \
| jq -r --arg name "$CHECKS_JOB" '.jobs[] | select(.name == $name) | "\(.status) \(.conclusion)"') || state=""
case "$state" in
"completed success") ;;
completed\ *)
echo "::error::The job '$CHECKS_JOB' ended with '${state#completed }', so nothing was published. Its log shows which check failed. To retry, use \"Re-run failed jobs\": re-running only one of the two jobs leaves this one failed."
exit 1
;;
esac
# Before accepting success too: a build that gets here late must not start publishing.
if [ "$(date +%s)" -ge "$deadline" ]; then
echo "::error::Too close to this job's timeout to publish safely (job '$CHECKS_JOB': '${state:-not found}'), so nothing was published."
exit 1
fi
if [ "$state" = "completed success" ]; then
echo "The checks passed."
exit 0
fi
echo "Job '$CHECKS_JOB': ${state:-not found yet}; checking again in 15 s"
sleep 15
done

- name: Authenticate to Google Cloud via Workload Identity
uses: google-github-actions/auth@v2
with:
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ android.nonTransitiveRClass=false
android.useAndroidX=true
org.gradle.caching=true
org.gradle.configureondemand=true
# Workflows that pass -Dorg.gradle.jvmargs replace this whole line, not just the heap size:
# CHECKS_JVMARGS in .github/workflows/debug.yml, release.yml and generate_assets.yml. A flag
# added here must be added there too.
org.gradle.jvmargs=-Xmx8192M -Dkotlin.daemon.jvm.options\="-Xmx8192M" -XX\:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.lang\=ALL-UNNAMED --add-opens java.base/java.util\=ALL-UNNAMED --add-opens java.base/java.io\=ALL-UNNAMED
org.gradle.parallel=true
org.gradle.vfs.watch=true
Expand Down
2 changes: 1 addition & 1 deletion subprojects/sqlite-debugger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The layout of `sqlitedbg_event_record` lives in `sqlitedbg.h`. The JNI layer han
- **JNI test:** when a JDK is on PATH, `test.sh` also builds `libsqlitedbg.so` as it ships (no `SQLITE_CORE`) against a requery-like `libsqlite3x.so` and runs `src/test/jni/JniQueryTest.java` through `NativeBridge`: paging, the total-bytes budget, per-cell truncation, bound types, one statement per call, the deadline, refused writes and transactions, and the rollback of a transaction left open. It uses Java stubs of `NativeBridge` and `DebugEngineException` instead of the Kotlin, so a JDK is all it needs; `test.sh` checks the native names match `NativeBridge.kt`. Otherwise it is skipped with a message. CI runs `test.sh` in `.github/workflows/test-sqlite-debugger.yml` for changes under this module.
- **JVM tests:** `flox activate -d flox/local -- ./gradlew :subprojects:sqlite-debugger:testDebugUnitTest`. They cover `EventDecoder`, `McpProtocol`, `McpHttp`, `DatabaseTools` (with `FakeDebugEngine`) and `EndpointBroadcast`, its announce receiver included.

`.github/workflows/test-sqlite-debugger.yml` runs `test.sh` (the C and JNI tests) on pull requests that touch the module or the SQLite headers. The JVM tests run in `.github/workflows/debug.yml`, in the step "Run sqlite-debugger unit tests" beside the `:plugin-api` one.
`.github/workflows/test-sqlite-debugger.yml` runs `test.sh` (the C and JNI tests) on pull requests that touch the module or the SQLite headers. The JVM tests run in `.github/workflows/debug.yml`, in the job "Run checks (API, unit tests, Spotless)", step "Run sqlite-debugger unit tests", beside the `:plugin-api` one.

## Not done yet

Expand Down
Loading