From 4b1cbb934d841308889866e73315050ed50d5f51 Mon Sep 17 00:00:00 2001 From: Shantanu Kotambkar <52007797+skotambkar@users.noreply.github.com> Date: Thu, 29 Jul 2021 15:30:59 -0700 Subject: [PATCH] add ci task for error check linters (#1327) Adds a CI task to ensure SDK implementation checks for errors --- .github/workflows/golangci-lint.yml | 28 ++++++++++++++++++++++++++++ .golangci.toml | 27 +++++++++++++++++++++++++++ Makefile | 21 +++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .golangci.toml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 00000000000..41010c548ae --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,28 @@ +name: golangci-lint +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + golangci: + name: lint + runs-on: ${{ matrix.os }} + strategy: + matrix: + go-version: [1.16.x] + os: [ubuntu-latest] # other options: macos-latest, windows-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + # Required: the version of golangci-lint is required and must be specified without patch version + version: latest + # the following causes golangci-init to do nothing, so all it does is install golang and golangci + args: --version + # Show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + - name: run ci linter + run: make ci-lint diff --git a/.golangci.toml b/.golangci.toml new file mode 100644 index 00000000000..75e338858d4 --- /dev/null +++ b/.golangci.toml @@ -0,0 +1,27 @@ +[run] +concurrency = 4 +timeout = "1m" +issues-exit-code = 0 +modules-download-mode = "readonly" +allow-parallel-runners = true +skip-dirs = ["internal/repotools"] +skip-dirs-use-default = true + +[output] +format = "github-actions" + +[linters-settings.cyclop] +skip-tests = false + +[linters-settings.errcheck] +check-blank = true + +[linters] +disable-all = true +enable = ["errcheck"] +fast = false + +[issues] +exclude-use-default = false + +# Refer config definitions at https://golangci-lint.run/usage/configuration/#config-file diff --git a/Makefile b/Makefile index bb5a024dbe9..2ce85f2afae 100644 --- a/Makefile +++ b/Makefile @@ -316,6 +316,27 @@ ci-test-generate-validate: if [ "$$gitstatus" != "" ] && [ "$$gitstatus" != "skipping validation" ]; then echo "$$gitstatus"; exit 1; fi git update-index --no-assume-unchanged go.mod go.sum +ci-lint: ci-lint-. + +ci-lint-%: + @# Run golangci-lint command that uses the pattern to define the root path that the + @# module check will start from. Strips off the "ci-lint-" and + @# replaces all "_" with "/". + @# + @# e.g. ci-lint-internal_protocoltest + cd ./internal/repotools/cmd/eachmodule \ + && go run . -p $(subst _,/,$(subst ci-lint-,,$@)) \ + -fail-fast=false \ + -c 1 \ + -skip="internal/repotools" \ + "golangci-lint run" + +ci-lint-install: + @# Installs golangci-lint at GoPATH. + @# This should be used to run golangci-lint locally. + @# + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + ####################### # Integration Testing # #######################