This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/develop by this push:
new 1e023b794 refactor(makefile): rewrite makefile (#2975)
1e023b794 is described below
commit 1e023b794415f5c13037a0d4984b414c4dc81fe0
Author: marsevilspirit <[email protected]>
AuthorDate: Tue Aug 19 09:25:34 2025 +0800
refactor(makefile): rewrite makefile (#2975)
* refactor(makefile): rewrite makefile
* refactor(makefile): rewrite makefile
* feat(makefile): add make lint
* ci(test): move integration test to another job
* fix(ci): fix ci yaml file error
* style(ci): update ci yaml file
* ci(ci): try to remove unused field
* feat(ci): chmod +x integrate_test.sh
* ci(ci): try to delete unused field
* ci(style): udpate ci yaml file
* ci(style): move to CI
* ci(ci): try to delete unused field
---
.github/workflows/codeql-analysis.yml | 2 +-
.github/workflows/github-actions.yml | 87 +++++++++++----------
.github/workflows/golangci-lint.yml | 31 --------
Makefile | 106 +++++++++-----------------
config_center/apollo/impl.go | 10 +--
config_center/apollo/impl_test.go | 2 +-
integrate_test.sh | 0
protocol/dubbo/hessian2/hessian_dubbo_test.go | 6 +-
8 files changed, 92 insertions(+), 152 deletions(-)
diff --git a/.github/workflows/codeql-analysis.yml
b/.github/workflows/codeql-analysis.yml
index 827b60f59..27d8a156c 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -1,4 +1,4 @@
-name: "CodeQL"
+name: CodeQL
on:
push:
diff --git a/.github/workflows/github-actions.yml
b/.github/workflows/github-actions.yml
index a1ac2b622..80a98480b 100644
--- a/.github/workflows/github-actions.yml
+++ b/.github/workflows/github-actions.yml
@@ -27,8 +27,8 @@ jobs:
config: .licenserc.yaml
mode: check
- build:
- name: ${{ matrix.os }} - Go ${{ matrix.go_version }}
+ CI:
+ name: CI (${{ matrix.os }} - Go ${{ matrix.go_version }})
runs-on: ${{ matrix.os }}
strategy:
# If you want to matrix build , you can append the following list.
@@ -39,12 +39,10 @@ jobs:
- ubuntu-latest
steps:
-
- name: Setup Go ${{ matrix.go_version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go_version }}
- id: go
- name: Checkout
uses: actions/checkout@v4
@@ -63,48 +61,59 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- - name: Merge code into the upstream
- if: ${{ github.event_name == 'pull_request' }}
- run: |
- git fetch origin $GITHUB_BASE_REF
- git checkout -b $GITHUB_BASE_REF origin/$GITHUB_BASE_REF
- git remote add devrepo
https://github.com/${{github.event.pull_request.head.repo.full_name}}.git
- git fetch devrepo ${{github.event.pull_request.head.sha}}
- git config --global user.email "[email protected]"
- git config --global user.name "robot"
- git merge ${{github.event.pull_request.head.sha}}
-
- - name: Install dependencies
- run: |
- if [ -f Gopkg.toml ]; then
- curl
https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
- dep ensure
- else
- go get -v -t -d ./...
- fi
- go install github.com/dubbogo/tools/cmd/imports-formatter@latest
+ - name: Check Code Format
+ run: make fmt && git status && [[ -z `git status -s` ]]
- - name: Format code
- run: |
- go fmt ./... && GOROOT=$(go env GOROOT) imports-formatter && git
status && [[ -z `git status -s` ]]
+ - name: Unit Test
+ run: make test
- - name: Verify
- run: |
- go mod tidy
- make verify
+ - name: Lint
+ run: make lint
+
+ - name: Codecov
+ run: bash <(curl -s https://codecov.io/bash)
- - name: Integration Testing
+ Integration-Test:
+ name: Integration Test (${{ matrix.os }} - Go ${{ matrix.go_version }})
+ runs-on: ${{ matrix.os }}
+ strategy:
+ # If you want to matrix build , you can append the following list.
+ matrix:
+ go_version:
+ - '1.23'
+ os:
+ - ubuntu-latest
+
+ steps:
+ - name: Setup Go ${{ matrix.go_version }}
+ uses: actions/setup-go@v5
+ with:
+ go-version: ${{ matrix.go_version }}
+
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Cache dependencies
+ # ref: https://github.com/actions/cache/blob/main/examples.md#go---module
+ uses: actions/cache@v4
+ with:
+ # Cache, works only on Linux
+ path: |
+ ~/.cache/go-build
+ ~/go/pkg/mod
+ # Cache key
+ key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
+ # An ordered list of keys to use for restoring the cache if no cache
hit occurred for key
+ restore-keys: |
+ ${{ runner.os }}-go-
+
+ - name: Integration Test
run: |
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
- chmod +x integrate_test.sh \
- && ./integrate_test.sh
${{github.event.pull_request.head.repo.full_name}}
${{github.event.pull_request.head.sha}} ${{github.base_ref}}
+ ./integrate_test.sh
${{github.event.pull_request.head.repo.full_name}}
${{github.event.pull_request.head.sha}} ${{github.base_ref}}
elif [ "$GITHUB_EVENT_NAME" == "push" ]; then
- chmod +x integrate_test.sh \
- && ./integrate_test.sh $GITHUB_REPOSITORY $GITHUB_SHA
$GITHUB_REF_NAME
+ ./integrate_test.sh $GITHUB_REPOSITORY $GITHUB_SHA $GITHUB_REF_NAME
else
echo "$GITHUB_EVENT_NAME is an unsupported event type."
exit 1
fi
-
- - name: Codecov
- run: bash <(curl -s https://codecov.io/bash)
diff --git a/.github/workflows/golangci-lint.yml
b/.github/workflows/golangci-lint.yml
deleted file mode 100644
index 9df539d0d..000000000
--- a/.github/workflows/golangci-lint.yml
+++ /dev/null
@@ -1,31 +0,0 @@
-name: golangci-lint
-on:
- push:
- branches: "*"
- pull_request:
- branches: "*"
-
-permissions:
- contents: read
-
-jobs:
- golangci:
- permissions:
- contents: read # for actions/checkout to fetch code
- pull-requests: read # for golangci/golangci-lint-action to fetch pull
requests
- name: lint
- runs-on: ubuntu-latest
- strategy:
- matrix:
- golang:
- - "1.23"
- steps:
- - uses: actions/setup-go@v5
- with:
- go-version: ${{ matrix.golang }}
- - uses: actions/checkout@v4
- - name: golangci-lint
- uses: golangci/golangci-lint-action@v8
- with:
- version: v2.1.6
- args: --timeout=10m
diff --git a/Makefile b/Makefile
index c2dca5128..ac5a9c69c 100644
--- a/Makefile
+++ b/Makefile
@@ -15,81 +15,43 @@
# limitations under the License.
#
-# DO NOT RUN
-# The makefile is for ci test and has dependencies. Do not run it locally.
-# If you want to run the unit tests, run command `go test ./...` directly.
-
-VERSION ?= latest
-
-GO = go
-GO_PATH = $(shell $(GO) env GOPATH)
-GO_OS = $(shell $(GO) env GOOS)
-ifeq ($(GO_OS), darwin)
- GO_OS = mac
-endif
-GO_BUILD = $(GO) build
-GO_GET = $(GO) get
-GO_TEST = $(GO) test
-GO_BUILD_FLAGS = -v
-GO_BUILD_LDFLAGS = -X main.version=$(VERSION)
-
-GO_LICENSE_CHECKER_DIR = license-header-checker-$(GO_OS)
-GO_LICENSE_CHECKER = $(GO_PATH)/bin/license-header-checker
-LICENSE_DIR = /tmp/tools/license
-
-ARCH = amd64
-# for add zookeeper fatjar
-ZK_TEST_LIST=config_center/zookeeper registry/zookeeper cluster/router/chain
cluster/router/condition cluster/router/tag metadata/report/zookeeper
-ZK_JAR_NAME=zookeeper-3.4.9-fatjar.jar
-ZK_FATJAR_BASE=/zookeeper-4unittest/contrib/fatjar
-ZK_JAR_PATH=remoting/zookeeper$(ZK_FATJAR_BASE)
-ZK_JAR=$(ZK_JAR_PATH)/$(ZK_JAR_NAME)
-
-SHELL = /bin/bash
-
-prepareLic:
- echo 'The makefile is for ci test and has dependencies. Do not run it
locally. If you want to run the unit tests, run command `go test ./...`
directly.'
- $(GO_LICENSE_CHECKER) -version || (wget
https://github.com/lsm-dev/license-header-checker/releases/download/v1.2.0/$(GO_LICENSE_CHECKER_DIR).zip
-O $(GO_LICENSE_CHECKER_DIR).zip && unzip -o $(GO_LICENSE_CHECKER_DIR).zip &&
mkdir -p $(GO_PATH)/bin/ && cp
$(GO_LICENSE_CHECKER_DIR)/64bit/license-header-checker $(GO_PATH)/bin/)
- ls /tmp/tools/license/license.txt || wget -P $(LICENSE_DIR)
https://github.com/dubbogo/resources/raw/master/tools/license/license.txt
-
-prepare: prepareLic
-
-.PHONE: test
+SHELL := bash
+.DELETE_ON_ERROR:
+.DEFAULT_GOAL := help
+.SHELLFLAGS := -eu -o pipefail -c
+MAKEFLAGS += --warn-undefined-variables
+MAKEFLAGS += --no-builtin-rules
+MAKEFLAGS += --no-print-directory
+
+.PHONY: help test fmt clean lint
+
+help:
+ @echo "Available commands:"
+ @echo " test - Run unit tests"
+ @echo " clean - Clean test generate files"
+ @echo " fmt - Format code"
+ @echo " lint - Run golangci-lint"
+
+# Run unit tests
test: clean
- $(GO_TEST) ./... -coverprofile=coverage.txt -covermode=atomic
-
-deps: prepare
- $(GO_GET) -v -t -d ./...
-
-.PHONY: license
-license: clean prepareLic
- $(GO_LICENSE_CHECKER) -v -a -r -i
vendor,protocol/triple/triple_protocol,protocol/triple/reflection,metadata/triple_api/proto
$(LICENSE_DIR)/license.txt . go && [[ -z `git status -s` ]]
+ go test ./... -coverprofile=coverage.txt -covermode=atomic
-.PHONY: verify
-verify: clean license test
+fmt: install-imports-formatter
+ # replace interface{} with any
+ go run
golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest
-category=efaceany -fix -test ./...
+ go fmt ./... && GOROOT=$(shell go env GOROOT) imports-formatter
-.PHONE: fmt
-fmt:
- $(GO_GET) -u github.com/dubbogo/tools/cmd/imports-formatter
- imports-formatter
-
-LOCALBIN ?= $(shell pwd)/bin
-$(LOCALBIN):
- mkdir -p $(LOCALBIN)
-GOLANG_LINT_VERSION ?= v2.1.6
-GOLANG_LINT ?= $(LOCALBIN)/golangci-lint
-GOLANG_LINT_INSTALL_SCRIPT ?=
"https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh"
+# Clean test generate files
+clean:
+ rm -rf coverage.txt
-.PHONY: golangci-lint-install
-golangci-lint-install: $(LOCALBIN) ## Download golangci lint locally if
necessary.
- test -s $(LOCALBIN)/golangci-lint && $(LOCALBIN)/golangci-lint
--version | grep -q $(GOLANG_LINT_VERSION) || \
- GOBIN=$(LOCALBIN) go install
github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANG_LINT_VERSION)
+# Run golangci-lint
+lint: install-golangci-lint
+ go vet ./...
+ golangci-lint run ./... --timeout=10m
-.PHONY: lint
-lint: golangci-lint-install ## Run golang lint against code
- GO111MODULE=on $(GOLANG_LINT) run ./... --timeout=30m -v
+install-golangci-lint:
+ go install github.com/golangci/golangci-lint/v2/cmd/[email protected]
-.PHONY: clean
-clean: prepare
- rm -rf coverage.txt
- rm -rf license-header-checker*
+install-imports-formatter:
+ go install github.com/dubbogo/tools/cmd/imports-formatter@latest
diff --git a/config_center/apollo/impl.go b/config_center/apollo/impl.go
index 4ba364199..1fb602188 100644
--- a/config_center/apollo/impl.go
+++ b/config_center/apollo/impl.go
@@ -157,7 +157,7 @@ func formatContent(conf *storage.Config, fileType string)
(string, error) {
return conf.GetContent(), nil
case "yaml", "yml":
props := make(map[string]string)
- conf.GetCache().Range(func(key, value interface{}) bool {
+ conf.GetCache().Range(func(key, value any) bool {
k, ok1 := key.(string)
v, ok2 := value.(string)
if ok1 && ok2 {
@@ -192,8 +192,8 @@ func getFileTypeFromNS(ns string) string {
}
// makeNestedMap convert flat key-value pairs to nested structure
-func makeNestedMap(props map[string]string) map[string]interface{} {
- result := make(map[string]interface{})
+func makeNestedMap(props map[string]string) map[string]any {
+ result := make(map[string]any)
for k, v := range props {
parts := strings.Split(k, ".")
@@ -206,9 +206,9 @@ func makeNestedMap(props map[string]string)
map[string]interface{} {
} else {
// Create or get nested map
if _, exists := current[part]; !exists {
- current[part] =
make(map[string]interface{})
+ current[part] = make(map[string]any)
}
- current = current[part].(map[string]interface{})
+ current = current[part].(map[string]any)
}
}
}
diff --git a/config_center/apollo/impl_test.go
b/config_center/apollo/impl_test.go
index 63263c890..b2fa61d40 100644
--- a/config_center/apollo/impl_test.go
+++ b/config_center/apollo/impl_test.go
@@ -210,7 +210,7 @@ func TestListener(t *testing.T) {
// test remove
apollo.RemoveListener(mockNamespace, listener)
listenerCount := 0
- apollo.listeners.Range(func(_, value interface{}) bool {
+ apollo.listeners.Range(func(_, value any) bool {
apolloListener := value.(*apolloListener)
for e := range apolloListener.listeners {
t.Logf("listener:%v", e)
diff --git a/integrate_test.sh b/integrate_test.sh
old mode 100644
new mode 100755
diff --git a/protocol/dubbo/hessian2/hessian_dubbo_test.go
b/protocol/dubbo/hessian2/hessian_dubbo_test.go
index 436c527f7..668c3f67a 100644
--- a/protocol/dubbo/hessian2/hessian_dubbo_test.go
+++ b/protocol/dubbo/hessian2/hessian_dubbo_test.go
@@ -279,7 +279,7 @@ func TestDecodeFromTcpStream(t *testing.T) {
ID: 1,
ResponseStatus: Zero,
}
- resp, err := codecW.Write(service, header, []interface{}{cs})
+ resp, err := codecW.Write(service, header, []any{cs})
assert.NoError(t, err)
// set reader buffer = 1024 to split resp into two parts
@@ -291,7 +291,7 @@ func TestDecodeFromTcpStream(t *testing.T) {
assert.Equal(t, h.ID, header.ID)
assert.Equal(t, h.ResponseStatus, header.ResponseStatus)
- reqBody := make([]interface{}, 7)
+ reqBody := make([]any, 7)
err = codec.ReadBody(reqBody)
assert.NoError(t, err)
@@ -299,7 +299,7 @@ func TestDecodeFromTcpStream(t *testing.T) {
assert.Equal(t, reqBody[2], service.Version)
assert.Equal(t, reqBody[3], service.Method)
- if list, ok := reqBody[5].([]interface{}); ok {
+ if list, ok := reqBody[5].([]any); ok {
assert.Len(t, list, 1)
if infoPtr, ok2 := list[0].(*CaseStream); ok2 {
assert.Equal(t, len(infoPtr.Payload), 1024)