forked from polydawn/repeatr
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgoad
More file actions
executable file
·198 lines (183 loc) · 5.38 KB
/
goad
File metadata and controls
executable file
·198 lines (183 loc) · 5.38 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
set -euo pipefail
# Project details
name="repeatr"
pkg="go.polydawn.net/$name" # everything under here will be tested
cmd="$pkg/cmd/$name" # if you have a main.main not at the repo root, set this
### other config scripts? invoke here.
LDFLAGS=""
. meta/build/version.sh
### For demo runs and tests, ask them to lump all their state in one, unique dir.
### At the same time, tell it to use this local filesystem for assets.
mkdir -p /tmp/repeatr-test/
chmod 01777 /tmp/repeatr-test/ 2>/dev/null || true
export REPEATR_BASE="/tmp/repeatr-test/$(date +%Y.%m.%d..%H.%M.%S)..$RANDOM$RANDOM"
export REPEATR_ASSETS="file+ca://$PWD/meta/assets-cache/"
# Set up gopath -- relative to this dir, so we work in isolation.
cd "$( dirname "${BASH_SOURCE[0]}" )"
export GOPATH="$PWD"/.gopath/
# subcommand arg?
SUBCOMMAND=${1:-}
# subsection arg?
SUBSECTION=${2:-"..."}
SUBSECTION="./$SUBSECTION"
if [ -z "$SUBCOMMAND" ] ; then
(
go generate "$SUBSECTION"
go fmt "$SUBSECTION"
go install -ldflags "$LDFLAGS" "$cmd" && {
echo -e "\E[1;32minstall successful.\E[0;m\n"
} || {
echo -e "\E[1;41minstall failed!\E[0;m"
exit 8
}
go test -short "$SUBSECTION" && {
echo -e "\n\E[1;32mall tests green.\E[0;m"
} || {
echo -e "\n\E[1;41msome tests failed!\E[0;m"
exit 4
}
)
else
shift # munch $subcommand from passing on in "$@"
case "$SUBCOMMAND" in
-)
# passthrough for other commands
go "$@"
;;
env)
echo "GOROOT=`go env GOROOT`"
echo "GOPATH=`go env GOPATH`"
;;
path)
echo "$GOPATH"
;;
init)
# it's your responsibility to do this the first time
# (we don't do it at the front of every build because it will move submodules if you already have them, and that might not be what you want as you're plowing along)
git submodule update --init
# also make sure the self-symlink exists. should be committed anyway (but then, this is also useful for project-first-steps.)
mkdir -p "$(dirname ".gopath/src/$pkg")"
ln -snf "$(echo "${pkg//[^\/]}/" | sed s#/#../#g)"../ ".gopath/src/$pkg"
# and now some repeatr-specific stuff: place some asset caches locally.
(cd meta/assets-cache && ./bootstrap)
;;
test)
go generate "$SUBSECTION"
set +e ; shift ; set -e # munch $subsection from passing on in "$@"
go test -i "$SUBSECTION" "$@" &&
go test -v "$SUBSECTION" "$@" && {
echo -e "\n\E[1;32mall tests green.\E[0;m"
} || {
echo -e "\n\E[1;41msome tests failed!\E[0;m"
exit 4
}
;;
install)
go generate "./..."
go install -ldflags "$LDFLAGS" "$cmd"
;;
bench)
profPath="$GOPATH/tmp/prof/"
mkdir -p "$profPath"
go generate "$SUBSECTION"
set +e ; shift ; set -e # munch $subsection from passing on in "$@"
go test -i "$SUBSECTION" "$@" &&
GOCONVEY_REPORTER=silent \
go test \
-run=XXX -bench=. \
-o "$profPath/bench.bin" \
-cpuprofile="$profPath/cpu.pprof" \
"$SUBSECTION" "$@" || {
echo -e "\E[1;41msome benchmarks failed!\E[0;m"
exit 4
}
# use e.g.: go tool pprof --text .gopath/tmp/prof/bench.bin .gopath/tmp/prof/cpu.pprof
;;
test-acceptance)
[ -x "$GOPATH/bin/repeatr" ] || { echo "run 'goad install' first" 2>&1 ; exit 19; }
# demo and basic acceptance scenarios should run just about anywhere
./demo.sh -t
# repeat-thyself should usually run, but it has to sit out in travis PR-mode because of the synthetic commit which isn't actually cloneable
TRAVIS="${TRAVIS:-}"
TRAVIS_PULL_REQUEST="${TRAVIS_PULL_REQUEST:-}"
if [ "$TRAVIS" == 'true' -a "$TRAVIS_PULL_REQUEST" != 'false' ]; then
echo "skipping repeat-thyself test" 1>&2
else
./repeat-thyself.sh
fi
;;
fmt)
go fmt "$SUBSECTION"
;;
doc)
for package in $(go list "$SUBSECTION" | sed "s#^_${PWD}#${pkg}#"); do
echo -e "==== $package ====\n"
godoc "$package"
echo -e "\n\n\n"
done
;;
convey)
shift
go install github.com/smartystreets/goconvey && "$GOPATH"/bin/goconvey "$@"
;;
cover)
coverFile="$GOPATH/tmp/cover/cover.out"
mkdir -p "$(dirname "$coverFile")"
for package in $(go list "$SUBSECTION" | sed "s#^_${PWD}#${pkg}#"); do
rm -f "$coverFile"
echo "==== $package ===="
go test -coverprofile="$coverFile" "$package" && \
[ -f "$coverFile" ] && \
echo ---- && \
go tool cover -func="$coverFile" && \
echo ---- && \
go tool cover -html="$coverFile"
echo ====
echo
done
rm -f "$coverFile"
;;
validate)
# run all validations and exit non-zero after all of them if any fail
validators=()
validators+=("./meta/validators/validate-dco")
validators+=("./meta/validators/validate-gofmt")
validators+=("./meta/validators/validate-import-trees")
invalid=""
for validator in ${validators[@]}; do
echo -e "\E[1;34m==== checking $validator ... ====\E[0;m"
"$validator" && {
echo -e "\E[1;32mpassed.\E[0;m"
} || {
echo -e "\E[1;31mfailed!\E[0;m"
invalid="true"
}
echo
echo
done
echo
[ -z "$invalid" ] && {
echo -e "\E[1;32mall validations green.\E[0;m"
} || {
echo -e "\E[1;41msome validations failed!\E[0;m"
exit 6
}
;;
clean)
rm -rf "$GOPATH/bin" "$GOPATH/pkg" "$GOPATH/tmp" "demo"
;;
sys)
# i would call this `install` following make tradition, but, well, `go install` means something different, so.
go generate "./..."
go install "$cmd"
cp "$GOPATH/bin/repeatr" /usr/bin/repeatr
ls -la /usr/bin/repeatr
repeatr --version
;;
*)
echo "Usage: $0 {init|test|install|bench|exec|fmt|doc|cover|validate|clean}" 1>&2;
exit 1
;;
esac
fi