From fcc4821ce03aa2f1c44c9a4b705f691e648de0d4 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 28 May 2020 09:57:33 +1000 Subject: Use custom code_quality job inspired by the runner --- .gitlab-ci.yml | 19 +++++++++++-------- Makefile.build.mk | 2 +- Makefile.util.mk | 11 +++++++---- go.mod | 3 +++ go.sum | 7 +++++-- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bb87d51f..2b2bbf0f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -99,20 +99,23 @@ cover: paths: - coverage.html -lint: - extends: .go-mod-cache +code_quality: stage: test needs: ['download deps'] - image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine + extends: .go-mod-cache + image: golangci/golangci-lint:v1.27.0 + variables: + REPORT_FILE: gl-code-quality-report.json + LINT_FLAGS: "--issues-exit-code 0 --color never --deadline 15m" + OUT_FORMAT: code-climate script: - # Write the code coverage report to gl-code-quality-report.json - # and print linting issues to stdout in the format: path/to/file:line description - - golangci-lint run --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | "\(.location.path):\(.location.lines.begin) \(.description)"' + - make lint | tee ${REPORT_FILE} + timeout: 15 minutes artifacts: reports: - codequality: gl-code-quality-report.json + codequality: ${REPORT_FILE} paths: - - gl-code-quality-report.json + - ${REPORT_FILE} test:1.12: extends: .tests diff --git a/Makefile.build.mk b/Makefile.build.mk index b203cf4f..9cfcf69b 100644 --- a/Makefile.build.mk +++ b/Makefile.build.mk @@ -1,4 +1,4 @@ -GOLANGCI_LINT_VERSION := v1.25.1 # version used by $GOLANGCI_LINT_IMAGE +GOLANGCI_LINT_VERSION := v1.27.0 # version used by $GOLANGCI_LINT_IMAGE .PHONY: all setup generate-mocks build clean diff --git a/Makefile.util.mk b/Makefile.util.mk index c49b58bb..3f483647 100644 --- a/Makefile.util.mk +++ b/Makefile.util.mk @@ -1,14 +1,17 @@ # Dockerfile https://gitlab.com/gitlab-org/gitlab-build-images/-/blob/master/Dockerfile.golangci-lint-alpine -GOLANGCI_LINT_IMAGE := registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine +GOLANGCI_LINT_IMAGE := golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) -.PHONY: lint test race acceptance bench cover list deps-check deps-download +.PHONY: lint lint-docker test race acceptance bench cover list deps-check deps-download + +OUT_FORMAT ?= colored-line-number +LINT_FLAGS ?= $(if $V,-v) lint: .GOPATH/.ok bin/golangci-lint - $Q ./bin/golangci-lint run $(if $V,-v) + $Q ./bin/golangci-lint run ./... --out-format $(OUT_FORMAT) $(LINT_FLAGS) lint-docker: docker run -v $(PWD):/app -w /app $(GOLANGCI_LINT_IMAGE) \ - sh -c "golangci-lint run --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | \"\(.location.path):\(.location.lines.begin) \(.description)\"'" + sh -c "golangci-lint run ./... --out-format $(OUT_FORMAT) $(LINT_FLAGS)" test: .GOPATH/.ok gitlab-pages go test $(if $V,-v) $(allpackages) diff --git a/go.mod b/go.mod index c18dc1ae..84a99d32 100644 --- a/go.mod +++ b/go.mod @@ -29,5 +29,8 @@ require ( golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f golang.org/x/net v0.0.0-20200226121028-0de0cce0169b golang.org/x/sys v0.0.0-20200113162924-86b910548bc1 + golang.org/x/tools v0.0.0-20200502202811-ed308ab3e770 + gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect gopkg.in/yaml.v2 v2.2.8 + honnef.co/go/tools v0.0.1-2020.1.3 // indirect ) diff --git a/go.sum b/go.sum index a2783950..830b1603 100644 --- a/go.sum +++ b/go.sum @@ -440,11 +440,12 @@ golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200117161641-43d50277825c h1:2EA2K0k9bcvvEDlqD8xdlOhCOqq+O/p9Voqi4x9W1YU= golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200422022333-3d57cf2e726e h1:3Dzrrxi54Io7Aoyb0PYLsI47K2TxkRQg+cqUn+m04do= -golang.org/x/tools v0.0.0-20200422022333-3d57cf2e726e/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200502202811-ed308ab3e770 h1:M9Fif0OxNji8w+HvmhVQ8KJtiZOsjU9RgslJGhn95XE= +golang.org/x/tools v0.0.0-20200502202811-ed308ab3e770/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= @@ -506,4 +507,6 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= -- cgit v1.2.3