-
Notifications
You must be signed in to change notification settings - Fork 556
Expand file tree
/
Copy pathwatch_and_run.sh
More file actions
51 lines (43 loc) · 1.72 KB
/
Copy pathwatch_and_run.sh
File metadata and controls
51 lines (43 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# =============================================================================
# watch_and_run.sh — Watch .feature files and re-run Behat on changes to
# featureContext.php and any feature in the features/ directory.
# Requires: inotifywait (sudo apt install inotify-tools)
#
# Usage:
# ./watch_and_run.sh # watch all features
# ./watch_and_run.sh SpecialCase1.feature # watch one file only
# =============================================================================
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
FEATURES_DIR="$SCRIPT_DIR/features"
WATCH_TARGET="${1:-}"
if ! command -v inotifywait &>/dev/null; then
echo "ERROR: inotifywait not found. Install it with: sudo apt install inotify-tools"
exit 1
fi
echo "=== Behat Watch Mode ==="
echo "Watching: ${WATCH_TARGET:-all .feature files in $FEATURES_DIR}"
echo "Press Ctrl+C to stop."
echo ""
while true; do
if [ -n "$WATCH_TARGET" ]; then
WATCH_PATH="$FEATURES_DIR/$WATCH_TARGET"
else
WATCH_PATH="$FEATURES_DIR"
fi
# Block until any modify or create event fires on the watched path.
# -q suppresses the "Watching..." startup line; --format '%f' returns only
# the filename so we can pass it directly to run_and_log.sh.
CHANGED=$(inotifywait -q -e modify -e create --format '%f' "$WATCH_PATH" 2>/dev/null)
echo ""
echo ">>> Change detected: $CHANGED at $(date '+%H:%M:%S') — running Behat..."
echo ""
if [ -n "$WATCH_TARGET" ]; then
bash "$SCRIPT_DIR/run_and_log.sh" "features/$WATCH_TARGET"
else
bash "$SCRIPT_DIR/run_and_log.sh" "features/$CHANGED"
fi
echo ""
echo ">>> Waiting for next change..."
done