From c43f7d816d009a42b6061891ad93bfcfd63c254a Mon Sep 17 00:00:00 2001 From: Stanislav Bogatyrev Date: Mon, 21 Sep 2020 21:17:49 +0300 Subject: [PATCH] cicd: Update GH Actions setup - Update GH Actions workflow for go test - Add golangci linter config from neofs-node - Add DCO check for PR commits Signed-off-by: Stanislav Bogatyrev --- .github/workflows/dco.yml | 21 ++++++ .github/workflows/go.yml | 69 ++++++++----------- .golangci.yml | 136 ++++++++++++++++++++++++++++++++++++++ Makefile | 29 +++++++- 4 files changed, 213 insertions(+), 42 deletions(-) create mode 100644 .github/workflows/dco.yml create mode 100644 .golangci.yml diff --git a/.github/workflows/dco.yml b/.github/workflows/dco.yml new file mode 100644 index 0000000..40ed8fc --- /dev/null +++ b/.github/workflows/dco.yml @@ -0,0 +1,21 @@ +name: DCO check + +on: + pull_request: + branches: + - master + +jobs: + commits_check_job: + runs-on: ubuntu-latest + name: Commits Check + steps: + - name: Get PR Commits + id: 'get-pr-commits' + uses: tim-actions/get-pr-commits@master + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: DCO Check + uses: tim-actions/dco@master + with: + commits: ${{ steps.get-pr-commits.outputs.commits }} diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index fc6aa8c..ab7b4a0 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,4 +1,5 @@ -name: Go +name: neofs-api-go tests + on: push: branches: @@ -10,58 +11,46 @@ on: - master paths-ignore: - '*.md' -jobs: +jobs: test: - name: test - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: matrix: go: [ '1.14.x', '1.15.x' ] steps: + - name: Setup go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} - - name: Setup go - uses: actions/setup-go@v1 - with: - go-version: ${{ matrix.go }} - id: go + - name: Check out code + uses: actions/checkout@v2 - - name: Check out code into the Go module directory - uses: actions/checkout@v2 + - name: Cache go mod + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-${{ matrix.go }}- - - name: Set GOPATH - # temporary fix - # see https://github.com/actions/setup-go/issues/14 - run: | - echo "##[set-env name=GOPATH;]$(dirname $GITHUB_WORKSPACE)" - echo "##[add-path]$(dirname $GITHUB_WORKSPACE)/bin" - shell: bash + - name: Get dependencies + run: make dep - - uses: actions/cache@v1 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- + - name: Run go test + run: go test -coverprofile=coverage.txt -covermode=atomic ./... - - name: Get dependencies - run: | - go mod tidy -v + - name: Codecov + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + run: bash <(curl -s https://codecov.io/bash) - - name: Tests - run: go test -coverprofile=coverage.txt -covermode=atomic ./... - - - name: Codecov - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - run: bash <(curl -s https://codecov.io/bash) - - golangci: - name: lint - runs-on: ubuntu-latest + lint: + runs-on: ubuntu-20.04 steps: - - - uses: actions/checkout@v2 + - name: Check out code + uses: actions/checkout@v2 - name: golangci-lint uses: golangci/golangci-lint-action@v2 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..7fc9abf --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,136 @@ +# https://habr.com/company/roistat/blog/413175/ +# https://github.com/golangci/golangci-lint +linters-settings: + govet: + check-shadowing: false + golint: + # minimal confidence for issues, default is 0.8 + min-confidence: 0.8 + gofmt: + # simplify code: gofmt with `-s` option, true by default + simplify: true + gocyclo: + min-complexity: 30 + maligned: + suggest-new: true + dupl: + threshold: 100 + goconst: + min-len: 2 + min-occurrences: 2 + gosimple: + gocritic: + # Which checks should be enabled; can't be combined with 'disabled-checks'; + # See https://go-critic.github.io/overview#checks-overview + # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run` + # By default list of stable checks is used. +# enabled-checks: +# - rangeValCopy + # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty + disabled-checks: + - regexpMust + # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint` run to see all tags and checks. + # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". + enabled-tags: + - performance + + settings: # settings passed to gocritic + captLocal: # must be valid enabled check name + paramsOnly: true + rangeValCopy: + sizeThreshold: 32 +# depguard: +# list-type: blacklist +# include-go-root: false +# packages: +# - github.com/davecgh/go-spew/spew + lll: + # max line length, lines longer will be reported. Default is 120. + # '\t' is counted as 1 character by default, and can be changed with the tab-width option + line-length: 120 + # tab width in spaces. Default to 1. + tab-width: 1 + unused: + # treat code as a program (not a library) and report unused exported identifiers; default is false. + # XXX: if you enable this setting, unused will report a lot of false-positives in text editors: + # if it's called for subdir of a project it can't find funcs usages. All text editor integrations + # with golangci-lint call it on a directory with the changed file. + check-exported: false + unparam: + # Inspect exported functions, default is false. Set to true if no external program/library imports your code. + # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: + # if it's called for subdir of a project it can't find external interfaces. All text editor integrations + # with golangci-lint call it on a directory with the changed file. + check-exported: false + nakedret: + # make an issue if func has more lines of code than this setting and it has naked returns; default is 30 + max-func-lines: 30 + + +linters: + enable-all: true + fast: false + disable: + - gochecknoglobals +# - maligned +# - prealloc +# disable-all: false +# presets: +# - bugs +# - unused + +# options for analysis running +run: + # default concurrency is a available CPU number +# concurrency: 8 + + # timeout for analysis, e.g. 30s, 5m, default is 1m +# deadline: 1m + + # exit code when at least one issue was found, default is 1 +# issues-exit-code: 1 + + # include test files or not, default is true +# tests: true + + # list of build tags, all linters use it. Default is empty list. +# build-tags: +# - mytag + + # which dirs to skip: they won't be analyzed; + # can use regexp here: generated.*, regexp is applied on full path; + # default value is empty list, but next dirs are always skipped independently + # from this option's value: + # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ +# skip-dirs: +# - src/external_libs +# - autogenerated_by_my_lib + + # which files to skip: they will be analyzed, but issues from them + # won't be reported. Default value is empty list, but there is + # no need to include all autogenerated files, we confidently recognize + # autogenerated files. If it's not please let us know. +# skip-files: +# - ".*\\.my\\.go$" +# - lib/bad.go + + # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules": + # If invoked with -mod=readonly, the go command is disallowed from the implicit + # automatic updating of go.mod described above. Instead, it fails when any changes + # to go.mod are needed. This setting is most useful to check that go.mod does + # not need updates, such as in a continuous integration and testing system. + # If invoked with -mod=vendor, the go command assumes that the vendor + # directory holds the correct copies of dependencies and ignores + # the dependency descriptions in go.mod. +# modules-download-mode: readonly|release|vendor + +# output configuration options +output: + # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" + format: tab + + # print lines of code with issue, default is true + print-issued-lines: true + + # print linter name in the end of issue text, default is true + print-linter-name: true \ No newline at end of file diff --git a/Makefile b/Makefile index cd9e535..3f3f1dd 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ #!/usr/bin/make -f SHELL = bash -.PHONY: dep fmts fmt imports protoc +VERSION ?= $(shell git describe --tags --dirty --always) + +.PHONY: dep fmts fmt imports protoc test lint version help # Pull go dependencies dep: @@ -35,7 +37,7 @@ imports: GO111MODULE=on goimports -w $$f; \ done -# Regenerate proto files: +# Regenerate code for proto files protoc: @GOPRIVATE=github.com/nspcc-dev go mod vendor # Install specific version for protobuf lib @@ -48,3 +50,26 @@ protoc: --gofast_out=plugins=grpc,paths=source_relative:. $$f; \ done rm -rf vendor + +# Run Unit Test with go test +test: + @echo "⇒ Runnning go test" + @GO111MODULE=on go test ./... + +# Run linters +lint: + @golangci-lint run + +# Print version +version: + @echo $(VERSION) + +# Show this help prompt +help: + @echo ' Usage:' + @echo '' + @echo ' make ' + @echo '' + @echo ' Targets:' + @echo '' + @awk '/^#/{ comment = substr($$0,3) } comment && /^[a-zA-Z][a-zA-Z0-9_-]+ ?:/{ print " ", $$1, comment }' $(MAKEFILE_LIST) | column -t -s ':' | grep -v 'IGNORE' | sort -u