Skip to content

Commit

Permalink
feat: add stream ci for lint (merge request !1614)
Browse files Browse the repository at this point in the history
Squash merge branch 'feat/stream' into 'master'
feat: add stream ci for lint
  • Loading branch information
adevjoe authored and ifooth committed Feb 19, 2024
1 parent a6b7e6f commit 556eabe
Show file tree
Hide file tree
Showing 125 changed files with 4,180 additions and 1,692 deletions.
43 changes: 43 additions & 0 deletions .ci/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: v2.0

on:
push: [ master ]
mr: [ master, v1.* ]

stages:
- name: lint
jobs:
prepare:
steps:
- checkout: self
name: 拉取代码
- run: |
dir_json="$(find . -type f -name '.golangci.yml' -exec dirname {} \; | sed 's|^\./||' | sort -u | jq -c -R -s 'split("\n") | map(select(. != "")) | {dirs: .}')"
echo "::set-output name=parameters::$dir_json"
id: set-matrix
name: 矩阵参数生成
- run: |
bcs_image=${{ settings.bcs_docker_image.password }}
echo "::set-output name=parameters::$bcs_image"
id: set-image
name: 镜像参数设置
build:
depend-on:
- prepare
strategy:
matrix: ${{ fromJSON(jobs.prepare.steps.set-matrix.outputs.parameters) }}
max-parallel: 20
name: ${{ matrix.dirs }} 代码检查
runs-on:
pool-name: docker
container:
image: ${{ jobs.prepare.steps.set-image.outputs.parameters }}
steps:
- checkout: self
name: 拉取代码
- run: |
wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.54.2
mv ./bin/golangci-lint /usr/bin/golangci-lint
cd ${{ matrix.dirs }}
go mod tidy
CGO_ENABLED=0 golangci-lint run
41 changes: 21 additions & 20 deletions .code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,23 @@ source:
#用于匹配文件; 匹配方式为正则表达式。
filepath_regex:
# Deprecated module
- /bcs-services/bcs-argocd-manager/
- /bcs-services/bcs-log-manager/
- /bcs-services/bcs-mesh-manager/.*
- /bcs-services/bcs-api/.*
- /bcs-services/bcs-alert-manager/.*
- /bcs-services/bcs-log-manager/.*
- /bcs-services/bcs-netservice/.*
- /bcs-services/bcs-netservice/bcs-ipam/.*
- /bcs-services/bcs-argocd-manager/.*
- /bcs-services/bcs-client/.*
- /bcs-runtime/bcs-k8s/kubebkbcs/.*
- /bcs-runtime/bcs-k8s/kubedeprecated/.*
- /bcs-runtime/bcs-k8s/bcs-component/bcs-k8s-driver/.*
- /bcs-services/bcs-upgrader/.*
- /bcs-services/bcs-service-prometheus/.*
- /bcs-network/.*
- /bcs-runtime/bcs-mesos/.*
- /bcs-runtime/bcs-k8s/bcs-component/bcs-cc-agent/.*
- /bcs-runtime/bcs-k8s/bcs-component/bcs-cpuset-device/.*

# Comment ratio
- /bcs-services/bcs-bscp/cmd/data-service/service/config_item.go
Expand All @@ -17,7 +32,6 @@ source:
- /bcs-services/bcs-bscp/test/mock/repo/service/node.go
- /bcs-services/bcs-cli/bcs-user-manager/cmd/create.go
- /bcs-services/bcs-cluster-manager/internal/cloudprovider/qcloud/tasks/createNodeGroup.go
- /bcs-services/bcs-mesh-manager/config/options.go
- /bcs-services/bcs-upgrader/upgrades/u1.21.202203082112/migrate.go
- /bcs-services/bcs-upgrader/upgrades/u1.21.202203082112/types.go
- /bcs-services/bcs-cluster-manager/internal/cloudprovider/qcloud/tasks/createNodeGroup.go
Expand All @@ -28,8 +42,6 @@ source:
- /bcs-common/go.mod
- /bcs-runtime/bcs-k8s/bcs-component/bcs-cluster-autoscaler/bcs-cluster-autoscaler-1.16/go.mod
- /bcs-runtime/bcs-k8s/bcs-component/bcs-cluster-autoscaler/bcs-cluster-autoscaler-1.22/go.mod
- /bcs-services/bcs-alert-manager/go.mod
- /bcs-services/bcs-client/go.mod
- /bcs-services/bcs-data-manager/go.mod
- /bcs-services/bcs-gateway-discovery/plugins/t/bcs-auth.t
- /bcs-services/bcs-k8s-watch/go.mod
Expand All @@ -41,6 +53,10 @@ source:
- /bcs-scenarios/kourse
- /bcs-common/pkg/bcsapi/storage/tkex/gamedeployment/v1alpha1/gamedeployment.go
- /bcs-common/pkg/bcsapiv4/storage/tkex/gamedeployment/v1alpha1/gamedeployment.go
- /bcs-common/pkg/bcsapi/storage/tkex/gamestatefulset/v1alpha1/gamestatefulset.go
- /bcs-common/pkg/bcsapiv4/storage/tkex/gamestatefulset/v1alpha1/gamestatefulset.go
- /bcs-common/pkg/bcsapi/storage/tkex/generalpodautoscaler/v1alpha1/generalpodautoscaler.go
- /bcs-common/pkg/bcsapiv4/storage/tkex/generalpodautoscaler/v1alpha1/generalpodautoscaler.go
- /bcs-common/pkg/esb/apigateway/bkdata/types.go
- /bcs-runtime/bcs-k8s/bcs-component/bcs-cluster-autoscaler/core/scale_up.go
- /bcs-runtime/bcs-k8s/bcs-component/bcs-cluster-autoscaler/simulator/drain.go
Expand All @@ -64,29 +80,14 @@ source:
- /bcs-runtime/bcs-k8s/bcs-network/internal/.*
- /bcs-runtime/bcs-k8s/bcs-network/pkg/.*
- /bcs-runtime/bcs-k8s/bcs-network/qcloud-eip/.*
- /bcs-runtime/bcs-k8s/kubebkbcs/.*
- /bcs-runtime/bcs-k8s/kubedeprecated/.*
- /bcs-runtime/bcs-k8s/kubernetes/.*
- /bcs-runtime/bcs-mesos/bcs-clb-controller/.*
- /bcs-runtime/bcs-mesos/bcs-container-executor/.*
- /bcs-runtime/bcs-mesos/bcs-dns/.*
- /bcs-runtime/bcs-mesos/bcs-hpacontroller/.*
- /bcs-runtime/bcs-mesos/bcs-loadbalance/.*
- /bcs-runtime/bcs-mesos/bcs-mesos-driver/.*
- /bcs-runtime/bcs-mesos/bcs-mesos-watch/.*
- /bcs-runtime/bcs-mesos/bcs-scheduler/.*
- /bcs-runtime/bcs-mesos/bmsf-mesh/pkg/.*
- /bcs-runtime/bcs-mesos/kubebkbcsv2/.*
- /bcs-runtime/bcs-mesos/mesosv2/.*
- /bcs-runtime/bcs-mesos/pkg/.*
- /bcs-services/bcs-bscp/pkg/version/version.go
- /bcs-services/bcs-clb-controller/apis/.*
- /bcs-services/bcs-clb-controller/client/.*
- /bcs-services/bcs-cluster-manager/api/.*
- /bcs-services/bcs-cluster-manager/internal/cloudprovider/component/.*
- /bcs-services/bcs-cluster-manager/internal/cloudprovider/qcloud/api/common_.*
- /bcs-services/bcs-data-manager/pkg/mock/.*
- /bcs-services/bcs-mesh-manager/api/.*

# 提供产品代码库中工具或框架自动生成的且在代码库中的代码,没有可为空。以便后续代码统计环节进行排除等特殊处理。
auto_generate_source:
Expand Down
68 changes: 37 additions & 31 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
run:
timeout: 10m

skip-dirs:
- bcs-services/bcs-upgrader
- bcs-services/bcs-service-prometheus
- bcs-network
- bcs-runtime/bcs-mesos
- bcs-runtime/bcs-k8s/bcs-component/bcs-cc-agent
- bcs-runtime/bcs-k8s/bcs-component/bcs-cpuset-device
- .*/third_party/*
skip-files:
- .*\.docs\.go$
- .*\.gen\.go$
- .*\.pb\.go$
- .*\.pb.gw\.go$
- .*\.pb.micro\.go$
- .*\.pb.validate\.go$
- .*\_test\.go$
issues:
# 显示所有 issue
max-issues-per-linter: 0
max-same-issues: 0
exclude-use-default: false

linters:
disable-all: true
enable:
# enable by default
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused

# custom
- funlen
# - gci
- gci
- goconst
- gocritic
- gocyclo
Expand All @@ -34,9 +44,7 @@ linters:
- revive
- unconvert
- unparam

linters-settings:
# 只开启特定的规则
errcheck:
exclude-functions:
- (*os.File).Close
Expand All @@ -46,39 +54,39 @@ linters-settings:
- io.Copy
- os.RemoveAll
lll:
line-length: 120 # widely used and popular community recommended length
line-length: 120
funlen:
lines: 90 # 函数长度 default * 1.5
statements: -1 # 不限制语句数量, 通过圈复杂度处理
lines: 90
statements: -1
gocyclo:
min-complexity: 30 # 函数圈复杂度
min-complexity: 30
govet:
check-shadowing: true
# goimports:
# local-prefixes: github.com/Tencent/bk-bcs
# gci:
# sections:
# - standard
# - default
# - prefix(github.com/Tencent/bk-bcs)
goimports:
local-prefixes: github.com/Tencent/bk-bcs
gci:
sections:
- standard
- default
- prefix(github.com/Tencent/bk-bcs)
gocritic:
settings:
ifElseChain:
minThreshold: 3
gosec:
includes:
- G201 # SQL query construction using format string
- G202 # SQL query construction using string concatenation
- G101 # Look for hard coded credentials
- G401 # Detect the usage of DES, RC4, MD5 or SHA1
- G402 # Look for bad TLS connection settings
- G403 # Ensure minimum RSA key length of 2048 bits
- G404 # Insecure random number source (rand)
- G504 # Import blocklist: net/http/cgi
- G201
- G202
- G101
- G401
- G402
- G403
- G404
- G504
goheader:
values:
regexp:
YEAR: 20\d\d # 头部时间变量, 如: 2019等, 新增的为当前年份即可
YEAR: 20\d\d
template: |-
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) {{ YEAR }} THL A29 Limited, a Tencent company. All rights reserved.
Expand Down Expand Up @@ -110,6 +118,4 @@ linters-settings:
- name: range
- name: receiver-naming
- name: time-naming
# - name: unexported-return
- name: var-declaration
# - name: var-naming
61 changes: 36 additions & 25 deletions bcs-common/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
# Code generated by scripts/gen-lint. DO NOT EDIT.

run:
timeout: 10m

skip-dirs:
- bcs-services/bcs-upgrader
- bcs-services/bcs-service-prometheus
- bcs-network
- bcs-runtime/bcs-mesos
- bcs-runtime/bcs-k8s/bcs-component/bcs-cc-agent
- bcs-runtime/bcs-k8s/bcs-component/bcs-cpuset-device
- .*/third_party/*
skip-files:
- .*\.docs\.go$
- .*\.gen\.go$
- .*\.pb\.go$
- .*\.pb.gw\.go$
- .*\.pb.micro\.go$
- .*\.pb.validate\.go$
- .*\_test\.go$
- pkg/bcsapi/storage/tkex/gamedeployment/v1alpha1/gamedeployment.go
- pkg/bcsapiv4/storage/tkex/gamedeployment/v1alpha1/gamedeployment.go
- pkg/bcsapi/storage/tkex/gamestatefulset/v1alpha1/gamestatefulset.go
- pkg/bcsapiv4/storage/tkex/gamestatefulset/v1alpha1/gamestatefulset.go
- pkg/bcsapi/storage/tkex/generalpodautoscaler/v1alpha1/generalpodautoscaler.go
- pkg/bcsapiv4/storage/tkex/generalpodautoscaler/v1alpha1/generalpodautoscaler.go
- pkg/esb/apigateway/bkdata/types.go
issues:
# 显示所有 issue
max-issues-per-linter: 0
max-same-issues: 0
exclude-use-default: false

linters:
disable-all: true
enable:
# enable by default
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused

# custom
- funlen
- gci
- goconst
Expand All @@ -36,9 +51,7 @@ linters:
- revive
- unconvert
- unparam

linters-settings:
# 只开启特定的规则
errcheck:
exclude-functions:
- (*os.File).Close
Expand All @@ -48,12 +61,12 @@ linters-settings:
- io.Copy
- os.RemoveAll
lll:
line-length: 120 # widely used and popular community recommended length
line-length: 120
funlen:
lines: 90 # 函数长度 default * 1.5
statements: -1 # 不限制语句数量, 通过圈复杂度处理
lines: 90
statements: -1
gocyclo:
min-complexity: 30 # 函数圈复杂度
min-complexity: 30
govet:
check-shadowing: true
goimports:
Expand All @@ -69,18 +82,18 @@ linters-settings:
minThreshold: 3
gosec:
includes:
- G201 # SQL query construction using format string
- G202 # SQL query construction using string concatenation
- G101 # Look for hard coded credentials
- G401 # Detect the usage of DES, RC4, MD5 or SHA1
- G402 # Look for bad TLS connection settings
- G403 # Ensure minimum RSA key length of 2048 bits
- G404 # Insecure random number source (rand)
- G504 # Import blocklist: net/http/cgi
- G201
- G202
- G101
- G401
- G402
- G403
- G404
- G504
goheader:
values:
regexp:
YEAR: 20\d\d # 头部时间变量, 如: 2019等, 新增的为当前年份即可
YEAR: 20\d\d
template: |-
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) {{ YEAR }} THL A29 Limited, a Tencent company. All rights reserved.
Expand Down Expand Up @@ -112,6 +125,4 @@ linters-settings:
- name: range
- name: receiver-naming
- name: time-naming
# - name: unexported-return
- name: var-declaration
# - name: var-naming
Loading

0 comments on commit 556eabe

Please sign in to comment.