-
Notifications
You must be signed in to change notification settings - Fork 36
/
build.sh
executable file
·98 lines (81 loc) · 2.45 KB
/
build.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
95
96
97
98
#!/usr/bin/env bash
set -e
usage="
.
. build.sh CMD [OPTIONS]
.
Used to run tests and run the devel site.
Uses Make to ensure the dev database is running. Consult db.makefile for more
DB control options.
CMD can be:
devel -- Assumed if no CMD is given. Launches development site.
test -- Runs Stack tests. Does not launch site.
cleandb -- Blow away the database.
'test' accepts any additional options native to 'stack test'
"
# Figure out project root from this script's location and make it absolute:
projRoot=$(cd $(dirname "$0"); git rev-parse --show-toplevel)
export PGDATA="$projRoot"/.postgres-work
export PGHOST="$PGDATA"
export PGDATABASE="snowdrift_development"
# Using stack ensures postgres exists for Nix users, thanks to stack's Nix
# support.
dbmake() {
stack exec -- make --quiet --directory="$projRoot" --file=db.makefile "$@"
}
run_devel () {
cd "$projRoot"/website
stack --work-dir .stack-devel build yesod-bin
stack --work-dir .stack-devel exec yesod devel
}
with_db () {
# If the db is already running, just run the command
if dbmake isrunning; then
shift
"$@"
else
# Shut down the database on exit
( trap "dbmake stop" EXIT
# . . . and start it now
PGDATABASE="$1" dbmake
shift
"$@"
) # DB shutdown happens now
fi
}
main () {
if [ -z "$1" ]; then
CMD=devel
else
CMD="$1"
shift
fi
# Configure local Stripe keys for shell, devel, and test.
[ -e .stripe_keys ] && source .stripe_keys
case "$CMD" in
devel)
with_db snowdrift_development run_devel
;;
test)
touch website/src/Settings/StaticFiles.hs
with_db snowdrift_test stack --work-dir .stack-test test "$@"
;;
cleandb)
dbmake clean
;;
crowdmatch)
stack --work-dir .stack-devel build crowdmatch
# Unsure how portable '--iso-8601' is => use old-school % formatting
date="${1:-$(date +%Y-%m-%d)}"
year="$(printf "%s" "$date" | cut -d- -f1)"
month="$(printf "%s" "$date" | cut -d- -f2)"
day="$(printf "%s" "$date" | cut -d- -f3)"
with_db snowdrift_test stack exec --work-dir .stack-devel -- \
crowdmatch "$year" "$month" "$day"
;;
*)
echo "$usage"
;;
esac
}
main "$@"