You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2023/04/06 06:41:21 UTC
[shardingsphere-on-cloud] branch main updated: chore(ci): add golangci-lint (#295)
This is an automated email from the ASF dual-hosted git repository.
sunnianjun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shardingsphere-on-cloud.git
The following commit(s) were added to refs/heads/main by this push:
new a849b35 chore(ci): add golangci-lint (#295)
a849b35 is described below
commit a849b355cebe62e69c1403040d5b449a0543e190
Author: liyao <ma...@126.com>
AuthorDate: Thu Apr 6 14:41:15 2023 +0800
chore(ci): add golangci-lint (#295)
* chore(ci): add golangci-lint to github action
Signed-off-by: mlycore <ma...@126.com>
* chore(ci): seperate unit tests
Signed-off-by: mlycore <ma...@126.com>
* chore(ci): add golangci-lint for pitr
Signed-off-by: mlycore <ma...@126.com>
* chore(ci): fix license header
Signed-off-by: mlycore <ma...@126.com>
---------
Signed-off-by: mlycore <ma...@126.com>
---
.github/workflows/golint.yml | 58 +++++++++++++++
.../{unit-test.yml => operator-unit-test.yml} | 20 +----
.../{unit-test.yml => pitr-unit-test.yml} | 18 -----
pitr/agent/.golangci.yml | 86 ++++++++++++++++++++++
pitr/cli/.golangci.yml | 85 +++++++++++++++++++++
5 files changed, 230 insertions(+), 37 deletions(-)
diff --git a/.github/workflows/golint.yml b/.github/workflows/golint.yml
new file mode 100644
index 0000000..d7e4fdb
--- /dev/null
+++ b/.github/workflows/golint.yml
@@ -0,0 +1,58 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+name: golangci-lint
+
+on:
+ push:
+ branches:
+ - main
+ pull_request:
+ branches:
+ - main
+
+jobs:
+ changes:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ golangci-lint:
+ name: lint
+ needs: changes
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - name: Setup Go Env
+ uses: actions/setup-go@v3
+ with:
+ go-version: '1.19'
+ - name: Download golangci-lint
+ run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.49.0
+ - name: Lint ShardingSphere-Operator
+ run: |
+ cd shardingsphere-operator/
+ $(go env GOPATH)/bin/golangci-lint run -v --timeout 300s ./...
+ - name: Lint Pitr Cli
+ run: |
+ cd pitr/cli
+ $(go env GOPATH)/bin/golangci-lint run -v --timeout 300s ./...
+ - name: Lint Pitr Agent
+ run: |
+ cd pitr/gent
+ $(go env GOPATH)/bin/golangci-lint run -v --timeout 300s ./...
diff --git a/.github/workflows/unit-test.yml b/.github/workflows/operator-unit-test.yml
similarity index 73%
copy from .github/workflows/unit-test.yml
copy to .github/workflows/operator-unit-test.yml
index 5e77403..d8a2149 100644
--- a/.github/workflows/unit-test.yml
+++ b/.github/workflows/operator-unit-test.yml
@@ -22,8 +22,7 @@ on:
branches: [ main ]
paths:
- 'shardingsphere-operator/**'
- - 'pitr/**'
- - '.github/workflows/unit-test.yml'
+ - '.github/workflows/operator-unit-test.yml'
jobs:
operator:
runs-on: ubuntu-latest
@@ -42,20 +41,3 @@ jobs:
uses: codecov/codecov-action@v3
with:
files: ./shardingsphere-operator/coverage.txt
- pitr-cli:
- runs-on: ubuntu-latest
- steps:
- - name: "checkout codes"
- uses: actions/checkout@v3
- - name: "setup go"
- uses: actions/setup-go@v4
- with:
- go-version: '^1.18.1'
- - name: "unit test"
- run: |
- cd pitr/cli
- make test
- - name: "Code coverage"
- uses: codecov/codecov-action@v3
- with:
- files: ./pitr/cli/cover.out
diff --git a/.github/workflows/unit-test.yml b/.github/workflows/pitr-unit-test.yml
similarity index 73%
rename from .github/workflows/unit-test.yml
rename to .github/workflows/pitr-unit-test.yml
index 5e77403..560f31f 100644
--- a/.github/workflows/unit-test.yml
+++ b/.github/workflows/pitr-unit-test.yml
@@ -21,27 +21,9 @@ on:
pull_request:
branches: [ main ]
paths:
- - 'shardingsphere-operator/**'
- 'pitr/**'
- '.github/workflows/unit-test.yml'
jobs:
- operator:
- runs-on: ubuntu-latest
- steps:
- - name: "checkout codes"
- uses: actions/checkout@v3
- - name: "setup go"
- uses: actions/setup-go@v4
- with:
- go-version: '^1.18.1'
- - name: "unit test"
- run: |
- cd shardingsphere-operator
- make test
- - name: "Code coverage"
- uses: codecov/codecov-action@v3
- with:
- files: ./shardingsphere-operator/coverage.txt
pitr-cli:
runs-on: ubuntu-latest
steps:
diff --git a/pitr/agent/.golangci.yml b/pitr/agent/.golangci.yml
new file mode 100644
index 0000000..b7d0d56
--- /dev/null
+++ b/pitr/agent/.golangci.yml
@@ -0,0 +1,86 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+
+run:
+ timeout: 10m
+linters:
+ disable-all: true
+ enable:
+ - ineffassign
+ - typecheck
+ - varcheck
+ - unused
+ - structcheck
+ - deadcode
+ - gosimple
+ - goimports
+ - errcheck
+ - staticcheck
+ - stylecheck
+ - gosec
+ - asciicheck
+ - bodyclose
+ - exportloopref
+ - rowserrcheck
+ - makezero
+ - durationcheck
+ - prealloc
+ - predeclared
+
+# Refers: https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322
+linters-settings:
+ cyclop:
+ # The maximal code complexity to report.
+ # Default: 10
+ max-complexity: 30
+ # The maximal average package complexity.
+ # If it's higher than 0.0 (float) the check is enabled
+ # Default: 0.0
+ package-average: 10.0
+ errcheck:
+ # Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
+ # Such cases aren't reported by default.
+ # Default: false
+ check-type-assertions: true
+ exhaustive:
+ # Program elements to check for exhaustiveness.
+ # Default: [ switch ]
+ check:
+ - switch
+ - map
+ funlen:
+ # Checks the number of lines in a function.
+ # If lower than 0, disable the check.
+ # Default: 60
+ lines: 100
+ # Checks the number of statements in a function.
+ # If lower than 0, disable the check.
+ # Default: 40
+ statements: 50
+ gocognit:
+ # Minimal code complexity to report.
+ # Default: 30 (but we recommend 10-20)
+ min-complexity: 20
+issues:
+ exclude-rules:
+ - path: _test\.go
+ linters:
+ - errcheck
+ - gosec
+ - rowserrcheck
+ - makezero
diff --git a/pitr/cli/.golangci.yml b/pitr/cli/.golangci.yml
new file mode 100644
index 0000000..1b9b6ce
--- /dev/null
+++ b/pitr/cli/.golangci.yml
@@ -0,0 +1,85 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+run:
+ timeout: 10m
+linters:
+ disable-all: true
+ enable:
+ - ineffassign
+ - typecheck
+ - varcheck
+ - unused
+ - structcheck
+ - deadcode
+ - gosimple
+ - goimports
+ - errcheck
+ - staticcheck
+ - stylecheck
+ - gosec
+ - asciicheck
+ - bodyclose
+ - exportloopref
+ - rowserrcheck
+ - makezero
+ - durationcheck
+ - prealloc
+ - predeclared
+
+# Refers: https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322
+linters-settings:
+ cyclop:
+ # The maximal code complexity to report.
+ # Default: 10
+ max-complexity: 30
+ # The maximal average package complexity.
+ # If it's higher than 0.0 (float) the check is enabled
+ # Default: 0.0
+ package-average: 10.0
+ errcheck:
+ # Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
+ # Such cases aren't reported by default.
+ # Default: false
+ check-type-assertions: true
+ exhaustive:
+ # Program elements to check for exhaustiveness.
+ # Default: [ switch ]
+ check:
+ - switch
+ - map
+ funlen:
+ # Checks the number of lines in a function.
+ # If lower than 0, disable the check.
+ # Default: 60
+ lines: 100
+ # Checks the number of statements in a function.
+ # If lower than 0, disable the check.
+ # Default: 40
+ statements: 50
+ gocognit:
+ # Minimal code complexity to report.
+ # Default: 30 (but we recommend 10-20)
+ min-complexity: 20
+issues:
+ exclude-rules:
+ - path: _test\.go
+ linters:
+ - errcheck
+ - gosec
+ - rowserrcheck
+ - makezero