docs: add session preflight and expand lint scope batch5
This commit is contained in:
81
scripts/session/preflight.sh
Executable file
81
scripts/session/preflight.sh
Executable file
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
EXPECTED_ROOT="${EXPECTED_ROOT:-/Users/apple/github-projects/microdao-daarion}"
|
||||
REQUIRE_SESSION_STARTER=1
|
||||
|
||||
usage() {
|
||||
cat <<'USAGE'
|
||||
Usage:
|
||||
bash scripts/session/preflight.sh [--expected-root /path/to/repo] [--no-session-starter]
|
||||
|
||||
Checks:
|
||||
- current working directory
|
||||
- git repository root
|
||||
- current branch
|
||||
- latest commit
|
||||
- docs/SESSION_STARTER.md presence (default required)
|
||||
- docs directory presence
|
||||
|
||||
Exit codes:
|
||||
0 all checks passed
|
||||
10 wrong repo root
|
||||
11 missing SESSION_STARTER.md
|
||||
12 missing docs directory
|
||||
13 git not initialized / not a repo
|
||||
USAGE
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--expected-root)
|
||||
EXPECTED_ROOT="$2"
|
||||
shift 2
|
||||
;;
|
||||
--no-session-starter)
|
||||
REQUIRE_SESSION_STARTER=0
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown arg: $1" >&2
|
||||
usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if ! git_root="$(git rev-parse --show-toplevel 2>/dev/null)"; then
|
||||
echo "[FAIL] not a git repository" >&2
|
||||
exit 13
|
||||
fi
|
||||
|
||||
pwd_now="$(pwd)"
|
||||
branch="$(git branch --show-current || true)"
|
||||
head_line="$(git log --oneline -n 1 2>/dev/null || echo 'NO_COMMITS')"
|
||||
|
||||
printf "[INFO] pwd: %s\n" "$pwd_now"
|
||||
printf "[INFO] git_root: %s\n" "$git_root"
|
||||
printf "[INFO] branch: %s\n" "${branch:-DETACHED_OR_NONE}"
|
||||
printf "[INFO] head: %s\n" "$head_line"
|
||||
printf "[INFO] expected_root: %s\n" "$EXPECTED_ROOT"
|
||||
|
||||
if [[ "$git_root" != "$EXPECTED_ROOT" ]]; then
|
||||
echo "[FAIL] unexpected repository root" >&2
|
||||
exit 10
|
||||
fi
|
||||
|
||||
if [[ ! -d "$git_root/docs" ]]; then
|
||||
echo "[FAIL] missing docs directory: $git_root/docs" >&2
|
||||
exit 12
|
||||
fi
|
||||
|
||||
if [[ "$REQUIRE_SESSION_STARTER" -eq 1 && ! -f "$git_root/docs/SESSION_STARTER.md" ]]; then
|
||||
echo "[FAIL] missing SESSION_STARTER: $git_root/docs/SESSION_STARTER.md" >&2
|
||||
exit 11
|
||||
fi
|
||||
|
||||
echo "[PASS] preflight OK"
|
||||
Reference in New Issue
Block a user