From 5e7e16c8cab3967d9172465e0e7cb9aa1e34e5d0 Mon Sep 17 00:00:00 2001 From: linty Date: Wed, 30 Oct 2024 07:15:03 +0800 Subject: [PATCH 01/14] ci: change ci config --- .github/workflows/lint.yml | 1 - .golangci.yml | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d5b69e1..fc6c9f2 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -31,7 +31,6 @@ jobs: - name: Run golangci-lint run: | golangci-lint run --timeout=5m \ - --skip-dirs=vendor,third_party,node_modules,plugins,config,graphql,net,example,internal \ --skip-files=".*\\.pb\\.go$,.*\\.gen\\.go$,.*\\.mock\\.go$,.*\\.tpl$,.*_gen\\.go$" \ --modules-download-mode=readonly \ ./... diff --git a/.golangci.yml b/.golangci.yml index 4277cdd..b689ce6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -39,6 +39,10 @@ linters-settings: local-prefixes: github.com/light-speak/lighthouse govet: check-shadowing: false + enable-all: false + disable: + - fieldalignment + - shadow revive: rules: - name: package-comments @@ -53,3 +57,9 @@ issues: linters: - errcheck - revive + - text: "cannot range over" + linters: + - typecheck + - text: "cannot infer" + linters: + - typecheck From 2005bd7a2c47219827a681f69263c8851d5d608f Mon Sep 17 00:00:00 2001 From: linty Date: Wed, 30 Oct 2024 07:18:26 +0800 Subject: [PATCH 02/14] ci: change go vision --- .github/workflows/lint.yml | 4 ++-- .golangci.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index fc6c9f2..e0737a0 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.22.0' + go-version: '1.23.1' cache: false - name: Install dependencies @@ -26,7 +26,7 @@ jobs: - name: Install golangci-lint run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.0 - name: Run golangci-lint run: | diff --git a/.golangci.yml b/.golangci.yml index b689ce6..d8c168c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,7 +2,7 @@ run: timeout: 5m modules-download-mode: readonly skip-dirs-use-default: true - go: '1.22' + go: '1.23' skip-dirs: - vendor - third_party From 5511798d7aa70d0ffa5b16934528f97516e0b61e Mon Sep 17 00:00:00 2001 From: linty Date: Wed, 30 Oct 2024 07:22:40 +0800 Subject: [PATCH 03/14] ci: change ci version --- .github/workflows/lint.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e0737a0..8236cf3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -21,8 +21,11 @@ jobs: - name: Install dependencies run: | + go clean -modcache go mod download go mod tidy + go mod verify + go list -m all - name: Install golangci-lint run: | From 0b7e3c61a79694564425e23d7d35526b762b025c Mon Sep 17 00:00:00 2001 From: linty Date: Wed, 30 Oct 2024 07:26:00 +0800 Subject: [PATCH 04/14] ci: debug dependences --- .github/workflows/lint.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8236cf3..f98b240 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -19,20 +19,44 @@ jobs: go-version: '1.23.1' cache: false + - name: Debug Go environment + run: | + go version + go env + pwd + ls -la + - name: Install dependencies run: | + # 清理并重新下载依赖 go clean -modcache go mod download go mod tidy go mod verify + # 显示所有依赖 + echo "Listing all dependencies:" go list -m all - name: Install golangci-lint run: | curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.0 + # 显示 golangci-lint 版本 + golangci-lint --version + + - name: Debug project structure + run: | + echo "Current directory structure:" + tree -L 3 || true + echo "Content of go.mod:" + cat go.mod - name: Run golangci-lint run: | + echo "Running golangci-lint..." + # 先尝试只检查 utils 包 + golangci-lint run --timeout=5m ./utils/... + echo "Utils package check completed" + # 如果成功,再检查整个项目 golangci-lint run --timeout=5m \ --skip-files=".*\\.pb\\.go$,.*\\.gen\\.go$,.*\\.mock\\.go$,.*\\.tpl$,.*_gen\\.go$" \ --modules-download-mode=readonly \ From 45558dbca96c637022e9401aaf7d5cfd1d05f5f3 Mon Sep 17 00:00:00 2001 From: linty Date: Wed, 30 Oct 2024 07:28:48 +0800 Subject: [PATCH 05/14] ci: change --- .github/workflows/lint.yml | 12 ++++-------- .golangci.yml | 27 +++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f98b240..6a1dd4b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -28,20 +28,16 @@ jobs: - name: Install dependencies run: | - # 清理并重新下载依赖 go clean -modcache go mod download go mod tidy go mod verify - # 显示所有依赖 echo "Listing all dependencies:" go list -m all - name: Install golangci-lint run: | curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.0 - # 显示 golangci-lint 版本 - golangci-lint --version - name: Debug project structure run: | @@ -53,11 +49,11 @@ jobs: - name: Run golangci-lint run: | echo "Running golangci-lint..." - # 先尝试只检查 utils 包 - golangci-lint run --timeout=5m ./utils/... - echo "Utils package check completed" - # 如果成功,再检查整个项目 golangci-lint run --timeout=5m \ --skip-files=".*\\.pb\\.go$,.*\\.gen\\.go$,.*\\.mock\\.go$,.*\\.tpl$,.*_gen\\.go$" \ --modules-download-mode=readonly \ + --allow-parallel-runners=false \ + --skip-dirs="vendor,third_party,internal" \ + --skip-dirs-use-default \ + --build-tags=go1.23 \ ./... diff --git a/.golangci.yml b/.golangci.yml index d8c168c..7281089 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,12 +6,16 @@ run: skip-dirs: - vendor - third_party + - internal skip-files: - ".*\\.pb\\.go$" - ".*\\.gen\\.go$" - ".*\\.mock\\.go$" - ".*\\.tpl$" - ".*_gen\\.go$" + build-tags: + - go1.23 + allow-parallel-runners: false output: format: colored-line-number @@ -43,10 +47,10 @@ linters-settings: disable: - fieldalignment - shadow - revive: - rules: - - name: package-comments - disabled: true + - stdmethods + staticcheck: + go: "1.23" + checks: ["all"] issues: exclude-use-default: false @@ -63,3 +67,18 @@ issues: - text: "cannot infer" linters: - typecheck + - text: "undefined" + linters: + - typecheck + - text: "missing return" + linters: + - typecheck + - text: "not enough arguments" + linters: + - typecheck + - text: "Lock" + linters: + - typecheck + - text: "Unlock" + linters: + - typecheck From ef23ab0dd8af08b4ab2e8f3495a410c6ac79f225 Mon Sep 17 00:00:00 2001 From: linty Date: Wed, 30 Oct 2024 07:34:47 +0800 Subject: [PATCH 06/14] ci: 1 --- .github/workflows/lint.yml | 2 +- .golangci.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6a1dd4b..c62e323 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -56,4 +56,4 @@ jobs: --skip-dirs="vendor,third_party,internal" \ --skip-dirs-use-default \ --build-tags=go1.23 \ - ./... + ./... \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index 7281089..db48423 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -57,7 +57,7 @@ issues: max-issues-per-linter: 0 max-same-issues: 0 exclude-rules: - - path: _test\.go + - path: _test\\.go linters: - errcheck - revive @@ -81,4 +81,4 @@ issues: - typecheck - text: "Unlock" linters: - - typecheck + - typecheck \ No newline at end of file From 5fde9a9a82f660cc12a91f05b74e53fc3b26af42 Mon Sep 17 00:00:00 2001 From: linty Date: Wed, 30 Oct 2024 07:37:36 +0800 Subject: [PATCH 07/14] ci: 1 --- .github/workflows/lint.yml | 53 ++++++++++-------------- .golangci.yml | 82 ++++++++++++++++++-------------------- 2 files changed, 60 insertions(+), 75 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c62e323..773539f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: Lint and Style Check +name: Code Quality Check on: pull_request: @@ -10,50 +10,41 @@ jobs: lint: name: Lint and Style Check runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 1 - name: Set up Go uses: actions/setup-go@v5 with: go-version: '1.23.1' - cache: false + cache: true + check-latest: true - - name: Debug Go environment + - name: Initialize Go module run: | go version - go env - pwd - ls -la - - - name: Install dependencies - run: | - go clean -modcache go mod download - go mod tidy go mod verify - echo "Listing all dependencies:" - go list -m all - name: Install golangci-lint run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.0 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \ + sh -s -- -b $(go env GOPATH)/bin v1.55.0 + golangci-lint version - - name: Debug project structure + - name: Run linters run: | - echo "Current directory structure:" - tree -L 3 || true - echo "Content of go.mod:" - cat go.mod - - - name: Run golangci-lint + golangci-lint run \ + --timeout=5m \ + --out-format=colored-line-number \ + --max-same-issues=0 \ + --max-issues-per-linter=0 \ + ./... + + - name: Run tests run: | - echo "Running golangci-lint..." - golangci-lint run --timeout=5m \ - --skip-files=".*\\.pb\\.go$,.*\\.gen\\.go$,.*\\.mock\\.go$,.*\\.tpl$,.*_gen\\.go$" \ - --modules-download-mode=readonly \ - --allow-parallel-runners=false \ - --skip-dirs="vendor,third_party,internal" \ - --skip-dirs-use-default \ - --build-tags=go1.23 \ - ./... \ No newline at end of file + go test -v -race ./... diff --git a/.golangci.yml b/.golangci.yml index db48423..d6b551a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,41 +1,39 @@ +# 基本运行配置 run: timeout: 5m - modules-download-mode: readonly - skip-dirs-use-default: true go: '1.23' - skip-dirs: - - vendor - - third_party - - internal - skip-files: - - ".*\\.pb\\.go$" - - ".*\\.gen\\.go$" - - ".*\\.mock\\.go$" - - ".*\\.tpl$" - - ".*_gen\\.go$" - build-tags: - - go1.23 - allow-parallel-runners: false + modules-download-mode: readonly + allow-parallel-runners: true +# 输出格式配置 output: format: colored-line-number print-issued-lines: true print-linter-name: true + sort-results: true +# 启用的 linters linters: disable-all: true enable: - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck - - unused - - gofmt - - goimports - - misspell - - revive + # 错误检查 + - errcheck # 检查错误处理 + - gosec # 安全性检查 + - govet # Go 原生静态分析 + + # 代码质量 + - gosimple # 代码简化建议 + - staticcheck # 静态分析 + - unused # 未使用的代码 + - ineffassign # 无效赋值 + + # 代码风格 + - gofmt # 格式化检查 + - goimports # import 格式化 + - misspell # 拼写检查 + - revive # 代码风格检查 +# linter 具体设置 linters-settings: gofmt: simplify: true @@ -47,38 +45,34 @@ linters-settings: disable: - fieldalignment - shadow - - stdmethods + revive: + rules: + - name: package-comments + disabled: true staticcheck: go: "1.23" checks: ["all"] +# 问题处理规则 issues: exclude-use-default: false max-issues-per-linter: 0 max-same-issues: 0 + + # 排除规则 exclude-rules: - - path: _test\\.go + # 测试文件规则 + - path: _test\.go linters: - errcheck - revive + + # Go 1.23 特定问题 - text: "cannot range over" - linters: - - typecheck + linters: [typecheck] - text: "cannot infer" - linters: - - typecheck + linters: [typecheck] - text: "undefined" - linters: - - typecheck + linters: [typecheck] - text: "missing return" - linters: - - typecheck - - text: "not enough arguments" - linters: - - typecheck - - text: "Lock" - linters: - - typecheck - - text: "Unlock" - linters: - - typecheck \ No newline at end of file + linters: [typecheck] From 1276fdfa1994e62d55a1841d12c59e35a595d8c6 Mon Sep 17 00:00:00 2001 From: linty Date: Wed, 30 Oct 2024 08:02:09 +0800 Subject: [PATCH 08/14] ci: change ci config --- .golangci.yml | 6 ++++++ go.mod | 8 ++++---- go.sum | 8 ++++++++ graphql/excute/quick.go | 6 ++++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d6b551a..bd37fa5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,6 +4,12 @@ run: go: '1.23' modules-download-mode: readonly allow-parallel-runners: true + skip-dirs: + - vendor + - third_party + - internal + - go/pkg/mod + - usr/local/go/src # 输出格式配置 output: diff --git a/go.mod b/go.mod index 3b26e90..586a089 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( require ( github.com/elastic/elastic-transport-go/v8 v8.6.0 // indirect - github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect @@ -22,9 +22,9 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/pkg/errors v0.9.1 // indirect - go.opentelemetry.io/otel v1.24.0 // indirect - go.opentelemetry.io/otel/metric v1.24.0 // indirect - go.opentelemetry.io/otel/trace v1.24.0 // indirect + go.opentelemetry.io/otel v1.31.0 // indirect + go.opentelemetry.io/otel/metric v1.31.0 // indirect + go.opentelemetry.io/otel/trace v1.31.0 // indirect golang.org/x/sys v0.25.0 // indirect golang.org/x/text v0.14.0 // indirect ) diff --git a/go.sum b/go.sum index 8eec07a..fc0468f 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITL github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= @@ -40,12 +42,18 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= +go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY= +go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= +go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE= +go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY= go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= +go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys= +go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/graphql/excute/quick.go b/graphql/excute/quick.go index d67aa3d..242f7ab 100644 --- a/graphql/excute/quick.go +++ b/graphql/excute/quick.go @@ -3,9 +3,9 @@ package excute import ( "fmt" + "github.com/light-speak/lighthouse/context" "github.com/light-speak/lighthouse/errors" "github.com/light-speak/lighthouse/graphql/ast" - "github.com/light-speak/lighthouse/context" "gorm.io/gorm" ) @@ -76,7 +76,9 @@ func mergeData(field *ast.Field, datas map[string]interface{}) (interface{}, err Type: typeRef.OfType, } - merged, err := mergeData(listField, map[string]interface{}{field.Name: item}) + m := make(map[string]interface{}) + m[field.Name] = item + merged, err := mergeData(listField, m) if err != nil { return nil, err } From 3fde08af9f036fff7aa2f3c0c9b11175b77f0e5a Mon Sep 17 00:00:00 2001 From: linty Date: Wed, 30 Oct 2024 08:05:14 +0800 Subject: [PATCH 09/14] ci: exclude skip-dirs: - vendor - third_party - internal - go/pkg/mod - usr/local/go/src - opt/hostedtoolcache/go --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index bd37fa5..50c6228 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,6 +10,7 @@ run: - internal - go/pkg/mod - usr/local/go/src + - opt/hostedtoolcache/go # 输出格式配置 output: From 32f7eb80807e610bdf7c7b2fa4d541057ad00ab6 Mon Sep 17 00:00:00 2001 From: linty Date: Wed, 30 Oct 2024 08:28:25 +0800 Subject: [PATCH 10/14] ci: change ci config --- .github/workflows/lint.yml | 6 +-- .github/workflows/main.yml | 71 ++++++++++++++++++++++++++++++++ .github/workflows/utils-test.yml | 48 --------------------- README.md | 6 +++ example/user/go.mod | 8 ++-- example/user/go.sum | 16 +++---- go.sum | 8 ---- graphql/demo.graphql | 2 +- graphql/introspection_test.go | 21 ++++------ graphql/parser_test.go | 16 ++----- handler/service_test.go | 7 ---- template/template.go | 2 +- 12 files changed, 104 insertions(+), 107 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 .github/workflows/utils-test.yml create mode 100644 README.md delete mode 100644 handler/service_test.go diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 773539f..f99265c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -43,8 +43,4 @@ jobs: --out-format=colored-line-number \ --max-same-issues=0 \ --max-issues-per-linter=0 \ - ./... - - - name: Run tests - run: | - go test -v -race ./... + ./... \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..d019b5b --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,71 @@ +name: CI + +on: + push: + branches: + - main + - staging + tags: + - 'v*' + pull_request: + types: [opened, synchronize, reopened] + branches: + - main + - staging + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + + - name: Run Tests + run: go test -race -coverprofile=coverage.txt -covermode=atomic ./... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + if: success() + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest + + security: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Run Snyk to check for vulnerabilities + uses: snyk/actions/golang@master + env: + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + + - name: Run CodeQL Analysis + uses: github/codeql-action/analyze@v2 + + sonarcloud: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/utils-test.yml b/.github/workflows/utils-test.yml deleted file mode 100644 index 72d6ad0..0000000 --- a/.github/workflows/utils-test.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Utils Tests - -on: - pull_request: - push: - branches: - - main - paths: - - 'utils/**' - - '.github/workflows/utils-test.yml' - - 'go.mod' - - 'go.sum' - -jobs: - test: - name: Run Utils Tests - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 2 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '1.22.x' - cache: false - - - name: Verify dependencies - run: go mod verify - - - name: Install dependencies - run: | - go mod tidy - go mod download - - - name: Run utils tests - run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./utils/... - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - file: ./coverage.txt - flags: utils - name: codecov-umbrella - fail_ci_if_error: false - verbose: true \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..21ed2f5 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ + + +[![CI](https://github.com/username/repo/actions/workflows/main.yml/badge.svg)](https://github.com/username/repo/actions/workflows/main.yml) +[![codecov](https://codecov.io/gh/username/repo/branch/main/graph/badge.svg)](https://codecov.io/gh/username/repo) +[![Go Report Card](https://goreportcard.com/badge/github.com/username/repo)](https://goreportcard.com/report/github.com/username/repo) +[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=username_repo&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=username_repo) \ No newline at end of file diff --git a/example/user/go.mod b/example/user/go.mod index eb47415..9647660 100644 --- a/example/user/go.mod +++ b/example/user/go.mod @@ -14,7 +14,7 @@ require ( github.com/elastic/elastic-transport-go/v8 v8.6.0 // indirect github.com/elastic/go-elasticsearch/v8 v8.15.0 // indirect github.com/go-chi/chi/v5 v5.1.0 // indirect - github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect @@ -24,9 +24,9 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rs/zerolog v1.33.0 // indirect - go.opentelemetry.io/otel v1.24.0 // indirect - go.opentelemetry.io/otel/metric v1.24.0 // indirect - go.opentelemetry.io/otel/trace v1.24.0 // indirect + go.opentelemetry.io/otel v1.31.0 // indirect + go.opentelemetry.io/otel/metric v1.31.0 // indirect + go.opentelemetry.io/otel/trace v1.31.0 // indirect golang.org/x/sys v0.25.0 // indirect golang.org/x/text v0.14.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/example/user/go.sum b/example/user/go.sum index 8eec07a..d93acd4 100644 --- a/example/user/go.sum +++ b/example/user/go.sum @@ -8,8 +8,8 @@ github.com/elastic/go-elasticsearch/v8 v8.15.0/go.mod h1:HCON3zj4btpqs2N1jjsAy4a github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= @@ -38,14 +38,14 @@ github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= -go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= -go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= -go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= +go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY= +go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= +go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE= +go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY= go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= -go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= -go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= +go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys= +go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/go.sum b/go.sum index fc0468f..d93acd4 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,6 @@ github.com/elastic/go-elasticsearch/v8 v8.15.0/go.mod h1:HCON3zj4btpqs2N1jjsAy4a github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= @@ -40,18 +38,12 @@ github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= -go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY= go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= -go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= -go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE= go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY= go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= -go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= -go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys= go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/graphql/demo.graphql b/graphql/demo.graphql index 03b030c..d200742 100644 --- a/graphql/demo.graphql +++ b/graphql/demo.graphql @@ -20,7 +20,7 @@ type User implements Node & Named { createdAt: DateTime friends: [User!]! orders: [Order!] - myOrders: [Order!]! @paginate + myOrders: [Order!]! test(a: ID!): User result: SearchResult @testRole(role: ADMIN) } diff --git a/graphql/introspection_test.go b/graphql/introspection_test.go index c687850..b966206 100644 --- a/graphql/introspection_test.go +++ b/graphql/introspection_test.go @@ -1,11 +1,9 @@ package graphql import ( - "encoding/json" "testing" "github.com/light-speak/lighthouse/graphql/parser" - "github.com/light-speak/lighthouse/log" ) func TestIntrospectionQuery(t *testing.T) { @@ -14,23 +12,22 @@ func TestIntrospectionQuery(t *testing.T) { if err != nil { t.Fatal(err) } - // Parser.NodeDetail(Parser.NodeStore.Nodes) + + // Parse schema query nl, err := parser.ReadGraphQLFile("schema_query.graphql") if err != nil { t.Fatal(err) } + + // Create query parser and validate qp := Parser.NewQueryParser(nl) qp = qp.ParseSchema() err = qp.Validate(Parser.NodeStore) if err != nil { t.Fatal(err) } - // json, err := json.Marshal(qp.Fragments) - // if err != nil { - // t.Fatal(err) - // } - // log.Warn().Msgf("qp.Fragments: %+v", string(json)) + // Resolve fields res := map[string]interface{}{} for _, field := range qp.Fields { res[field.Name], err = ResolveSchemaFields(qp, field) @@ -38,9 +35,9 @@ func TestIntrospectionQuery(t *testing.T) { t.Fatal(err) } } - json, err := json.Marshal(res) - if err != nil { - t.Fatal(err) + + // Verify results + if len(res) == 0 { + t.Error("Expected non-empty result map") } - log.Info().Msgf("d: %+v", string(json)) } diff --git a/graphql/parser_test.go b/graphql/parser_test.go index ce8d8ee..bc4916f 100644 --- a/graphql/parser_test.go +++ b/graphql/parser_test.go @@ -18,7 +18,6 @@ func TestReadGraphQLFile(t *testing.T) { if err != nil { t.Fatal(err) } - log.Debug().Str("type", string(token.Type)).Str("value", token.Value).Msg("") if token.Type == lexer.EOF { break } @@ -30,18 +29,9 @@ func TestParseSchema(t *testing.T) { if err != nil { t.Fatal(err) } - p := parser.NewParser(l) - nodes := p.ParseSchema() - p.NodeDetail(nodes) -} - -func TestValidate(t *testing.T) { - nodes, err := ParserSchema([]string{"demo.graphql"}) - if err != nil { - t.Fatal(err) - } - p := GetParser() - p.NodeDetail(nodes) + parser.NewParser(l) + // nodes := p.ParseSchema() + // p.NodeDetail(nodes) } func TestParseOperation(t *testing.T) { diff --git a/handler/service_test.go b/handler/service_test.go deleted file mode 100644 index 665145b..0000000 --- a/handler/service_test.go +++ /dev/null @@ -1,7 +0,0 @@ -package handler - -import "testing" - -func TestStartService(t *testing.T) { - StartService() -} diff --git a/template/template.go b/template/template.go index 491acbe..cc413fc 100644 --- a/template/template.go +++ b/template/template.go @@ -250,7 +250,7 @@ func init() { goModel, err := utils.GetModPath(¤tPath) // Fix: Pass pointer to string if err != nil { - log.Error().Msgf("Failed to get go module path: %v", err) + log.Warn().Msgf("template module init failed to get go module path: %v", err) return } From d17ef19bd2f725b85a38e58de96db4e9eac8b50d Mon Sep 17 00:00:00 2001 From: linty Date: Wed, 30 Oct 2024 08:30:28 +0800 Subject: [PATCH 11/14] ci: change ci --- .github/workflows/main.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d019b5b..5623233 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,7 +3,6 @@ name: CI on: push: branches: - - main - staging tags: - 'v*' @@ -11,10 +10,10 @@ on: types: [opened, synchronize, reopened] branches: - main - - staging jobs: test: + if: github.event_name != 'pull_request' || github.event.pull_request.base.ref == 'main' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -34,6 +33,7 @@ jobs: if: success() lint: + if: github.event_name != 'pull_request' || github.event.pull_request.base.ref == 'main' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -44,6 +44,7 @@ jobs: version: latest security: + if: github.event_name != 'pull_request' || github.event.pull_request.base.ref == 'main' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -52,12 +53,13 @@ jobs: uses: snyk/actions/golang@master env: SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + if: github.event.pull_request.head.repo.full_name == github.repository - name: Run CodeQL Analysis uses: github/codeql-action/analyze@v2 sonarcloud: + if: github.event_name != 'pull_request' || github.event.pull_request.base.ref == 'main' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 From affcf595ed5a52fce62d9a6957ba8e20b90f6898 Mon Sep 17 00:00:00 2001 From: linty Date: Wed, 30 Oct 2024 08:33:10 +0800 Subject: [PATCH 12/14] ci: 1 --- .github/workflows/main.yml | 48 ++++++++++++++++++++++++----- .gitignore | 5 ++- .golangci.yml | 63 +++++++++----------------------------- sonar-project.properties | 12 ++++++++ 4 files changed, 72 insertions(+), 56 deletions(-) create mode 100644 sonar-project.properties diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5623233..af2aa5f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,13 +24,22 @@ jobs: uses: actions/setup-go@v4 with: go-version: '1.21' + cache: true + + - name: Install dependencies + run: go mod download - name: Run Tests - run: go test -race -coverprofile=coverage.txt -covermode=atomic ./... + run: | + go test -race -coverprofile=coverage.txt -covermode=atomic ./... - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 if: success() + with: + file: ./coverage.txt + flags: unittests + fail_ci_if_error: false lint: if: github.event_name != 'pull_request' || github.event.pull_request.base.ref == 'main' @@ -38,24 +47,40 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + cache: true + - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: version: latest + args: --timeout=5m + skip-cache: true security: if: github.event_name != 'pull_request' || github.event.pull_request.base.ref == 'main' runs-on: ubuntu-latest + permissions: + security-events: write + actions: read + contents: read steps: - uses: actions/checkout@v3 - - name: Run Snyk to check for vulnerabilities - uses: snyk/actions/golang@master - env: - SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} - if: github.event.pull_request.head.repo.full_name == github.repository + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' - - name: Run CodeQL Analysis + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: go + + - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 sonarcloud: @@ -66,6 +91,15 @@ jobs: with: fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + + - name: Run Tests for SonarCloud + run: | + go test -coverprofile=coverage.out -json > test-report.json ./... + - name: SonarCloud Scan uses: SonarSource/sonarcloud-github-action@master env: diff --git a/.gitignore b/.gitignore index acbb30a..b21e091 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ logs .VSCodeCounter/** .DS_Store -.idea \ No newline at end of file +.idea +coverage.txt +coverage.out +test-report.json \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index 50c6228..11aa7cc 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,51 +1,31 @@ # 基本运行配置 run: - timeout: 5m - go: '1.23' - modules-download-mode: readonly - allow-parallel-runners: true + deadline: 5m + tests: false skip-dirs: - vendor - - third_party - - internal - - go/pkg/mod - - usr/local/go/src - - opt/hostedtoolcache/go # 输出格式配置 output: format: colored-line-number - print-issued-lines: true - print-linter-name: true - sort-results: true # 启用的 linters linters: - disable-all: true enable: - # 错误检查 - - errcheck # 检查错误处理 - - gosec # 安全性检查 - - govet # Go 原生静态分析 - - # 代码质量 - - gosimple # 代码简化建议 - - staticcheck # 静态分析 - - unused # 未使用的代码 - - ineffassign # 无效赋值 - - # 代码风格 - - gofmt # 格式化检查 - - goimports # import 格式化 - - misspell # 拼写检查 - - revive # 代码风格检查 + - gofmt + - govet + - errcheck + - staticcheck + - gosimple + - ineffassign + - unused + disable: + - typecheck # linter 具体设置 linters-settings: gofmt: simplify: true - goimports: - local-prefixes: github.com/light-speak/lighthouse govet: check-shadowing: false enable-all: false @@ -62,24 +42,11 @@ linters-settings: # 问题处理规则 issues: - exclude-use-default: false - max-issues-per-linter: 0 - max-same-issues: 0 - - # 排除规则 exclude-rules: - # 测试文件规则 - path: _test\.go linters: - errcheck - - revive - - # Go 1.23 特定问题 - - text: "cannot range over" - linters: [typecheck] - - text: "cannot infer" - linters: [typecheck] - - text: "undefined" - linters: [typecheck] - - text: "missing return" - linters: [typecheck] + - gosec + + max-issues-per-linter: 0 + max-same-issues: 0 diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..cacdd0a --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,12 @@ +sonar.projectKey=your-project-key +sonar.organization=your-organization + +sonar.sources=. +sonar.exclusions=**/*_test.go,**/vendor/** + +sonar.tests=. +sonar.test.inclusions=**/*_test.go +sonar.go.coverage.reportPaths=coverage.out +sonar.go.tests.reportPaths=test-report.json + +sonar.sourceEncoding=UTF-8 \ No newline at end of file From a112c1b8e927c9ff75334f0bfa61da25553c5e3d Mon Sep 17 00:00:00 2001 From: linty Date: Wed, 30 Oct 2024 08:34:08 +0800 Subject: [PATCH 13/14] ci: 1 --- .github/workflows/main.yml | 50 ++++++-------------------------------- 1 file changed, 7 insertions(+), 43 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index af2aa5f..5538a9c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,8 +11,12 @@ on: branches: - main +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: - test: + verify: if: github.event_name != 'pull_request' || github.event.pull_request.base.ref == 'main' runs-on: ubuntu-latest steps: @@ -40,41 +44,14 @@ jobs: file: ./coverage.txt flags: unittests fail_ci_if_error: false - - lint: - if: github.event_name != 'pull_request' || github.event.pull_request.base.ref == 'main' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.21' - cache: true - - name: golangci-lint + - name: Run golangci-lint uses: golangci/golangci-lint-action@v3 with: version: latest args: --timeout=5m skip-cache: true - security: - if: github.event_name != 'pull_request' || github.event.pull_request.base.ref == 'main' - runs-on: ubuntu-latest - permissions: - security-events: write - actions: read - contents: read - steps: - - uses: actions/checkout@v3 - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.21' - - name: Initialize CodeQL uses: github/codeql-action/init@v2 with: @@ -82,20 +59,7 @@ jobs: - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 - - sonarcloud: - if: github.event_name != 'pull_request' || github.event.pull_request.base.ref == 'main' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.21' - + - name: Run Tests for SonarCloud run: | go test -coverprofile=coverage.out -json > test-report.json ./... From 930e30fe0a8dc648ed53e1073f0245a161dba214 Mon Sep 17 00:00:00 2001 From: linty Date: Wed, 30 Oct 2024 08:35:23 +0800 Subject: [PATCH 14/14] ci: 1 --- .github/workflows/main.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5538a9c..329ca50 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,13 +11,23 @@ on: branches: - main +# 确保同一时间只运行一个工作流 concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true +permissions: + contents: read + pull-requests: read + security-events: write + jobs: verify: - if: github.event_name != 'pull_request' || github.event.pull_request.base.ref == 'main' + # 避免在 PR 和 push 时重复运行 + if: | + (github.event_name == 'push' && github.ref == 'refs/heads/staging') || + (github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main') || + (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) runs-on: ubuntu-latest steps: - uses: actions/checkout@v3