Skip to content

Commit c58d649

Browse files
committed
scripts: add travis tests runner
1 parent bf78374 commit c58d649

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

scripts/travis/pr-test.sh

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
set -o pipefail
4+
5+
PROJ="go-systemd"
6+
ORG_PATH="github.com/coreos"
7+
REPO_PATH="${ORG_PATH}/${PROJ}"
8+
9+
PACKAGES="activation daemon dbus journal login1 machine1 sdjournal unit util"
10+
EXAMPLES="activation listen udpconn"
11+
12+
function build_source {
13+
go build ./...
14+
}
15+
16+
function build_tests {
17+
rm -rf ./test_bins ; mkdir -p ./test_bins
18+
for pkg in ${PACKAGES}; do
19+
echo " - ${pkg}"
20+
go test -c -o ./test_bins/${pkg}.test ./${pkg}
21+
done
22+
for ex in ${EXAMPLES}; do
23+
echo " - examples/${ex}"
24+
go build -o ./test_bins/${ex}.example ./examples/activation/${ex}.go
25+
done
26+
}
27+
28+
function run_tests {
29+
pushd test_bins
30+
sudo -v
31+
for pkg in ${PACKAGES}; do
32+
echo " - ${pkg}"
33+
sudo -E ./${pkg}.test -test.v
34+
done
35+
popd
36+
rm -rf ./test_bins
37+
}
38+
39+
function go_fmt {
40+
for pkg in ${PACKAGES}; do
41+
echo " - ${pkg}"
42+
fmtRes=$(gofmt -l "./${pkg}")
43+
if [ -n "${fmtRes}" ]; then
44+
echo -e "gofmt checking failed:\n${fmtRes}"
45+
exit 255
46+
fi
47+
done
48+
}
49+
50+
function go_vet {
51+
for pkg in ${PACKAGES}; do
52+
echo " - ${pkg}"
53+
vetRes=$(go vet "./${pkg}")
54+
if [ -n "${vetRes}" ]; then
55+
echo -e "govet checking failed:\n${vetRes}"
56+
exit 254
57+
fi
58+
done
59+
}
60+
61+
function license_check {
62+
licRes=$(for file in $(find . -type f -iname '*.go' ! -path './vendor/*'); do
63+
head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED)" || echo -e " ${file}"
64+
done;)
65+
if [ -n "${licRes}" ]; then
66+
echo -e "license header checking failed:\n${licRes}"
67+
exit 253
68+
fi
69+
}
70+
71+
export GO15VENDOREXPERIMENT=1
72+
73+
subcommand="$1"
74+
case "$subcommand" in
75+
"build_source" )
76+
echo "Building source..."
77+
build_source
78+
;;
79+
80+
"build_tests" )
81+
echo "Building tests..."
82+
build_tests
83+
;;
84+
85+
"run_tests" )
86+
echo "Running tests..."
87+
run_tests
88+
;;
89+
90+
"go_fmt" )
91+
echo "Checking gofmt..."
92+
go_fmt
93+
;;
94+
95+
"go_vet" )
96+
echo "Checking govet..."
97+
go_vet
98+
;;
99+
100+
"license_check" )
101+
echo "Checking licenses..."
102+
license_check
103+
;;
104+
105+
* )
106+
echo "Error: unrecognized subcommand."
107+
exit 1
108+
;;
109+
esac

0 commit comments

Comments
 (0)