forked from ricardoarchive/wercker-step-goveralls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·48 lines (41 loc) · 1.24 KB
/
run.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
#!/bin/bash
if [ ! -n "$WERCKER_GOVERALLS_TOKEN" ]; then
error 'Please specify your Coveralls repository token'
exit 1
fi
GIT_BRANCH=$WERCKER_GIT_BRANCH
if [ "$GIT_BRANCH" = "HEAD" ]; then
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
fi
echo "Git branch: $GIT_BRANCH"
version=$(go version)
regex="(go[0-9].[0-9].[0-9])"
if [[ $version =~ $regex ]]; then
version=${BASH_REMATCH[1]}
else
fail 'Unable to determine Go version'
fi
echo "Go version: $version"
if [[ "$version" < "go1.4.0" ]]; then
go get code.google.com/p/go.tools/cmd/cover
else
go get golang.org/x/tools/cmd/cover
fi
go get github.com/mattn/goveralls
echo "mode: count" > profile.cov
err=0
for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -not -path './vendor*' -type d); do
if ls $dir/*.go &> /dev/null; then
echo "Parsing directory: $dir"
go test -v -tags=unit -covermode=count -coverprofile=profile.out $dir || err=1
if [ -f profile.out ]; then
cat profile.out | grep -v "mode: count" >> profile.cov
rm profile.out
fi
fi
done
if [ "$err" -eq 0 ]; then
GIT_BRANCH=$GIT_BRANCH goveralls -coverprofile=profile.cov -service=wercker -repotoken $WERCKER_GOVERALLS_TOKEN
else
fail 'Coverage tests failed, skipping upload'
fi