-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·238 lines (191 loc) · 8.07 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·238 lines (191 loc) · 8.07 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#! /bin/bash
# Copyright 2021 CloudWeGo Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
# add time for each command for timing
export PS4='[$(date "+%F %T")] '
bits=$(getconf LONG_BIT)
if [[ $bits != 64 ]]; then
echo "this script runs on 64-bit architectures only" >&2
exit 1
fi
set -x
PATH_BIN=$PWD/bin
mkdir -p $PATH_BIN
export PATH=$PATH_BIN:$PATH
# GOBIN need to be changed here as kitex-tests will install different version bin when testing,
# GOPATH remains the same as default,
# coz other runners in the same host may share path like GOMODCACHE, GOCACHE
export GOBIN=$PATH_BIN
# Fix some dependency versions to ensure compatibility when testing with old Go versions
IS_OLD_GO=false
GO_VERSION=`go version`
if [[ $GO_VERSION == *"go1.21"* || $GO_VERSION == *"go1.22"* || $GO_VERSION == *"go1.23"* ]]; then
IS_OLD_GO=true
fi
# make sure it will not use toolchain go version automatically
export GOTOOLCHAIN=local
PROTOC_VERSION=v3.20.2
install_protoc() {
echo "installing protoc ... "
os=`uname -s | sed 's/Darwin/osx/'`
arch=`uname -m | sed 's/amd64/x86_64/' | sed 's/arm64/aarch_64/'`
suffix=$(echo ${os}-${arch})
filename=protoc-${PROTOC_VERSION#v}-${suffix}.zip
url=https://github.com/protocolbuffers/protobuf/releases/download/${PROTOC_VERSION}/${filename}
rm -f $filename
wget -q $url || exit 1
unzip -o -q $filename -d ./tmp/
mv ./tmp/bin/protoc $PATH_BIN
rm -rf ./tmp/
echo "installing protoc ... done"
}
# use abs path, the env will be passed to and used by other scripts in sub dirs
if [[ -n $1 ]]; then
LOCAL_REPO=`realpath $1`
fi
# export and reuse the latest version,
# then no need to query the remote develop branch multiple times for it.
export KITEX_LATEST_VERSION=main # default value if not set
if [[ -z $LOCAL_REPO ]]; then
# use GOPROXY=direct to fix proxy cache issues
export KITEX_LATEST_VERSION=`GOPROXY=direct go list -m github.com/cloudwego/kitex@main | cut -d" " -f2`
fi
go_install() {
echo "installing $@ ..."
go install $@
echo "installing $@ ... done"
}
kitex_cmd() {
kitex --no-dependency-check $@
}
echo -e "\ninstalling missing commands\n"
PROTOC_GEN_GO_VERSION="latest"
PROTOC_GEN_GO_GRPC_VERSION="latest"
if $IS_OLD_GO; then
# fix the version when running with old Go versions
PROTOC_GEN_GO_VERSION="v1.34.1"
PROTOC_GEN_GO_GRPC_VERSION="v1.5.1"
fi
# install protoc
which protoc || install_protoc &
# install protoc-gen-go and protoc-gen-go-kitexgrpc
which protoc-gen-go || go_install "google.golang.org/protobuf/cmd/protoc-gen-go@${PROTOC_GEN_GO_VERSION}" &
# install protoc-gen-go and protoc-gen-go-kitexgrpc
which protoc-gen-go-grpc || go_install "google.golang.org/grpc/cmd/protoc-gen-go-grpc@${PROTOC_GEN_GO_GRPC_VERSION}" &
# install thriftgo
which thriftgo || go_install github.com/cloudwego/thriftgo@latest &
# install kitex
if [[ -n $LOCAL_REPO ]]; then
cd ${LOCAL_REPO}
go_install ${LOCAL_REPO}/tool/cmd/kitex
cd -
else
go_install github.com/cloudwego/kitex/tool/cmd/kitex@$KITEX_LATEST_VERSION
fi
wait
echo -e "\ninstalling missing commands ... done\n"
# double check commands,
# set -e may not working since commands run in background
protoc --version
protoc-gen-go --version
protoc-gen-go-grpc --version
thriftgo --version
kitex -version
echo -e "\ngenerating code for testing ...\n"
rm -rf kitex_gen
kitex_cmd -module github.com/cloudwego/kitex-tests ./idl/stability.thrift
kitex_cmd -module github.com/cloudwego/kitex-tests ./idl/http.thrift
kitex_cmd -module github.com/cloudwego/kitex-tests ./idl/http.proto
kitex_cmd -streamx -module github.com/cloudwego/kitex-tests ./idl/tenant.thrift
kitex_cmd -module github.com/cloudwego/kitex-tests -combine-service ./idl/combine_service.thrift
kitex_cmd -module github.com/cloudwego/kitex-tests ./idl/thrift_multi_service.thrift
kitex_cmd -module github.com/cloudwego/kitex-tests ./idl/thrift_multi_service_2.thrift
kitex_cmd -module github.com/cloudwego/kitex-tests -I idl ./idl/stability.proto
kitex_cmd -module github.com/cloudwego/kitex-tests -I idl ./idl/unknown_handler.proto
kitex_cmd -module github.com/cloudwego/kitex-tests -I idl ./idl/grpc_demo.proto
kitex_cmd -module github.com/cloudwego/kitex-tests -I idl -combine-service ./idl/grpc_multi_service.proto
kitex_cmd -module github.com/cloudwego/kitex-tests -I idl ./idl/grpc_multi_service_2.proto
kitex_cmd -module github.com/cloudwego/kitex-tests -I idl ./idl/pb_multi_service.proto
kitex_cmd -module github.com/cloudwego/kitex-tests -I idl -combine-service ./idl/combine_service.proto
kitex_cmd -streamx -module github.com/cloudwego/kitex-tests -I idl ./idl/pbapi.proto
rm -rf kitex_gen_slim
kitex_cmd -module github.com/cloudwego/kitex-tests -thrift template=slim -gen-path kitex_gen_slim ./idl/stability.thrift
# we need to generate kitex_gen with apache codec independently to test codec logic in kitex bthrift.
rm -rf kitex_gen_apache_codec
kitex_cmd -module github.com/cloudwego/kitex-tests -thrift no_default_serdes=false -gen-path kitex_gen_apache_codec ./idl/stability.thrift
rm -rf grpc_gen
mkdir grpc_gen
protoc --go_out=grpc_gen/. ./idl/grpc_demo_2.proto
protoc --go-grpc_out=grpc_gen/. ./idl/grpc_demo_2.proto
# generate thrift streaming code
LOCAL_REPO=$LOCAL_REPO ./thrift_streaming/generate.sh
echo -e "\ngenerating code for testing ... done\n"
echo -e "\nupdating dependencies ... \n"
# Init dependencies
rm -f go.mod
go mod init github.com/cloudwego/kitex-tests
if [[ -n $LOCAL_REPO ]]; then
go mod edit -replace github.com/cloudwego/kitex=${LOCAL_REPO}
go mod edit -replace github.com/cloudwego/kitex/pkg/protocol/bthrift=${LOCAL_REPO}/pkg/protocol/bthrift
else
go get github.com/cloudwego/kitex@$KITEX_LATEST_VERSION
fi
fixed_version() {
go mod edit -replace $1=$1@$2
}
# ...
fixed_version github.com/apache/thrift v0.13.0
# https://github.com/googleapis/go-genproto/issues/1015
fixed_version google.golang.org/genproto v0.0.0-20241223144023-3abc09e42ca8
fixed_version google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142
# used by this repo, and it takes seconds for `go mod tidy`
# can we get rid of it one day? used in kitexgrpc/normalcall/normalcall_test.go
fixed_version github.com/shirou/gopsutil/v3 v3.24.5
if $IS_OLD_GO; then
# fix the version when running old go versions
# FIXME:
# you may need to confirm the oldest Go version we support,
# and then check with go.mod of these repos to see which versions are good for the Go version
fixed_version google.golang.org/grpc v1.67.3
fixed_version google.golang.org/protobuf v1.35.2
fixed_version github.com/jhump/protoreflect v1.17.0
fi
go mod tidy
echo -e "\nupdating dependencies ... done\n"
# run tests
# use less cores for stability
# coz some of them are logical cores
nproc=$(nproc)
export GOMAXPROCS=$(( 3 * $nproc / 4 ))
echo -e "\nrunning tests ... \n"
# skip kitex_gen dirs which have no tests
test_modules=`go list ./... | grep -v kitex_gen | grep -v grpc_gen | grep -v kitexgrpc/abc/ | grep -v generic/proxy`
if [[ -n $LOCAL_REPO && -n $CI ]]; then
# only generate coverage file in ci env
# CI=true will be set by Github runner or you can set by yourself
# It will be slower if generate code coverage
go test -failfast -covermode=atomic -coverprofile=${LOCAL_REPO}/coverage.txt.tmp -coverpkg=github.com/cloudwego/kitex/... $test_modules
if [[ "$OSTYPE" =~ ^darwin ]]; # remove `mode: atomic` line
then
sed -i '' 1d ${LOCAL_REPO}/coverage.txt.tmp
else
sed -i '1d' ${LOCAL_REPO}/coverage.txt.tmp
fi
cat ${LOCAL_REPO}/coverage.txt.tmp >> ${LOCAL_REPO}/coverage.txt
rm ${LOCAL_REPO}/coverage.txt.tmp
else
go test -failfast $test_modules
fi
echo "PASSED"