diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 0000000000000000000000000000000000000000..77c30df451a127ccaa1403edd0b92722dd1207d5 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,24 @@ +--- +version: "2" +plugins: + structure: + enabled: false + duplication: + enabled: false + gofmt: + enabled: true + golint: + enabled: true + govet: + enabled: true + gocyclo: + enabled: true + config: + over: 9 + fixme: + enabled: false + shellcheck: + enabled: false +exclude_patterns: +- vendor/ +- .GOPATH/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 32819b76d1c8485079aed8bad5a0db467fdb16a6..b4d61a04fdf4a6397dc1131ba3178998a7f48542 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,6 +17,20 @@ license_management: variables: SETUP_CMD: echo "Skip setup. Dependency already vendored" +code_quality: + image: docker:19.03-git + services: + - docker:19.03-dind + variables: + DOCKER_DRIVER: overlay2 + CODECLIMATE_FORMAT: json + dependencies: [] + script: + - ./scripts/codequality analyze -f json --dev | tee gl-code-quality-report.json + artifacts: + paths: [gl-code-quality-report.json] + expire_in: 7d + verify: image: golang:1.11 script: diff --git a/Makefile.util.mk b/Makefile.util.mk index 626d146b41c0cd5bff7e54cfc8e25e53d9deb0e2..44a94b6acfa1cb264d5d5bcfb8a348e2c3ca71bb 100644 --- a/Makefile.util.mk +++ b/Makefile.util.mk @@ -1,7 +1,10 @@ -.PHONY: verify fmt vet lint complexity test cover list +.PHONY: verify fmt vet lint complexity test cover list codequality verify: list fmt vet lint complexity +codequality: + ./scripts/codequality analyze --dev + fmt: bin/goimports .GOPATH/.ok $Q @./bin/goimports -local $(IMPORT_PATH) -l $(allfiles) | awk '{ print } END { if (NR>0) { print "Please run ./bin/goimports -w -local $(IMPORT_PATH) -l $(allfiles)"; exit 1 } }' diff --git a/scripts/codequality b/scripts/codequality new file mode 100755 index 0000000000000000000000000000000000000000..820281d407321c14b714d498fdcb3478dbc7454d --- /dev/null +++ b/scripts/codequality @@ -0,0 +1,21 @@ +#!/bin/sh + +set -eo pipefail + +code_path=$(pwd) + +# docker run --tty will merge stderr and stdout, we don't need this on CI or +# it will break codequality json file +[ "$CI" != "" ] || docker_tty="--tty" + +# Preparing gocyclo analyzer +docker pull registry.gitlab.com/nolith/codeclimate-gocyclo > /dev/null +docker tag registry.gitlab.com/nolith/codeclimate-gocyclo codeclimate/codeclimate-gocyclo > /dev/null + +# Executing codeclimate check +exec docker run --rm $docker_tty --env CODECLIMATE_CODE="$code_path" \ + --volume "$code_path":/code \ + --volume /var/run/docker.sock:/var/run/docker.sock \ + --volume /tmp/cc:/tmp/cc \ + codeclimate/codeclimate:0.85.5 "$@" +