-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathpizza_test.sh
More file actions
executable file
·126 lines (111 loc) · 3.37 KB
/
pizza_test.sh
File metadata and controls
executable file
·126 lines (111 loc) · 3.37 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
set -euo pipefail
# Usage: ./pizza_test.sh <github_account> <config_js_path>
# Optional env vars:
# GH_HOST - GitHub host (default: github.com)
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <github_account> <config_js_path>" >&2
exit 1
fi
ACCOUNT_ID="$1"
CONFIG_PATH="$2"
BASE_DIR="test-${ACCOUNT_ID}"
BASE_DIR_ABS="$(pwd)/${BASE_DIR}"
REPOS=("jwt-pizza" "jwt-pizza-service")
GH_HOST="${GH_HOST:-github.com}"
API_BASE="https://api.${GH_HOST}"
if [[ "${GH_HOST}" == "github.com" ]]; then
API_BASE="https://api.github.com"
fi
mkdir -p "$BASE_DIR"
cd "$BASE_DIR"
for repo in "${REPOS[@]}"; do
if [[ -d "$repo/.git" ]]; then
echo "Repo $repo already exists. Skipping clone."
else
if command -v curl >/dev/null 2>&1; then
status=$(curl -fsSL -o /dev/null -w "%{http_code}" \
"${API_BASE}/repos/${ACCOUNT_ID}/${repo}" || true)
if [[ "${status}" != "200" ]]; then
echo "Repo ${ACCOUNT_ID}/${repo} not found or inaccessible (HTTP ${status}). Skipping clone."
continue
fi
fi
git clone "https://${GH_HOST}/${ACCOUNT_ID}/${repo}.git"
fi
done
# Ensure jwt-pizza-service config symlink exists (after clone)
if [[ ! -e "$CONFIG_PATH" ]]; then
echo "Config file not found: $CONFIG_PATH" >&2
exit 1
fi
if [[ -d "jwt-pizza-service" ]]; then
mkdir -p "jwt-pizza-service/src"
ln -sf "$CONFIG_PATH" "jwt-pizza-service/src/config.js"
else
echo "jwt-pizza-service directory not found; cannot create config symlink." >&2
exit 1
fi
for repo in "${REPOS[@]}"; do
echo "Installing deps in $repo..."
(cd "$repo" && npm install)
done
# Start apps in background
cleanup() {
echo -e "\n\n***************\nEverything is running. You can check logs in $BASE_DIR/*.log"
read -r -p "Do you want to stop the services? [y/N] " answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
kill_tree() {
local pid="$1"
local child
for child in $(ps -o pid= --ppid "$pid" 2>/dev/null); do
kill_tree "$child"
done
kill "$pid" >/dev/null 2>&1 || true
}
if [[ -n "${PIZZA_PID:-}" ]]; then
kill_tree "$PIZZA_PID"
fi
if [[ -n "${SERVICE_PID:-}" ]]; then
kill_tree "$SERVICE_PID"
fi
read -r -p "Do you want to delete the test directory? [y/N] " answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
echo "Cleaning up test directory..."
cd ..
rm -rf "$BASE_DIR_ABS"
fi
fi
}
trap cleanup EXIT INT TERM
echo "Starting jwt-pizza (npm run dev)..."
bash -c 'cd jwt-pizza && exec npm run dev' >"pizza.log" 2>&1 &
PIZZA_PID=$!
echo "Starting jwt-pizza-service (npm run start)..."
bash -c 'cd jwt-pizza-service && exec npm run start' >"pizza-service.log" 2>&1 &
SERVICE_PID=$!
cat <<INFO
Apps started.
- jwt-pizza PID: $PIZZA_PID (logs: $BASE_DIR/pizza.log)
- jwt-pizza-service PID: $SERVICE_PID (logs: $BASE_DIR/pizza-service.log)
INFO
# Basic health check for pizza-service
if command -v curl >/dev/null 2>&1; then
echo "Waiting for pizza-service to start..."
ok=0
for i in $(seq 1 30); do
if curl -fsS "http://localhost:3000" >/dev/null 2>&1; then
echo "pizza-service is responding on http://localhost:3000"
ok=1
break
fi
sleep 1
done
if [[ "$ok" -ne 1 ]]; then
echo "pizza-service did not start within 30 seconds. Check logs: $BASE_DIR/pizza-service.log" >&2
exit 1
fi
else
echo "curl not found; cannot verify http://localhost:3000" >&2
exit 1
fi