feat: make script project-agnostic with configurable directories
- Add --frontend and --backend flags for custom directory paths - Auto-detect common frontend directory patterns if not specified - Default backend to repository root if not specified - Replace hardcoded 'rfc-edge-frontend' with dynamic variables - Support any project structure with pnpm frontend and Rust backend Examples: check-history.sh 2 4 # auto-detect check-history.sh 2 4 --frontend web --backend . # custom dirs check-history.sh 2 4 --backend server -j8 # no frontend 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
115
check-history.sh
115
check-history.sh
@@ -4,16 +4,24 @@ set -euo pipefail
|
|||||||
# Usage:
|
# Usage:
|
||||||
# check-history.sh <start_offset> <count> [OPTIONS]
|
# check-history.sh <start_offset> <count> [OPTIONS]
|
||||||
# Example:
|
# Example:
|
||||||
# check-history.sh 2 4 # checks commits 2,3,4,5
|
# check-history.sh 2 4 # checks commits 2,3,4,5
|
||||||
# check-history.sh 5 1 -v # verbose mode
|
# check-history.sh 5 1 -v # verbose mode
|
||||||
# check-history.sh 2 28 -j4 # check 28 commits, 4 at a time
|
# check-history.sh 2 28 -j4 # check 28 commits, 4 at a time
|
||||||
|
# check-history.sh 2 4 --frontend web --backend . # custom directories
|
||||||
|
|
||||||
VERBOSE=0
|
VERBOSE=0
|
||||||
JOBS=1
|
JOBS=1
|
||||||
|
FRONTEND_DIR=""
|
||||||
|
BACKEND_DIR=""
|
||||||
|
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
if [ $# -lt 2 ]; then
|
if [ $# -lt 2 ]; then
|
||||||
echo "Usage: $0 <start_offset_from_head> <count> [--verbose|-v] [-j|--jobs N]"
|
echo "Usage: $0 <start_offset_from_head> <count> [OPTIONS]"
|
||||||
|
echo "Options:"
|
||||||
|
echo " -v, --verbose Enable verbose debug logging"
|
||||||
|
echo " -j, --jobs N Run N jobs in parallel"
|
||||||
|
echo " --frontend DIR Frontend directory to build (default: auto-detect)"
|
||||||
|
echo " --backend DIR Backend directory to check (default: repository root)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -40,9 +48,25 @@ while [ $# -gt 0 ]; do
|
|||||||
fi
|
fi
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--frontend)
|
||||||
|
if [ $# -lt 2 ]; then
|
||||||
|
echo "Error: --frontend requires a directory path" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
FRONTEND_DIR="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--backend)
|
||||||
|
if [ $# -lt 2 ]; then
|
||||||
|
echo "Error: --backend requires a directory path" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
BACKEND_DIR="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Error: Unknown option $1" >&2
|
echo "Error: Unknown option $1" >&2
|
||||||
echo "Usage: $0 <start_offset_from_head> <count> [--verbose|-v] [-j|--jobs N]"
|
echo "Usage: $0 <start_offset_from_head> <count> [OPTIONS]"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -55,6 +79,24 @@ debug() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Auto-detect frontend directory if not specified
|
||||||
|
if [ -z "$FRONTEND_DIR" ]; then
|
||||||
|
# Try common frontend directory patterns
|
||||||
|
for dir in "frontend" "web" "client" "ui" "app" "*-frontend"; do
|
||||||
|
if [ -d "$dir" ] && [ -f "$dir/package.json" ]; then
|
||||||
|
FRONTEND_DIR="$dir"
|
||||||
|
debug "Auto-detected frontend directory: $FRONTEND_DIR"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Default backend to repository root if not specified
|
||||||
|
if [ -z "$BACKEND_DIR" ]; then
|
||||||
|
BACKEND_DIR="."
|
||||||
|
debug "Using repository root as backend directory"
|
||||||
|
fi
|
||||||
|
|
||||||
# Convert user-friendly 1-indexed "Nth from HEAD" into 0-indexed offset
|
# Convert user-friendly 1-indexed "Nth from HEAD" into 0-indexed offset
|
||||||
START_OFFSET="$(( START_ARG - 1 ))"
|
START_OFFSET="$(( START_ARG - 1 ))"
|
||||||
COUNT="$COUNT_ARG"
|
COUNT="$COUNT_ARG"
|
||||||
@@ -118,10 +160,12 @@ done
|
|||||||
# Frontend builder
|
# Frontend builder
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
build_frontend() {
|
build_frontend() {
|
||||||
|
local frontend_dir="$1"
|
||||||
|
|
||||||
(
|
(
|
||||||
[ "$VERBOSE" -eq 1 ] && echo "[BUILD_DEBUG] Entering rfc-edge-frontend directory" || true
|
[ "$VERBOSE" -eq 1 ] && echo "[BUILD_DEBUG] Entering $frontend_dir directory" || true
|
||||||
cd rfc-edge-frontend || {
|
cd "$frontend_dir" || {
|
||||||
echo "❌ Failed to cd into rfc-edge-frontend"
|
echo "❌ Failed to cd into $frontend_dir"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
[ "$VERBOSE" -eq 1 ] && echo "[BUILD_DEBUG] cd succeeded, PWD=$PWD" || true
|
[ "$VERBOSE" -eq 1 ] && echo "[BUILD_DEBUG] cd succeeded, PWD=$PWD" || true
|
||||||
@@ -131,9 +175,9 @@ build_frontend() {
|
|||||||
export PNPM_HARD_LINKS=false
|
export PNPM_HARD_LINKS=false
|
||||||
|
|
||||||
# Copy .env file from main repo if it exists and isn't present in worktree
|
# Copy .env file from main repo if it exists and isn't present in worktree
|
||||||
if [ ! -f .env ] && [ -f "$REPO_ROOT/rfc-edge-frontend/.env" ]; then
|
if [ ! -f .env ] && [ -f "$REPO_ROOT/$frontend_dir/.env" ]; then
|
||||||
[ "$VERBOSE" -eq 1 ] && echo "[BUILD_DEBUG] Copying .env file from main repo" || true
|
[ "$VERBOSE" -eq 1 ] && echo "[BUILD_DEBUG] Copying .env file from main repo" || true
|
||||||
cp "$REPO_ROOT/rfc-edge-frontend/.env" .env
|
cp "$REPO_ROOT/$frontend_dir/.env" .env
|
||||||
elif [ -f .env ]; then
|
elif [ -f .env ]; then
|
||||||
[ "$VERBOSE" -eq 1 ] && echo "[BUILD_DEBUG] .env file already exists in worktree" || true
|
[ "$VERBOSE" -eq 1 ] && echo "[BUILD_DEBUG] .env file already exists in worktree" || true
|
||||||
else
|
else
|
||||||
@@ -218,30 +262,41 @@ check_commit() {
|
|||||||
cd "$worktree"
|
cd "$worktree"
|
||||||
[ "$VERBOSE" -eq 1 ] && echo "[CHECK_DEBUG] In worktree, PWD=$PWD" || true
|
[ "$VERBOSE" -eq 1 ] && echo "[CHECK_DEBUG] In worktree, PWD=$PWD" || true
|
||||||
|
|
||||||
if [ -d rfc-edge-frontend ]; then
|
# Build frontend if specified
|
||||||
[ "$VERBOSE" -eq 1 ] && echo "[CHECK_DEBUG] Found rfc-edge-frontend directory" || true
|
if [ -n "$FRONTEND_DIR" ]; then
|
||||||
echo "→ Building frontend…"
|
if [ -d "$FRONTEND_DIR" ]; then
|
||||||
if ! build_frontend; then
|
[ "$VERBOSE" -eq 1 ] && echo "[CHECK_DEBUG] Found $FRONTEND_DIR directory" || true
|
||||||
echo "❌ Frontend build failed"
|
echo "→ Building frontend…"
|
||||||
exit 1
|
if ! build_frontend "$FRONTEND_DIR"; then
|
||||||
|
echo "❌ Frontend build failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
[ "$VERBOSE" -eq 1 ] && echo "[CHECK_DEBUG] Frontend build completed successfully" || true
|
||||||
|
else
|
||||||
|
[ "$VERBOSE" -eq 1 ] && echo "[CHECK_DEBUG] Frontend directory $FRONTEND_DIR not found, skipping" || true
|
||||||
fi
|
fi
|
||||||
[ "$VERBOSE" -eq 1 ] && echo "[CHECK_DEBUG] Frontend build completed successfully" || true
|
|
||||||
else
|
else
|
||||||
[ "$VERBOSE" -eq 1 ] && echo "[CHECK_DEBUG] No rfc-edge-frontend directory found, skipping frontend build" || true
|
[ "$VERBOSE" -eq 1 ] && echo "[CHECK_DEBUG] No frontend directory specified, skipping frontend build" || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if Rust files changed in this commit
|
# Check backend if Rust/Cargo files changed in this commit
|
||||||
if git diff --name-only "${commit}^..${commit}" 2>/dev/null | grep -qE '\.(rs|toml)$|Cargo\.lock'; then
|
if [ -n "$BACKEND_DIR" ]; then
|
||||||
[ "$VERBOSE" -eq 1 ] && echo "[CHECK_DEBUG] Rust files changed, running cargo check" || true
|
if git diff --name-only "${commit}^..${commit}" 2>/dev/null | grep -qE '\.(rs|toml)$|Cargo\.lock'; then
|
||||||
echo "→ Running cargo check…"
|
[ "$VERBOSE" -eq 1 ] && echo "[CHECK_DEBUG] Rust files changed, running cargo check in $BACKEND_DIR" || true
|
||||||
if ! cargo check --quiet; then
|
echo "→ Running cargo check…"
|
||||||
echo "❌ Cargo check failed"
|
cd "$BACKEND_DIR" || {
|
||||||
exit 1
|
echo "❌ Failed to cd into $BACKEND_DIR"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
if ! cargo check --quiet; then
|
||||||
|
echo "❌ Cargo check failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
[ "$VERBOSE" -eq 1 ] && echo "[CHECK_DEBUG] Cargo check completed successfully" || true
|
||||||
|
else
|
||||||
|
[ "$VERBOSE" -eq 1 ] && echo "[CHECK_DEBUG] No Rust files changed, skipping cargo check" || true
|
||||||
|
echo "→ Skipping cargo check (no Rust changes)"
|
||||||
fi
|
fi
|
||||||
[ "$VERBOSE" -eq 1 ] && echo "[CHECK_DEBUG] Cargo check completed successfully" || true
|
|
||||||
else
|
|
||||||
[ "$VERBOSE" -eq 1 ] && echo "[CHECK_DEBUG] No Rust files changed, skipping cargo check" || true
|
|
||||||
echo "→ Skipping cargo check (no Rust changes)"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "✓ OK"
|
echo "✓ OK"
|
||||||
@@ -258,7 +313,7 @@ TOTAL=${#COMMITS[@]}
|
|||||||
|
|
||||||
# Export functions and variables for parallel execution
|
# Export functions and variables for parallel execution
|
||||||
export -f check_commit build_frontend debug
|
export -f check_commit build_frontend debug
|
||||||
export VERBOSE REPO_ROOT PNPM_STORE WORKTREES_DIR LOGS_DIR
|
export VERBOSE REPO_ROOT PNPM_STORE WORKTREES_DIR LOGS_DIR FRONTEND_DIR BACKEND_DIR
|
||||||
|
|
||||||
# Process a single commit (for xargs)
|
# Process a single commit (for xargs)
|
||||||
process_commit() {
|
process_commit() {
|
||||||
|
|||||||
Reference in New Issue
Block a user