forked from snowdriftcoop/snowdrift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·80 lines (63 loc) · 1.78 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
#!/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 -s -C "$projRoot" -f 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 () {
# Shut down the database on exit
( trap "${dbmake[*]} stop" EXIT
# . . . and start it now
PGDATABASE="$1" ${dbmake[*]}
shift
"$@"
) # DB shutdown happens now
}
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
;;
*)
echo "$usage"
;;
esac
}
main "$@"