-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathharness
executable file
·142 lines (122 loc) · 2.94 KB
/
harness
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#! /usr/bin/env bash
# `e`: fail script if a command's exitcode is non-zero
# `u`: fail script if a variable is unset (unitialized)
set -eu
say_done() {
printf "░░░ Done.\n"
}
fail() {
echo "${@}" >&2
exit 1
}
# Called when Ctrl-C is sent
function trap_ctrlc ()
{
echo ">~"
echo "░░░ Cleaning up..."
down
exit 2
}
trap "trap_ctrlc" 2
up() {
echo '░░░ PlaceOS Driver Harness'
echo '░░░ -> Pulling latest code...'
git pull
echo '░░░ -> Pulling latest images...'
docker compose pull
echo '░░░ -> Starting environment...'
docker compose up -d
printf "░░░ The harness can be found at http://localhost:8085/index.html\n"
echo '░░░ Stop the harness with `harness down`'
say_done
}
down() {
echo '░░░ Stopping PlaceOS Driver Harness...'
docker compose down --remove-orphans &> /dev/null
say_done
}
format() {
echo '░░░ Running `crystal tool format` over `drivers` and `repositories`'
docker compose run \
-v "${PWD}/drivers:/wd/drivers" \
-v "${PWD}/repositories:/wd/repositories" \
--no-deps \
--rm \
install-shards \
crystal tool format
say_done
}
report() {
echo '░░░ PlaceOS Driver Compilation Report'
echo '░░░ Pulling images...'
docker compose pull &> /dev/null
# Ensure shards are satisfied before running the report
echo '░░░ Installing shards...'
docker compose run \
--rm \
install-shards > /dev/null
echo '░░░ Starting environment...'
docker compose up -d &> /dev/null
exit_code=0
echo '░░░ Starting report...'
docker exec placeos-drivers report $@ || exit_code=$?
down
exit ${exit_code}
}
build() {
docker compose run \
--rm \
--no-deps \
-v "${PWD}/repositories:/app/repositories" \
-v "${PWD}/drivers:/app/repositories/drivers" \
--entrypoint="/app/scripts/entrypoint.sh" \
build build $@
}
usage() {
cat <<EOF
Usage: harness [-h|--help] [command]
Helper script for interfacing with the PlaceOS Driver spec runner
Command:
report check all drivers' compilation status
up starts the harness
down stops the harness
build builds drivers and uploads them to S3
format formats driver code
help display this message
EOF
}
if [ $# -eq 0 ]
then
usage
exit 1
fi
command="$1"
shift
case $command in
report)
report $@
;;
build)
build $@
;;
up)
up
;;
down)
down
;;
format)
format
;;
-h|--help|help)
usage
;;
*)
if [ -n "$command" ]; then
fail "Unknown command: $command"
else
usage
exit 1
fi
;;
esac