Skip to content

Commit

Permalink
chore: Add script to test sub project and add more unit test for naco…
Browse files Browse the repository at this point in the history
…s v2 (#29)
  • Loading branch information
Skyenought committed Jan 13, 2024
1 parent 1c2367c commit 7e572af
Show file tree
Hide file tree
Showing 27 changed files with 1,862 additions and 208 deletions.
34 changes: 31 additions & 3 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,44 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.16
go-version: 1.18

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
resolve-modules:
name: resolve module
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- id: set-matrix
run: ./hack/resolve-modules.sh

lint:
name: lint module
runs-on: ubuntu-latest
needs: resolve-modules
strategy:
matrix: ${{ fromJson(needs.resolve-modules.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
working-directory: ${{ matrix.workdir }}
args: -E gofumpt --timeout 10m
skip-pkg-cache: true
34 changes: 18 additions & 16 deletions .github/workflows/push-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,31 @@ on: [ push, pull_request ]
jobs:
build:
runs-on: ubuntu-latest

services:
nacos:
image: 'nacos/nacos-server:2.0.3'
ports:
- '8848:8848'
- '9848:9848'
env:
MODE: standalone

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.16
go-version: 1.18

- uses: actions/cache@v2
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Prepare Nacos
run: |
make prepare
- name: Check License Header
uses: apache/skywalking-eyes/header@v0.4.0
env:
Expand All @@ -32,18 +38,14 @@ jobs:
- name: typos-action
uses: crate-ci/typos@v1.2.1

- name: Lint
run: |
go vet -stdmethods=false $(go list ./...)
go install mvdan.cc/gofumpt@v0.2.0
test -z "$(gofumpt -l -extra .)"

- name: Benchmark
run: go test -bench=. -benchmem -run=none ./...

- name: Unit Test
run: go test -v -race -covermode=atomic -coverprofile=coverage.out ./...
run: make test
env:
serverAddr: 127.0.0.1
serverPort: 8848
namespace: public

- name: Benchmark
run: go test -bench=. -benchmem -run=none ./...
1 change: 1 addition & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ header:
- '**/*.go'
paths-ignore:
- example/hello/**
- v2/example/hello/**
comment: on-failure
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
NACOS_VERSION ?= 2.0.3
TOOLS_SHELL="./hack/tools.sh"

prepare:
docker pull nacos/nacos-server:$(NACOS_VERSION)
docker run --rm --name nacos-quick -e MODE=standalone -p 8848:8848 -p 9848:9848 -d nacos/nacos-server:$(NACOS_VERSION)

stop:
docker stop nacos-quick


.PHONY: test
test:
@${TOOLS_SHELL} test
@echo "go test finished"



.PHONY: vet
vet:
@${TOOLS_SHELL} vet
@echo "vet check finished"
22 changes: 22 additions & 0 deletions hack/resolve-modules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

# This is used by the linter action.
# Recursively finds all directories with a go.mod file and creates
# a GitHub Actions JSON output option.

set -o errexit

HOME=$(
cd "$(dirname "${BASH_SOURCE[0]}")" &&
cd .. &&
pwd
)

source "${HOME}/hack/util.sh"
all_modules=$(util::find_modules)
PATHS=""
for mod in $all_modules; do
PATHS+=$(printf '{"workdir":"%s"},' ${mod})
done

echo "::set-output name=matrix::{\"include\":[${PATHS%?}]}"
51 changes: 51 additions & 0 deletions hack/tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

HOME=$(
cd "$(dirname "${BASH_SOURCE[0]}")" &&
cd .. &&
pwd
)

source "${HOME}/hack/util.sh"

all_modules=$(util::find_modules)

# test all mod
function test() {
for mod in $all_modules; do
pushd "$mod" >/dev/null &&
echo "go test $(sed -n 1p go.mod | cut -d ' ' -f2)" &&
go test -race -covermode=atomic -coverprofile=coverage.out ./...
popd >/dev/null || exit
done
}

# vet all mod
function vet() {
for mod in $all_modules; do
pushd "$mod" >/dev/null &&
echo "go vet $(sed -n 1p go.mod | cut -d ' ' -f2)" &&
go vet -stdmethods=false ./...
popd >/dev/null || exit
done
}

function help() {
echo "use: test,vet"
}

case $1 in
vet)
vet
;;
test)
test
;;
*)
help
;;
esac
15 changes: 15 additions & 0 deletions hack/util.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

# find all go mod path
# returns an array contains mod path
function util::find_modules() {
find . -not \( \
\( \
-path './output' \
-o -path './.git' \
-o -path '*/third_party/*' \
-o -path '*/vendor/*' \
-o -path '*/example/*' \
\) -prune \
\) -name 'go.mod' -print0 | xargs -0 -I {} dirname {}
}
9 changes: 9 additions & 0 deletions v2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
NACOS_VERSION ?= 2.0.3
TOOLS_SHELL="./hack/tools.sh"

prepare:
docker pull nacos/nacos-server:$(NACOS_VERSION)
docker run --rm --name nacos-quick -e MODE=standalone -p 8848:8848 -p 9848:9848 -d nacos/nacos-server:$(NACOS_VERSION)

stop:
docker stop nacos-quick
5 changes: 3 additions & 2 deletions v2/example/basic/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import (
"log"
"time"

"github.com/kitex-contrib/registry-nacos/v2/example/hello/kitex_gen/api"
"github.com/kitex-contrib/registry-nacos/v2/example/hello/kitex_gen/api/hello"

"github.com/cloudwego/kitex/client"
"github.com/kitex-contrib/registry-nacos/example/hello/kitex_gen/api"
"github.com/kitex-contrib/registry-nacos/example/hello/kitex_gen/api/hello"
"github.com/kitex-contrib/registry-nacos/v2/resolver"
)

Expand Down
4 changes: 2 additions & 2 deletions v2/example/basic/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

"github.com/cloudwego/kitex/pkg/rpcinfo"
"github.com/cloudwego/kitex/server"
"github.com/kitex-contrib/registry-nacos/example/hello/kitex_gen/api"
"github.com/kitex-contrib/registry-nacos/example/hello/kitex_gen/api/hello"
"github.com/kitex-contrib/registry-nacos/v2/example/hello/kitex_gen/api"
"github.com/kitex-contrib/registry-nacos/v2/example/hello/kitex_gen/api/hello"
"github.com/kitex-contrib/registry-nacos/v2/registry"
)

Expand Down
4 changes: 2 additions & 2 deletions v2/example/custom-config/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"time"

"github.com/cloudwego/kitex/client"
"github.com/kitex-contrib/registry-nacos/example/hello/kitex_gen/api"
"github.com/kitex-contrib/registry-nacos/example/hello/kitex_gen/api/hello"
"github.com/kitex-contrib/registry-nacos/v2/example/hello/kitex_gen/api"
"github.com/kitex-contrib/registry-nacos/v2/example/hello/kitex_gen/api/hello"
"github.com/kitex-contrib/registry-nacos/v2/resolver"
"github.com/nacos-group/nacos-sdk-go/v2/clients"
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
Expand Down
4 changes: 2 additions & 2 deletions v2/example/custom-config/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

"github.com/cloudwego/kitex/pkg/rpcinfo"
"github.com/cloudwego/kitex/server"
"github.com/kitex-contrib/registry-nacos/example/hello/kitex_gen/api"
"github.com/kitex-contrib/registry-nacos/example/hello/kitex_gen/api/hello"
"github.com/kitex-contrib/registry-nacos/v2/example/hello/kitex_gen/api"
"github.com/kitex-contrib/registry-nacos/v2/example/hello/kitex_gen/api/hello"
"github.com/kitex-contrib/registry-nacos/v2/registry"
"github.com/nacos-group/nacos-sdk-go/v2/clients"
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
Expand Down
28 changes: 28 additions & 0 deletions v2/example/hello/hello.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.
//

namespace go api

struct Request {
1: string message
}

struct Response {
1: string message
}

service Hello {
Response echo(1: Request req)
}

0 comments on commit 7e572af

Please sign in to comment.