Skip to content

Commit 88e79d1

Browse files
authored
ci: add code check (#138)
1 parent ef05f31 commit 88e79d1

97 files changed

Lines changed: 7384 additions & 7518 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/lint.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: lint
2+
on: [push, pull_request]
3+
jobs:
4+
bcs-bscp:
5+
name: bcs-bscp
6+
runs-on: ubuntu-latest
7+
steps:
8+
# 拉取代码
9+
- name: checkout
10+
uses: actions/checkout@v3
11+
12+
# 设置 Go 环境
13+
- name: setup go
14+
uses: actions/setup-go@v3
15+
with:
16+
go-version-file: go.mod
17+
18+
# 检查 Go 模块依赖是否整理
19+
- name: go mod tidy check
20+
uses: katexochen/go-tidy-check@v2
21+
with:
22+
modules: .
23+
24+
# 运行代码风格检查 (golangci-lint)
25+
- name: golangci-lint
26+
uses: golangci/golangci-lint-action@v3
27+
with:
28+
version: v1.62.0
29+
args: --timeout=30m
30+
working-directory: .
31+
32+
# 编译项目
33+
- name: build go project
34+
run: |
35+
make build_bscp && make build_frontend

.github/workflows/pr-lint.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: pr-lint
2+
on: [pull_request]
3+
jobs:
4+
PR-format-check:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Check PR naming convention
8+
run: |
9+
title="${{ github.event.pull_request.title }}"
10+
pattern="^(feat|fix|docs|style|refactor|perf|test|chore|revert|build|ci): .*"
11+
if [[ ! $title =~ $pattern ]]; then
12+
echo "PR title does not match naming convention. Example: 'feat: 添加新功能'.\
13+
You can refer to this address for details:\
14+
https://github.com/TencentBlueKing/bk-bscp/tree/master/docs/specification/commit-spec.md"
15+
exit 1
16+
fi

.golangci.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
run:
22
timeout: 10m
3-
skip-dirs:
3+
issues:
4+
exclude-dirs-use-default: true
5+
exclude-dirs:
46
- .*/third_party/*
5-
- test/*
6-
skip-files:
7+
exclude-files:
78
- .*\.docs\.go$
89
- .*\.gen\.go$
910
- .*\.pb\.go$
@@ -16,10 +17,9 @@ run:
1617
- test/benchmark/run/template.go
1718
- test/mock/repo/service/node.go
1819
- pkg/version/version.go
19-
issues:
2020
max-issues-per-linter: 0
2121
max-same-issues: 0
22-
exclude-use-default: false
22+
# exclude-use-default: false
2323
linters:
2424
disable-all: true
2525
enable:
@@ -45,6 +45,8 @@ linters:
4545
- unconvert
4646
- unparam
4747
linters-settings:
48+
staticcheck:
49+
checks: ["all", "-SA1006", "-SA1019"]
4850
errcheck:
4951
exclude-functions:
5052
- (*os.File).Close
@@ -53,6 +55,9 @@ linters-settings:
5355
- github.com/go-chi/render.Render
5456
- io.Copy
5557
- os.RemoveAll
58+
- fmt.Fprint
59+
- fmt.Fprintf
60+
- fmt.Fprintln
5661
lll:
5762
line-length: 120
5863
funlen:
@@ -61,7 +66,10 @@ linters-settings:
6166
gocyclo:
6267
min-complexity: 30
6368
govet:
64-
check-shadowing: true
69+
enable:
70+
- shadow
71+
disable:
72+
- printf
6573
goimports:
6674
local-prefixes: github.com/TencentBlueKing/bk-bscp
6775
gci:

cmd/api-server/service/middleware.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121

2222
"github.com/TencentBlueKing/bk-bscp/pkg/kit"
2323
"github.com/TencentBlueKing/bk-bscp/pkg/metrics"
24-
"github.com/TencentBlueKing/bk-bscp/pkg/rest"
2524
pbcs "github.com/TencentBlueKing/bk-bscp/pkg/protocol/config-server"
25+
"github.com/TencentBlueKing/bk-bscp/pkg/rest"
2626
)
2727

2828
// CheckDefaultTmplSpace create default template space if not existent

cmd/api-server/service/released_kv.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ import (
2626
"github.com/xuri/excelize/v2"
2727
"gopkg.in/yaml.v3"
2828

29-
"github.com/TencentBlueKing/bk-bscp/pkg/criteria/constant"
29+
"github.com/TencentBlueKing/bk-bscp/internal/criteria/constant"
3030
"github.com/TencentBlueKing/bk-bscp/pkg/dal/table"
3131
"github.com/TencentBlueKing/bk-bscp/pkg/i18n"
3232
"github.com/TencentBlueKing/bk-bscp/pkg/kit"
3333
"github.com/TencentBlueKing/bk-bscp/pkg/logs"
34-
"github.com/TencentBlueKing/bk-bscp/pkg/rest"
3534
pbcs "github.com/TencentBlueKing/bk-bscp/pkg/protocol/config-server"
3635
pbkv "github.com/TencentBlueKing/bk-bscp/pkg/protocol/core/kv"
3736
pbrkv "github.com/TencentBlueKing/bk-bscp/pkg/protocol/core/released-kv"
37+
"github.com/TencentBlueKing/bk-bscp/pkg/rest"
3838
)
3939

4040
// Exporter The Exporter interface defines methods for exporting files.
@@ -164,11 +164,11 @@ func (m *kvService) Export(w http.ResponseWriter, r *http.Request) {
164164
var exporter Exporter
165165

166166
switch format {
167-
case "yaml":
167+
case constant.YamlFormat:
168168
exporter = &YAMLExporter{OutData: outData}
169169
w.Header().Set("Content-Disposition", "attachment; filename=output.yaml")
170170
w.Header().Set("Content-Type", "application/x-yaml")
171-
case "json":
171+
case constant.JsonFormat:
172172
exporter = &JSONExporter{OutData: outData}
173173
w.Header().Set("Content-Type", "application/json")
174174
w.Header().Set("Content-Disposition", "attachment; filename=output.json")

cmd/api-server/service/variable.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/go-chi/render"
2525
"gopkg.in/yaml.v3"
2626

27+
"github.com/TencentBlueKing/bk-bscp/internal/criteria/constant"
2728
"github.com/TencentBlueKing/bk-bscp/pkg/dal/table"
2829
"github.com/TencentBlueKing/bk-bscp/pkg/kit"
2930
"github.com/TencentBlueKing/bk-bscp/pkg/logs"
@@ -69,11 +70,11 @@ func (s *variableService) ExportGlobalVariables(w http.ResponseWriter, r *http.R
6970

7071
outData := variablesToOutData(vs)
7172
switch format {
72-
case "yaml":
73+
case constant.YamlFormat:
7374
exporter = &YAMLVariableExporter{OutData: outData}
7475
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%d_global_variable.yaml", kt.BizID))
7576
w.Header().Set("Content-Type", "application/x-yaml")
76-
case "json":
77+
case constant.JsonFormat:
7778
exporter = &JSONVariableExporter{OutData: outData}
7879
w.Header().Set("Content-Type", "application/json")
7980
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%d_global_variable.json", kt.BizID))
@@ -124,12 +125,12 @@ func (s *variableService) ExportAppVariables(w http.ResponseWriter, r *http.Requ
124125

125126
outData := variablesToOutData(vars.Details)
126127
switch format {
127-
case "yaml":
128+
case constant.YamlFormat:
128129
exporter = &YAMLVariableExporter{OutData: outData}
129130
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%d_%s_variable.yaml",
130131
kt.BizID, app.Spec.Name))
131132
w.Header().Set("Content-Type", "application/x-yaml")
132-
case "json":
133+
case constant.JsonFormat:
133134
exporter = &JSONVariableExporter{OutData: outData}
134135
w.Header().Set("Content-Type", "application/json")
135136
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%d_%s_variable.json",
@@ -193,12 +194,12 @@ func (s *variableService) ExportReleasedAppVariables(w http.ResponseWriter, r *h
193194

194195
outData := variablesToOutData(vars.Details)
195196
switch format {
196-
case "yaml":
197+
case constant.YamlFormat:
197198
exporter = &YAMLVariableExporter{OutData: outData}
198199
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%d_%s_%s_variable.yaml",
199200
kt.BizID, app.Spec.Name, rel.Spec.Name))
200201
w.Header().Set("Content-Type", "application/x-yaml")
201-
case "json":
202+
case constant.JsonFormat:
202203
exporter = &JSONVariableExporter{OutData: outData}
203204
w.Header().Set("Content-Type", "application/json")
204205
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%d_%s_%s_variable.json",

cmd/cache-service/service/cache/client/released_kv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import (
2222
"github.com/TencentBlueKing/bk-bscp/pkg/criteria/errf"
2323
"github.com/TencentBlueKing/bk-bscp/pkg/kit"
2424
"github.com/TencentBlueKing/bk-bscp/pkg/logs"
25+
pbds "github.com/TencentBlueKing/bk-bscp/pkg/protocol/data-service"
2526
"github.com/TencentBlueKing/bk-bscp/pkg/runtime/jsoni"
2627
"github.com/TencentBlueKing/bk-bscp/pkg/tools"
2728
"github.com/TencentBlueKing/bk-bscp/pkg/types"
28-
pbds "github.com/TencentBlueKing/bk-bscp/pkg/protocol/data-service"
2929
)
3030

3131
// GetReleasedKv get released kv from cache.

cmd/cache-service/service/cache/event/update_last_consumed_time.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ func (cm *ClientMetric) getLastConsumedTimeList(kt *kit.Kit, key string, listLen
6363
continue
6464
}
6565
appIDs := parseAndFilterJSON(list)
66-
if err := cm.op.BatchUpdateLastConsumedTime(kt, appIDs); err != nil {
67-
logs.Errorf("batch upsert client metrics failed, rid: %s, err: %s", kt.Rid, err.Error())
66+
if errB := cm.op.BatchUpdateLastConsumedTime(kt, appIDs); errB != nil {
67+
logs.Errorf("batch upsert client metrics failed, rid: %s, err: %s", kt.Rid, errB.Error())
6868
continue
6969
}
7070

cmd/config-server/service/credential.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
"github.com/TencentBlueKing/bk-bscp/pkg/iam/meta"
2121
"github.com/TencentBlueKing/bk-bscp/pkg/kit"
2222
"github.com/TencentBlueKing/bk-bscp/pkg/logs"
23-
"github.com/TencentBlueKing/bk-bscp/pkg/tools"
2423
pbcs "github.com/TencentBlueKing/bk-bscp/pkg/protocol/config-server"
2524
pbcredential "github.com/TencentBlueKing/bk-bscp/pkg/protocol/core/credential"
2625
pbds "github.com/TencentBlueKing/bk-bscp/pkg/protocol/data-service"
26+
"github.com/TencentBlueKing/bk-bscp/pkg/tools"
2727
)
2828

2929
// CreateCredentials create a credential

cmd/config-server/service/kv.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"golang.org/x/sync/errgroup"
2929
"gopkg.in/yaml.v3"
3030

31+
cs "github.com/TencentBlueKing/bk-bscp/internal/criteria/constant"
3132
"github.com/TencentBlueKing/bk-bscp/pkg/criteria/constant"
3233
"github.com/TencentBlueKing/bk-bscp/pkg/criteria/errf"
3334
"github.com/TencentBlueKing/bk-bscp/pkg/dal/table"
@@ -496,14 +497,14 @@ func (s *Service) ImportKvs(ctx context.Context, req *pbcs.ImportKvsReq) (*pbcs.
496497
// format:text、json、yaml
497498
var kvMap map[string]interface{}
498499
switch req.Format {
499-
case "json":
500+
case cs.JsonFormat:
500501
if !json.Valid([]byte(req.GetData())) {
501502
return nil, errors.New(i18n.T(grpcKit, "not legal JSON data"))
502503
}
503504
if err := json.Unmarshal([]byte(req.GetData()), &kvMap); err != nil {
504505
return nil, errors.New(i18n.T(grpcKit, "json format error, err: %v", err))
505506
}
506-
case "yaml":
507+
case cs.YamlFormat:
507508
if err := yaml.Unmarshal([]byte(req.GetData()), &kvMap); err != nil {
508509
return nil, errors.New(i18n.T(grpcKit, "yaml format error, err: %v", err))
509510
}

0 commit comments

Comments
 (0)