-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathpackage-smoke-test.sh
More file actions
executable file
·77 lines (64 loc) · 2.16 KB
/
Copy pathpackage-smoke-test.sh
File metadata and controls
executable file
·77 lines (64 loc) · 2.16 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
#!/usr/bin/env bash
set -euo pipefail
CLEAN_BUILD=true
if [[ "$1" == "--no-clean-build" ]]; then
CLEAN_BUILD=false
fi
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
WORK="$(mktemp -d)"
SERVER_PID=""
cleanup() {
[[ -n "$SERVER_PID" ]] && kill "$SERVER_PID" 2>/dev/null || true
rm -rf "$WORK"
}
trap cleanup EXIT
cd "$ROOT"
if [[ "$CLEAN_BUILD" == true ]]; then
echo "Building from a clean slate..."
rm -rf dist build
npm run build
fi
TARBALL="$WORK/$(npm pack --silent --pack-destination "$WORK")"
echo "Packed: $TARBALL"
FILES="$(tar tzf "$TARBALL")"
# UI must be inside the tarball
if ! grep -qx 'package/dist/build/index.html' <<<"$FILES"; then
echo "FAIL: dist/build/index.html is missing from the tarball."
echo "--- everything under dist/build ---"
grep '^package/dist/build' <<<"$FILES" || echo "(dist/build is entirely absent)"
echo "--- top level ---"
sed 's|^package/||' <<<"$FILES" | cut -d/ -f1 | sort -u
exit 1
fi
grep -qE '^package/dist/build/assets/.+\.js$' <<<"$FILES" \
|| { echo "FAIL: no JS bundle under dist/build/assets."; exit 1; }
# Install like a normal user
cd "$WORK"
npm init -y >/dev/null
npm install --no-audit --no-fund --loglevel=error "$TARBALL"
# Boot from a scratch cwd so it writes its .data/.tmp
mkdir -p "$WORK/run" && cd "$WORK/run"
"$WORK/node_modules/.bin/git-proxy" > "$WORK/server.log" 2>&1 &
SERVER_PID=$!
for i in $(seq 1 60); do
curl -fsS http://localhost:8080/api/v1/healthcheck >/dev/null 2>&1 && break
if [[ $i -eq 60 ]]; then
echo "FAIL: server did not come up within 60s"
cat "$WORK/server.log"
exit 1
fi
sleep 1
done
# Check UI wrapper is served
HTML="$(curl -fsS http://localhost:8080/)"
if ! grep -q '<div id="root">' <<<"$HTML"; then
echo "FAIL: / did not return the GitProxy UI wrapper."
head -30 <<<"$HTML"
exit 1
fi
# The bundled reference must resolve, not just exist as a string
ASSET="$(grep -oE '/assets/[A-Za-z0-9._-]+\.js' <<<"$HTML" | head -1)"
[[ -n "$ASSET" ]] || { echo "FAIL: index.html references no JS bundle."; exit 1; }
curl -fsS -o /dev/null "http://localhost:8080$ASSET" \
|| { echo "FAIL: $ASSET 404s."; exit 1; }
echo "PASS: packaged UI installs and serves correctly ($ASSET)"