-
Notifications
You must be signed in to change notification settings - Fork 21
/
zh
executable file
·101 lines (89 loc) · 2.15 KB
/
zh
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
#!/bin/bash
set -eo pipefail
# Helpers
separator () {
echo '------------------------------------------------------------------------------'
}
export DEVELOPMENT_DB_NAME='zoomhub_development'
export TEST_DB_NAME='zoomhub_test'
# Commands
case "$1" in
init)
echo "Install Haskell 'stack'"
brew install haskell-stack
stack setup
echo "Install 'jq'"
brew install jq
echo "Install 'postgres'"
brew install postgresql@10
brew services start postgresql@10
echo "Install 'vips'"
brew install vips
;;
lint)
stack exec hlint -- src tests
;;
format)
case "$2" in
install)
stack install ormolu
exit 0
;;
check)
mode='check'
;;
"")
mode='inplace'
;;
*)
echo "Unknown command: $0 $*. Try $0 $1 [check|install]"
exit 1
esac
files=$(git ls-files '*.hs' | grep --invert 'vendor/')
set +e
ormolu --mode "$mode" $files
ormolu_status=$?
set -e
if [[ "$mode" == "check" && $ormolu_status != 0 ]]; then
echo "Ormolu check failed. Exit status: $ormolu_status"
exit $ormolu_status
fi
;;
run)
npx dotenvx run --env-file .env -- ./scripts/run.sh
;;
test)
dropdb --if-exists "$TEST_DB_NAME"
createdb "$TEST_DB_NAME"
PGUSER="$(whoami)" HASHIDS_SALT='secret-salt' \
stack build \
--fast \
--test \
--no-run-tests \
--ghc-options='-Wall' \
--exec "migrate-database $TEST_DB_NAME migrate"
psql --output /dev/null --quiet "$TEST_DB_NAME" < ./data/zoomhub_data.sql
psql --output /dev/null --quiet "$TEST_DB_NAME" < ./data/zoomhub_sequences.sql
# See: https://github.com/commercialhaskell/stack/issues/2210
MODULES="$2"
PGUSER="$(whoami)" \
PGDATABASE="$TEST_DB_NAME" \
stack test \
--fast \
--ghc-options='-Wall' \
--test-arguments '--match "'"$MODULES"'"'
;;
db)
case "$2" in
dump)
pg_dump "$DEVELOPMENT_DB_NAME"
;;
*)
echo "Unknown command: $0 $*. Try $0 $1 dump"
exit 1
esac
;;
*)
echo "Unknown command: $0 $*. Try: $0 format|init|lint|run|test"
;;
esac