-
Notifications
You must be signed in to change notification settings - Fork 8
/
travis-helper-functions.sh
167 lines (139 loc) · 3.76 KB
/
travis-helper-functions.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
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
#! /usr/bin/env bash
read -r -d '' CODE_HEADER <<H
// Copyright \d{4} The go-gl Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
H
wget -q https://raw.github.com/go-gl/testutils/master/imgurbash.sh
chmod u+x imgurbash.sh
# Error log
erl() {
at " ""$@"
"$@" &>> error.log
return $?
}
at() {
echo "--" "$@" | tee -a error.log
date +%H:%M:%S.%N &>> error.log
}
check-formatting() {
BADFMT="$(find . -iname \*.go | xargs gofmt -l)"
if [[ -n "$BADFMT" ]]
then
at "go fmt found problems with the following files:"
echo "$BADFMT"
return 1
fi
if [[ -n "$(go vet)" ]]
then
at "go vet found problems"
return 1
fi
if [[ -n "$(go fix)" ]]
then
at "go fix found problems"
return 1
fi
FILES_MISSING_HEADERS=false
for f in $(find . -iname "*.go")
do
if ! pcregrep -qM "$CODE_HEADER" "$f"
then
at " '$f' is missing license header:"
FILES_MISSING_HEADERS=true
fi
done
if $FILES_MISSING_HEADERS
then
echo "Some files are missing license headers, which should look like this,"\
" followed by an empty line:"
echo "$CODE_HEADER"
return 1
fi
}
# $1 == name of this package
# $2 == name of package to checkout and test
# For example, if the package being tested is pwaller's clone of go-gl/gl,
# and we wish to ensure go-gl/examples still works, then the current package
# needs to be copied from pwaller/gl to go-gl/gl and installed.
subtest-init() {
WHOAMI="$1"
PROPER_LOCATION="${GOPATH}/src/github.com/${WHOAMI}"
TESTPKG="github.com/${2}"
if [[ "$PWD" != "${PROPER_LOCATION}" ]]; then
at "Moving myself to ${PROPER_LOCATION}..."
mkdir -p "${PROPER_LOCATION}"
cp -R "${PWD}"/* "${PROPER_LOCATION}"
pushd "${PROPER_LOCATION}"
at "go get"
erl go get -d -v
at "go build"
erl go build
at "go install"
erl go install
popd
fi
at "Fetching ${TESTPKG}"
go get -d -v "${TESTPKG}"
at "Installing test deps for ${TESTPKG}"
go test -i "${TESTPKG}"
}
subtest() {
TESTPKG="github.com/${2}"
at "Testing ${TESTPKG}"
go test -v "${TESTPKG}"
}
failure() {
at "Failure - error log contents:"
cat error.log
upload-to-imgur
exit 1
}
upload-to-imgur() {
at "Uploading to imgur"
for file in *.png
do
at "Uploading $file"
./imgurbash.sh $file
echo
done
}
die() {
at "Failure: $@"
exit 1
}
initialize() {
at "Installing eatmydata and pcregrep"
erl sudo apt-get install eatmydata pcregrep || die "Failed to install"
at "Checking code formatting"
check-formatting \
|| die "Formatting checks failed"
at "apt-get update -qq"
erl sudo eatmydata apt-get update -qq \
|| die "'apt-get update -qq' failed"
at "Installing packages"
# eatmydata provides a slight speedup for installing many packages. At one time
# it was significant (when installing the whole of lightdm for example), but
# I'm not sure if it's the case here. It doesn't cost anything, so here it is.
erl sudo eatmydata apt-get install -qq \
libglfw-dev libglew-dev mesa-utils inotify-tools xserver-xorg \
libsdl1.2-dev libsdl-image1.2-dev \
|| die "Failed to install dependencies"
at "Starting X"
erl sudo mkdir -p /tmp/.X11-unix
(sleep 0.5 && sudo X) &>> error.log &
at "Waiting for X to come up"
erl inotifywait -t 4 -r /tmp/.X11-unix
export DISPLAY=:0
at "Running glxgears test"
(glxgears -info &) && sleep 2 && pkill glxgears
at "Fetching package dependencies"
go get -d -v \
|| die "go get failed"
at "Fetching test dependencies"
go list -f '{{range .TestImports}}{{.}} {{end}}' | xargs go get -d -v \
|| die "Fetching test deps failed"
at "Installing test dependencies"
go test -i \
|| die "'go test -i' failed"
}