-
Notifications
You must be signed in to change notification settings - Fork 949
/
travis_ci.sh
executable file
·164 lines (131 loc) · 3.37 KB
/
travis_ci.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
#!/bin/bash
set -e # fast fail
# action for travis ci
Action=$1
# config the number of integration test job.
JOBS=$2
# config the id of job
JOB_ID=$3
CASE_PREFIX="testcase.list"
LOCAL_CASE_FILE="${TRAVIS_BUILD_DIR}/test/${CASE_PREFIX}"
source "${TRAVIS_BUILD_DIR}/hack/install/config.sh"
prepare_testcase() {
# get the number of all test case
# test case must write with this format:
# func (XXX) TestXXX(c *check.C) {
grep -h -E "^func\ \(.*\)\ Test.*\(c\ \*check\.C\)\ \{" ./test -r \
| awk '{print $3,$4}' | awk -F \( '{print $1}' \
| sed 's/\*//' | sed 's/) /./' > "${LOCAL_CASE_FILE}"
# make test case list file
local sum nums
# shellcheck disable=SC2002
sum=$(cat "${LOCAL_CASE_FILE}" | wc -l)
nums=$((sum / JOBS + 1))
rm -rf "${LOCAL_CASE_FILE}.*"
split -l ${nums} -d --suffix-length=1 "${LOCAL_CASE_FILE}" "${LOCAL_CASE_FILE}."
}
run_pre_test() {
prepare_testcase
}
run_unittest() {
sudo env "PATH=$PATH" hack/install/install_ci_related.sh
sudo env "PATH=$PATH" make unit-test
make coverage
bash <(curl -s https://codecov.io/bash) -cF unittest -y .codecov.yml
}
run_integration_test() {
local job_id=$1
check_port
make build
sudo env "PATH=$PATH" make install
sudo env "PATH=$PATH" make download-dependencies
sudo env "PATH=$PATH" "INTEGRATION_FLAGS=${job_id}" make integration-test
make coverage
bash <(curl -s https://codecov.io/bash) -cF "integration_test_${job_id}" -y .codecov.yml
}
run_criv1alpha2_test() {
check_port
make build
TEST_FLAGS="" BUILDTAGS="selinux seccomp apparmor" make build-daemon-integration
sudo env "PATH=$PATH" make install
sudo env "PATH=$PATH" make download-dependencies
sudo env "PATH=$PATH" make cri-v1alpha2-test
make coverage
bash <(curl -s https://codecov.io/bash) -cF criv1alpha2_test -y .codecov.yml
}
run_node_e2e_test() {
check_port
make build
TEST_FLAGS="" make build-daemon-integration
sudo env "PATH=$PATH" make install
sudo env "PATH=$PATH" make download-dependencies
sudo env "PATH=$PATH" make cri-e2e-test
make coverage
bash <(curl -s https://codecov.io/bash) -cF node_e2e_test -y .codecov.yml
}
check_port() {
# docker-containerd will use port 10010 in docker.service
sudo netstat -npl | grep -q "10010"
if [[ $? -ne 0 ]]; then
return
fi
sudo systemctl stop docker
}
install_osscmd() {
sudo wget "http://gosspublic.alicdn.com/ossutil/1.4.1/ossutil64" \
-O /usr/local/bin/ossutil
sudo chmod +x /usr/local/bin/ossutil
}
oss() {
local action=$1
local src=$2
local dst=$3
command -v ossutil || install_osscmd
local osscmd="ossutil -e ${OSS_ENDPOINT} \
-i ${OSS_ACCESS_KEY_ID} \
-k ${OSS_ACCESS_KEY_SECRET}"
case ${action} in
ls)
${osscmd} ls "${src}"
;;
cp)
${osscmd} cp -r -f "${src}" "${dst}"
;;
rm)
${osscmd} rm -rf "${src}"
;;
*)
echo "Unsupport command"
;;
esac
}
main () {
case ${Action} in
pretest)
echo "pre-test"
run_pre_test
;;
unittest)
echo "run unit test"
run_unittest
;;
integrationtest)
echo "run integration test"
run_pre_test
run_integration_test "${JOB_ID}"
;;
criv1alpha2test)
echo "run criv1alpha2 test"
run_criv1alpha2_test
;;
nodee2etest)
echo "run node e2e test"
run_node_e2e_test
;;
*)
echo "Unsupport action"
exit 1
;;
esac
}
main