-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
pre-commit
executable file
·90 lines (68 loc) · 3.05 KB
/
pre-commit
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
#!/bin/sh
export GO15VENDOREXPERIMENT=1
declare -a libs=(ansi arg as bitmask cache cachedfile channel csv file foreach gopath gps graphics http log node re regex rss ssl stack structs xmath xtime yoloDB)
echo "COVERAGE TEST" > coverage.log
BADGEBUILD=" ![OSX Build Status](https://simonwaldherr.de/icon/osx.png) | ![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square) | | go test ./... "
for i in "${libs[@]}"
do
go fmt ./$i
go test -v -coverprofile=$i.coverprofile ./$i
COVER="$(go test -v -coverprofile=$i.coverprofile ./$i 2> /dev/null | grep "coverage" 2> /dev/null)"
COVERAGE="$(echo $COVER | sed -E "s/^.+ ([0-9.%]+) .+/\1/")"
COVERINT="$(echo $COVER | sed -E "s/^.+ ([0-9]+).[0-9]%.+/\1/")"
CHEADER="$(cat README.md | grep "### " | grep "$i ")"
if [ "$COVERINT" -gt "90" ]; then
COVCOL="brightgreen"
elif [ "$COVERINT" -gt "80" ]; then
COVCOL="green"
elif [ "$COVERINT" -gt "70" ]; then
COVCOL="yellowgreen"
elif [ "$COVERINT" -gt "60" ]; then
COVCOL="yellow"
elif [ "$COVERINT" -gt "50" ]; then
COVCOL="orange"
else
COVCOL="red"
fi
BADGEDOC="[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/$i)"
BADGECOV="[![Coverage Status](https://img.shields.io/badge/coverage-$COVERINT%25-$COVCOL.svg?style=flat-square)](https://coveralls.io/r/SimonWaldherr/golibs)"
BADGEBLD=""
if [ "x$COVER" == "x" ]; then
echo "$i 0% (could not build)"
echo "$i 0% (could not build)" >> coverage.log
BADGEBUILD=" ![OSX Build Status](https://simonwaldherr.de/icon/osx.png) | ![Build Status](https://img.shields.io/badge/build-failing-red.svg?style=flat-square) | | go test ./... "
BADGEBLD="[![Build Status](https://img.shields.io/badge/build-failing-red.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)"
NHEADER="### $i - $BADGEDOC $BADGECOV $BADGEBLD"
else
echo "$i $COVER"
echo "$i $COVER" >> coverage.log
BADGEBLD="[![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square)](https://travis-ci.org/SimonWaldherr/golibs)"
NHEADER="### $i - $BADGEDOC $BADGECOV $BADGEBLD"
#rm "$i.coverprofile"
fi
if [ "x$CHEADER" != "x" ]; then
#//replace "$CHEADER" "$NHEADER" README.md
./go_replace_tool README.md README_new.md "$CHEADER" "$NHEADER"
rm README.md
mv README_new.md README.md
#rpl "$CHEADER" "$NHEADER" README.md
fi
done
gover
go tool cover -html=gover.coverprofile -o coverage.html
for i in "${libs[@]}"
do
rm "$i.coverprofile"
done
godoc -http=:6060 &
wget -r -np -N -E -p -k -e robots=off http://localhost:6060/pkg/simonwaldherr.de/go/golibs
kill $(lsof -t -i:6060)
mv localhost:6060 godoc
#rpl "$(cat README.md | grep " go test ./... ")" "$BADGEBUILD" README.md
./go_replace_tool README.md README_new.md "$(cat README.md | grep " go test ./... ")" "$BADGEBUILD"
rm README.md
mv README_new.md README.md
cp ./file/test.txt ./cachedfile/test.txt
cp ./file/test.txt ./examples/test.txt
git add coverage.log
git add README.md