Skip to content

Commit d76ba5a

Browse files
authored
chore: support go >=1.21 (#150)
1 parent 487aa84 commit d76ba5a

3 files changed

Lines changed: 37 additions & 33 deletions

File tree

.github/workflows/pr-check.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ on: [pull_request]
44

55
jobs:
66
run-tests:
7+
strategy:
8+
matrix:
9+
go: [ "1.21", oldstable, stable ]
710
runs-on: [ self-hosted, Linux, X64 ]
811
steps:
912
- uses: actions/checkout@v4
1013
- name: Set up Go
11-
uses: actions/setup-go@v5
14+
uses: actions/setup-go@v6
1215
with:
13-
go-version: stable
16+
go-version: ${{ matrix.go }}
1417
cache: false
1518
- name: Run Tests
1619
run: ./run.sh

kitexgrpc/compressor/grpc_compressor_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import (
1919
"errors"
2020
"net"
2121
"testing"
22-
"time"
2322

2423
"github.com/cloudwego/kitex-tests/kitex_gen/protobuf/grpc_demo/servicea"
2524
"github.com/cloudwego/kitex-tests/pkg/test"
2625
"github.com/cloudwego/kitex-tests/pkg/utils/clientutils"
26+
"github.com/cloudwego/kitex-tests/pkg/utils/serverutils"
2727
client_opt "github.com/cloudwego/kitex/client"
2828
"github.com/cloudwego/kitex/client/callopt"
2929
"github.com/cloudwego/kitex/pkg/endpoint"
@@ -35,15 +35,15 @@ import (
3535
)
3636

3737
func TestKitexWithoutCompressor(t *testing.T) {
38-
hostport := "localhost:9020"
38+
hostport := serverutils.NextListenAddr()
3939
addr, _ := net.ResolveTCPAddr("tcp", hostport)
4040
svr := servicea.NewServer(new(ServiceAImpl), server.WithServiceAddr(addr))
4141
go func() {
4242
err := svr.Run()
4343
test.Assert(t, err == nil, err)
4444
}()
4545
defer svr.Stop()
46-
time.Sleep(50 * time.Millisecond)
46+
serverutils.Wait(hostport)
4747
client, err := GetClient(hostport)
4848
test.Assert(t, err == nil, err)
4949
defer clientutils.CallClose(client)
@@ -62,15 +62,15 @@ func TestKitexWithoutCompressor(t *testing.T) {
6262
}
6363

6464
func TestKitexCompressor(t *testing.T) {
65-
hostport := "localhost:9021"
65+
hostport := serverutils.NextListenAddr()
6666
addr, _ := net.ResolveTCPAddr("tcp", hostport)
6767
svr := servicea.NewServer(new(ServiceAImpl), server.WithServiceAddr(addr))
6868
go func() {
6969
err := svr.Run()
7070
test.Assert(t, err == nil, err)
7171
}()
7272
defer svr.Stop()
73-
time.Sleep(50 * time.Millisecond)
73+
serverutils.Wait(hostport)
7474
client, err := GetClient(hostport)
7575
test.Assert(t, err == nil, err)
7676
defer clientutils.CallClose(client)
@@ -90,15 +90,15 @@ func TestKitexCompressor(t *testing.T) {
9090
}
9191

9292
func TestKitexCompressorWithGRPCClient(t *testing.T) {
93-
hostport := "localhost:9022"
93+
hostport := serverutils.NextListenAddr()
9494
addr, _ := net.ResolveTCPAddr("tcp", hostport)
9595
svr := servicea.NewServer(new(ServiceAImpl), server.WithServiceAddr(addr))
9696
go func() {
9797
err := svr.Run()
9898
test.Assert(t, err == nil, err)
9999
}()
100100
defer svr.Stop()
101-
time.Sleep(50 * time.Millisecond)
101+
serverutils.Wait(hostport)
102102

103103
conn, err := grpc.Dial(hostport, grpc.WithInsecure(), grpc.WithBlock())
104104
test.Assert(t, err == nil, err)
@@ -136,12 +136,12 @@ func ServiceNameMW(next endpoint.Endpoint) endpoint.Endpoint {
136136
}
137137

138138
func TestKitexCompressorWithGRPCServer(t *testing.T) {
139-
hostport := "localhost:9023"
139+
hostport := serverutils.NextListenAddr()
140140
go func() {
141141
err := RunGRPCServer(hostport)
142142
test.Assert(t, err == nil, err)
143143
}()
144-
time.Sleep(50 * time.Millisecond)
144+
serverutils.Wait(hostport)
145145

146146
client, err := GetClient(hostport, client_opt.WithMiddleware(ServiceNameMW))
147147
test.Assert(t, err == nil, err)

run.sh

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ export PATH=$PATH_BIN:$PATH
3636
# coz other runners in the same host may share path like GOMODCACHE, GOCACHE
3737
export GOBIN=$PATH_BIN
3838

39-
# Fix some dependency versions to ensure compatibility when testing with Go 1.18
40-
# TODO: Remove this if Go 1.18 is no longer supported
41-
IS_GO_118=false
42-
if [[ `go version` == *"go1.18"* ]]; then
43-
IS_GO_118=true
39+
# Fix some dependency versions to ensure compatibility when testing with old Go versions
40+
IS_OLD_GO=false
41+
GO_VERSION=`go version`
42+
if [[ $GO_VERSION == *"go1.21"* || $GO_VERSION == *"go1.22"* || $GO_VERSION == *"go1.23"* ]]; then
43+
IS_OLD_GO=true
4444
fi
45+
# make sure it will not use toolchain go version automatically
46+
export GOTOOLCHAIN=local
4547

4648
PROTOC_VERSION=v3.20.2
4749

@@ -75,7 +77,7 @@ fi
7577

7678
go_install() {
7779
echo "installing $@ ..."
78-
go install $@ || go get $@
80+
go install $@
7981
echo "installing $@ ... done"
8082
}
8183

@@ -87,10 +89,10 @@ echo -e "\ninstalling missing commands\n"
8789

8890
PROTOC_GEN_GO_VERSION="latest"
8991
PROTOC_GEN_GO_GRPC_VERSION="latest"
90-
if $IS_GO_118; then
91-
# fix the version when running go1.18
92-
PROTOC_GEN_GO_VERSION="v1.31.0"
93-
PROTOC_GEN_GO_GRPC_VERSION="v1.3.0"
92+
if $IS_OLD_GO; then
93+
# fix the version when running with old Go versions
94+
PROTOC_GEN_GO_VERSION="v1.34.1"
95+
PROTOC_GEN_GO_GRPC_VERSION="v1.5.1"
9496
fi
9597

9698
# install protoc
@@ -184,18 +186,21 @@ fixed_version() {
184186
fixed_version github.com/apache/thrift v0.13.0
185187

186188
# https://github.com/googleapis/go-genproto/issues/1015
187-
fixed_version google.golang.org/genproto v0.0.0-20250227231956-55c901821b1e
188-
fixed_version google.golang.org/genproto/googleapis/rpc v0.0.0-20250227231956-55c901821b1e
189+
fixed_version google.golang.org/genproto v0.0.0-20241223144023-3abc09e42ca8
190+
fixed_version google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142
189191

190192
# used by this repo, and it takes seconds for `go mod tidy`
191193
# can we get rid of it one day? used in kitexgrpc/normalcall/normalcall_test.go
192194
fixed_version github.com/shirou/gopsutil/v3 v3.24.5
193195

194-
if $IS_GO_118; then
195-
# fix the version when running go1.18
196-
fixed_version google.golang.org/grpc v1.56.3
197-
fixed_version google.golang.org/protobuf v1.34.1
198-
fixed_version github.com/jhump/protoreflect v1.8.2
196+
if $IS_OLD_GO; then
197+
# fix the version when running old go versions
198+
# FIXME:
199+
# you may need to confirm the oldest Go version we support,
200+
# and then check with go.mod of these repos to see which versions are good for the Go version
201+
fixed_version google.golang.org/grpc v1.67.3
202+
fixed_version google.golang.org/protobuf v1.35.2
203+
fixed_version github.com/jhump/protoreflect v1.17.0
199204
fi
200205

201206
go mod tidy
@@ -211,11 +216,7 @@ export GOMAXPROCS=$(( 3 * $nproc / 4 ))
211216
echo -e "\nrunning tests ... \n"
212217

213218
# skip kitex_gen dirs which have no tests
214-
if $IS_GO_118; then
215-
test_modules=`go list ./... | grep -v kitex_gen | grep -v grpc_gen | grep -v kitexgrpc/abc/ | grep -v generic/proxy`
216-
else
217-
test_modules=`go list ./... | grep -v kitex_gen | grep -v grpc_gen | grep -v kitexgrpc/abc/`
218-
fi
219+
test_modules=`go list ./... | grep -v kitex_gen | grep -v grpc_gen | grep -v kitexgrpc/abc/ | grep -v generic/proxy`
219220

220221
if [[ -n $LOCAL_REPO && -n $CI ]]; then
221222
# only generate coverage file in ci env

0 commit comments

Comments
 (0)