mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-10 18:07:24 +01:00
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
30 lines
1.1 KiB
Bash
Executable File
30 lines
1.1 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)
|
|
|
|
pkgs=()
|
|
full=0
|
|
for f in "${CHANGED[@]}"; do
|
|
case "$f" in
|
|
go.mod | go.sum) full=1 ;;
|
|
*.go) pkgs+=("./$(dirname "$f")") ;;
|
|
esac
|
|
done
|
|
|
|
if [[ $full -eq 0 && ${#pkgs[@]} -eq 0 ]]; then echo "no go changes: nothing to test"; exit 0; fi
|
|
if [[ $full -eq 1 ]]; then echo "module changed: running full suite"; go test ./...; exit $?; fi
|
|
mapfile -t uniq < <(printf '%s\n' "${pkgs[@]}" | sort -u)
|
|
go test "${uniq[@]}"
|