forked from CMSgov/design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loki.sh
executable file
·94 lines (74 loc) · 2.06 KB
/
loki.sh
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
#!/usr/bin/env bash
set -Eeo pipefail
trap cleanup SIGINT SIGTERM ERR
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
STORYBOOK_DS=${STORYBOOK_DS:-core}
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] <...loki args>
Assists with running the Storybook Loki visual regression tests. Items in brackets
are optional. Must have docker running and able to start up instances.
Utilizes the STORYBOOK_DS environment variable to determine which system to test.
Available options:
args One of: update/test/approve
-h, --help Print this help and exit
-v, --verbose Print script debug info
EOF
exit
}
cleanup() {
trap - SIGINT SIGTERM ERR
pkill -f storybook
}
die() {
local msg=$1
local code=${2-1} # default exit status 1
msg "$msg"
exit "$code"
}
msg() {
echo >&2 -e "${1-}"
}
while :; do
case "${1-}" in
-h | --help) usage ;;
-v | --verbose) set -x ;;
*) break ;;
esac
shift
done
args=("$@")
[ ${#args[@]} -eq 0 ] && usage
npx start-storybook --no-open -p 6006 > /dev/null 2>&1 &
SB_PID=$!
msg "\n-+- Starting: Storybook on port 6006 ${STORYBOOK_DS} PID: ${SB_PID}"
# wait for storybook to be ready
msg "-i- Waiting for storybook instance to be ready, timeout in 120s ..\n"
attempts=0
until $(true &>/dev/null </dev/tcp/127.0.0.1/6006); do
if [ $attempts -eq 20 ]; then
kill $SB_PID
die "[x] Something went wrong starting storybook ..\n"
fi
attempts=$(($attempts+1))
sleep 6
done
# storybook is up, start the appropriate loki process
msg "[✓] Storybook instance found at http://localhost:6006!"
msg "-+- Starting: npx loki ${args} ${STORYBOOK_DS}\n"
if npx loki $args ; then
msg "\n[✓] Loki ${args} ran successfully"
else
msg "\n[X] There was a problem with Loki ${args}"
fi
if pkill -f storybook ; then
msg "[✓] Successfully killed storybook instance"
else
msg "[X] There was a problem killing storybook, trying harder"
if kill -9 $SB_PID ; then
msg "[✓] That did it, storybook closed"
else
msg "[X] Storybook can't be killed, oh no, run!"
fi
fi
echo ""