mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-21 21:02:18 +01:00
Some checks are pending
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,dependency-freshness) (push) Waiting to run
Tests / test (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
A bare targeted flutter test on the shared /tmp held a build slot 67 s under the build queue (perf.heavybuild, 2026-11-21) against ~4 s alone. Match the ci_mirror.sh shards: own TMPDIR, --concurrency=2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
81 lines
3.2 KiB
Bash
Executable File
81 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# ============================================================================
|
|
# Run only the tests related to files changed vs HEAD (staged, unstaged and
|
|
# untracked). Quiet: failures plus a one-line summary. Falls back to the full
|
|
# suite when a change cannot be mapped to tests. Generated by repo_contract.
|
|
# ============================================================================
|
|
|
|
set -euo pipefail
|
|
|
|
cd "$(git rev-parse --show-toplevel)"
|
|
CHANGED=()
|
|
while IFS= read -r f; do
|
|
[[ -n "$f" && -e "$f" ]] && CHANGED+=("$f")
|
|
done < <({ git diff --name-only HEAD 2>/dev/null || true; git ls-files --others --exclude-standard; } | sort -u)
|
|
|
|
# --no-cov: a subset cannot meet the 100% bar, and the term-missing table is noise.
|
|
pytest_run() {
|
|
local py=python3
|
|
[[ -x .venv/bin/python ]] && py=.venv/bin/python
|
|
"$py" -m pytest --no-cov -p no:sugar "$@"
|
|
}
|
|
|
|
# Dart changes map to app/test/<name>_test.dart; any other app/ change runs the app suite.
|
|
# A private TMPDIR and two isolates, as each ci_mirror.sh shard does: on the
|
|
# shared /tmp a 3-file run stalled to 67 s in the build queue (2026-11-21)
|
|
# against ~4 s alone, and the default isolate count overruns capped.sh's 2 GiB.
|
|
flutter_run() {
|
|
local tmp status=0
|
|
tmp="$(mktemp -d "${XDG_CACHE_HOME:-$HOME/.cache}/diet-guard-flutter-test.XXXXXX")"
|
|
(cd app && TMPDIR="$tmp" flutter test --reporter=compact \
|
|
--concurrency="${FLUTTER_TEST_CONCURRENCY:-2}" "$@") || status=$?
|
|
rm -rf -- "$tmp"
|
|
return "$status"
|
|
}
|
|
|
|
if grep -qs testmon pyproject.toml requirements*.txt; then
|
|
pytest_run --testmon -q --tb=short; exit $?
|
|
fi
|
|
|
|
full=0
|
|
tests=()
|
|
dart_tests=()
|
|
dart_full=0
|
|
for f in "${CHANGED[@]}"; do
|
|
case "$f" in
|
|
*/conftest.py | conftest.py | pyproject.toml | requirements*.txt | pytest.ini | setup.cfg) full=1 ;;
|
|
app/test/*_test.dart) dart_tests+=("${f#app/}") ;;
|
|
app/lib/*.dart)
|
|
base="$(basename "$f" .dart)"
|
|
while IFS= read -r t; do dart_tests+=("${t#app/}"); done \
|
|
< <(git ls-files "app/test/*${base}_test.dart")
|
|
[[ ${#dart_tests[@]} -eq 0 ]] && dart_full=1
|
|
;;
|
|
app/pubspec.yaml | app/pubspec.lock) dart_full=1 ;;
|
|
*.py)
|
|
base="$(basename "$f" .py)"
|
|
if [[ "$base" == test_* || "$base" == *_test ]]; then
|
|
tests+=("$f")
|
|
else
|
|
while IFS= read -r t; do tests+=("$t"); done \
|
|
< <(git ls-files "*test_${base}.py" "*${base}_test.py")
|
|
fi
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ ${#CHANGED[@]} -eq 0 ]]; then echo "no changes vs HEAD: nothing to test"; exit 0; fi
|
|
rc=0
|
|
if [[ $dart_full -eq 1 ]]; then flutter_run || rc=1
|
|
elif [[ ${#dart_tests[@]} -gt 0 ]]; then flutter_run "${dart_tests[@]}" || rc=1; fi
|
|
if [[ $full -eq 1 ]]; then
|
|
echo "config changed: running full python suite"; pytest_run -q -n auto || rc=1
|
|
elif [[ ${#tests[@]} -gt 0 ]]; then pytest_run -q --tb=short "${tests[@]}" || rc=1
|
|
elif printf '%s\n' "${CHANGED[@]}" | grep -q '\.py$'; then
|
|
echo "no mapped python tests: running full python suite"; pytest_run -q -n auto --tb=short || rc=1
|
|
elif [[ $dart_full -eq 0 && ${#dart_tests[@]} -eq 0 ]]; then
|
|
echo "no python/dart changes: nothing to test"
|
|
fi
|
|
exit "$rc"
|