-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcoverage.sh
executable file
·74 lines (57 loc) · 1.87 KB
/
coverage.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
#! /bin/sh
# author xiaojun207
# clean up
find ./array -name data -type d|xargs rm -fR
find ./utils -name data -type d|xargs rm -fR
find ./verify -name data -type d|xargs rm -fR
rm -f coverage.out
# clean up finished
go test ./... -race -covermode=atomic -coverprofile=coverage.out
# If test fails exit the pipeline # Check discussion at https://github.com/golang/go/issues/25989
rc=$?
if [ $rc -ne 0 ]; then
echo "testing failed" >&2
exit $rc
fi
########## codecov starts ########3
# make sure to set CODECOV_TOKEN env variable before doing this
os=`uname -s`
if ! command -v codecov &> /dev/null
then
# codecov uploader does not exist. Most likely in a CI environment.
if [ $os == "Darwin" ]; then
url="https://uploader.codecov.io/latest/macos/codecov"
elif [ $os == "Linux" ]; then
url="https://uploader.codecov.io/latest/linux/codecov"
elif [ $os == "Windows" ]; then
url="https://uploader.codecov.io/latest/linux/codecov"
else
echo "Unknown OS"
continue
fi
curl -Os $url
chmod +x codecov
./codecov -t ${CODECOV_TOKEN} -f coverage.out
rm codecov
else
codecov -t ${CODECOV_TOKEN} -f coverage.out
fi
########## codecov ends ########3
# Example setup https://github.com/lluuiissoo/go-testcoverage/blob/main/.github/workflows/ci.yml
# enable threshold
COVERAGE_THRESHOLD=81
totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]'`
# clean up
find ./array -name data -type d|xargs rm -fR
find ./utils -name data -type d|xargs rm -fR
find ./verify -name data -type d|xargs rm -fR
# clean up finished
echo "Total Coverage is $totalCoverage %"
diff=$(echo "$totalCoverage < $COVERAGE_THRESHOLD" | bc)
if [ $diff -eq 1 ]; then
echo "Coverage is below threshold of $COVERAGE_THRESHOLD %"
exit 1
else
echo "Coverage is above threshold of $COVERAGE_THRESHOLD %"
exit 0
fi