feat(tools): pre_pr.sh runs the CI checks the fast loop skips, for what the branch changes (#3119)

* feat(tools): pre_pr.sh runs the CI checks the fast loop skips, for what the branch changes

* fix(tools): pre_pr.sh checks authorship with no file changes and skips deleted tests

* docs(agents): pre_pr.sh picks tests by name

* docs(agents): pre_pr.sh compiles and lints only for app changes
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-24 04:45:54 -05:00
1 parent 1534cf1c93
commit e2d87c5083
2 files changed
+85

No files matched your search

+1
View File
@@ -27,6 +27,7 @@
# CI
- Before pushing a PR, run `tools/pre_pr.sh`. It checks authorship and the merge onto `main`, then, when app sources change, compiles and runs lint as CI does. It picks tests by name: `<File>*Test` for changed Kotlin files, and `tools/tests` modules that mention a changed path. Add any other tests that cover your change, and leave the full suites to CI.
- CI builds the PR merged onto `main`. Before pushing, merge or rebase onto `origin/main` and compile: most "works locally" Kotlin failures come from that merge.
- Before a PR that touches strings or resources, run `./gradlew :app:lintVitalRelease`. The fast loop skips lint, and lint catches `ExtraTranslation` and missing-locale errors.
- Commit messages and PR bodies must not carry `Co-Authored-By` or other bot trailers. `tools/release/check_authorship.py` fails the build on them.
+84
View File
@@ -0,0 +1,84 @@
#!/usr/bin/env bash
# Runs the CI checks the fast deploy loop skips, limited to what this branch changes.
set -euo pipefail
repo_root=$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
cd "${repo_root}"
base_ref=${1:-origin/main}
git fetch -q origin main 2>/dev/null || echo "Could not fetch origin/main; comparing with the local copy." >&2
base=$(git merge-base "${base_ref}" HEAD)
changed=()
while IFS= read -r path; do changed+=("${path}"); done \
< <({ git diff --name-only "${base}"; git ls-files --others --exclude-standard; } | sort -u)
failed=()
run() {
local name=$1
shift
echo "== ${name}"
if "$@"; then echo "ok: ${name}"; else failed+=("${name}"); echo "FAILED: ${name}"; fi
}
run "human authorship" python3 tools/release/check_authorship.py "${base}..HEAD"
if [[ ${#changed[@]} -eq 0 ]]; then
[[ ${#failed[@]} -eq 0 ]] || exit 1
echo "No files differ from ${base_ref}."
exit 0
fi
behind=$(git rev-list --count "HEAD..${base_ref}")
if [[ "${behind}" != 0 ]]; then
echo "== merge onto ${base_ref}"
if git merge-tree --write-tree HEAD "${base_ref}" >/dev/null 2>&1; then
echo "${behind} commits behind ${base_ref}. CI compiles the merge, so rebase before pushing if they touch code you use."
else
failed+=("merge onto ${base_ref}")
echo "FAILED: the branch conflicts with ${base_ref}; CI cannot merge it."
fi
fi
app=0 settings=0
tests=() python_tests=()
for path in "${changed[@]}"; do
case "${path}" in
app/src/main/*|app/build.gradle|gradle.properties|gradle/*) app=1 ;;
app/src/test/*Test.kt) app=1; [[ ! -f "${path}" ]] || tests+=("$(basename "${path}" .kt)") ;;
esac
case "${path}" in
*/SettingsIndex.kt) settings=1 ;;
esac
if [[ "${path}" == app/src/main/java/*.kt && -f "${path}" ]]; then
while IFS= read -r test; do tests+=("$(basename "${test}" .kt)"); done \
< <(find app/src/test -name "$(basename "${path}" .kt)*Test.kt")
fi
if [[ "${path}" == tools/tests/test_*.py ]]; then
[[ ! -f "${path}" ]] || python_tests+=("${path}")
elif [[ "${path}" == tools/* && "${path}" != tools/tests/* ]]; then
while IFS= read -r test; do python_tests+=("${test}"); done \
< <(grep -lF "${path#tools/}" tools/tests/test_*.py 2>/dev/null || true)
fi
done
[[ "${settings}" == 0 ]] || tests+=(SettingsMapTest)
if [[ "${app}" == 1 ]]; then
gradle_tasks=(:app:compileReleaseKotlin :app:lintVitalRelease)
test_args=()
if [[ ${#tests[@]} -gt 0 ]]; then
gradle_tasks+=(:app:testReleaseUnitTest)
for test in $(printf '%s\n' "${tests[@]}" | sort -u); do test_args+=(--tests "*.${test}"); done
fi
run "Kotlin, lint and $((${#test_args[@]} / 2)) unit test classes" \
./gradlew -q -PskipRust=true -PallowStaleRuntime=true "${gradle_tasks[@]}" ${test_args[@]+"${test_args[@]}"}
fi
if [[ ${#python_tests[@]} -gt 0 ]]; then
modules=()
while IFS= read -r test; do modules+=("tools.tests.$(basename "${test}" .py)"); done \
< <(printf '%s\n' "${python_tests[@]}" | sort -u)
run "${#modules[@]} Python test modules" python3 -m unittest "${modules[@]}"
fi
if [[ ${#failed[@]} -gt 0 ]]; then
printf 'Failed: %s\n' "${failed[@]}" >&2
exit 1
fi
echo "Pre-PR checks passed. CI still runs the full suites."