From f72211f532e13c4a0bed74cfa3921fc0a47fb783 Mon Sep 17 00:00:00 2001 From: Oscar Tovar Date: Wed, 16 Nov 2022 15:48:56 -0500 Subject: [PATCH 1/4] ci: add golangci-lint linter --- .gitlab-ci.yml | 1 + .gitlab/ci/lint.gitlab-ci.yml | 2 +- .golangci.yml | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1a0f66321..d6cdee352 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -20,6 +20,7 @@ include: - template: Security/SAST.gitlab-ci.yml - template: Security/Dependency-Scanning.gitlab-ci.yml - template: Security/Secret-Detection.gitlab-ci.yml + - local: ".gitlab/ci/lint.gitlab-ci.yml" # From: https://docs.gitlab.com/ee/ci/caching/#cache-go-dependencies diff --git a/.gitlab/ci/lint.gitlab-ci.yml b/.gitlab/ci/lint.gitlab-ci.yml index 29ca259d7..eaa5da84a 100644 --- a/.gitlab/ci/lint.gitlab-ci.yml +++ b/.gitlab/ci/lint.gitlab-ci.yml @@ -7,7 +7,7 @@ lint: # 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 # remove `--issues-exit-code 0` or set to non-zero to fail the job if linting issues are detected - - golangci-lint run --issues-exit-code 0 --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | "\(.location.path):\(.location.lines.begin) \(.description)"' + - golangci-lint run --issues-exit-code 0 --out-format colored-line-number:stdout,code-climate:gl-code-quality-report.json artifacts: reports: codequality: gl-code-quality-report.json diff --git a/.golangci.yml b/.golangci.yml index f3f3e90f9..edc1852d8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,16 @@ linters: enable: - gofmt + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - typecheck + - unused + - exhaustive + - exportloopref + - prealloc run: timeout: 5m -- GitLab From 7046ce00cd1f7e312f8fd0f8e2a1bf26645f4c1b Mon Sep 17 00:00:00 2001 From: Oscar Tovar Date: Wed, 16 Nov 2022 15:54:52 -0500 Subject: [PATCH 2/4] ci: print golangci-lint version --- .gitlab/ci/lint.gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab/ci/lint.gitlab-ci.yml b/.gitlab/ci/lint.gitlab-ci.yml index eaa5da84a..eac294441 100644 --- a/.gitlab/ci/lint.gitlab-ci.yml +++ b/.gitlab/ci/lint.gitlab-ci.yml @@ -2,10 +2,10 @@ lint: image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine stage: test script: + - golangci-lint --version # Use default .golangci.yml file from the image if one is not present in the project root. - '[ -e .golangci.yml ] || cp /golangci/.golangci.yml .' # 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 # remove `--issues-exit-code 0` or set to non-zero to fail the job if linting issues are detected - golangci-lint run --issues-exit-code 0 --out-format colored-line-number:stdout,code-climate:gl-code-quality-report.json artifacts: -- GitLab From d986798c98e00a11e404bd223aedf3334bbf7aad Mon Sep 17 00:00:00 2001 From: Oscar Tovar Date: Wed, 16 Nov 2022 16:07:01 -0500 Subject: [PATCH 3/4] ci: fix broken gofmt linter --- .gitlab/ci/lint.gitlab-ci.yml | 11 ++++++++++- .golangci.yml | 1 - 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.gitlab/ci/lint.gitlab-ci.yml b/.gitlab/ci/lint.gitlab-ci.yml index eac294441..ce8bb32f8 100644 --- a/.gitlab/ci/lint.gitlab-ci.yml +++ b/.gitlab/ci/lint.gitlab-ci.yml @@ -2,12 +2,21 @@ lint: image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine stage: test script: + - FMT_CMD="gofmt -w ." + - eval "$FMT_CMD" + - | + if ! git diff --ignore-submodules=dirty --exit-code; then + echo "Some files are not formatted. Please format with \`$FMT_CMD\`" + exit 1; + fi - golangci-lint --version # Use default .golangci.yml file from the image if one is not present in the project root. - '[ -e .golangci.yml ] || cp /golangci/.golangci.yml .' # Write the code coverage report to gl-code-quality-report.json # remove `--issues-exit-code 0` or set to non-zero to fail the job if linting issues are detected - - golangci-lint run --issues-exit-code 0 --out-format colored-line-number:stdout,code-climate:gl-code-quality-report.json + - golangci-lint run --issues-exit-code 1 --out-format colored-line-number:stdout,code-climate:gl-code-quality-report.json + allow_failure: + exit_codes: 1 artifacts: reports: codequality: gl-code-quality-report.json diff --git a/.golangci.yml b/.golangci.yml index edc1852d8..8565474f2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,5 @@ linters: enable: - - gofmt - errcheck - gosimple - govet -- GitLab From 340ccf35887dc1039801bc6c1b3c509781440eff Mon Sep 17 00:00:00 2001 From: Oscar Tovar Date: Wed, 16 Nov 2022 16:25:48 -0500 Subject: [PATCH 4/4] ci: re-add gofmt linter --- .gitlab/ci/lint.gitlab-ci.yml | 7 ------- .golangci.yml | 1 + 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.gitlab/ci/lint.gitlab-ci.yml b/.gitlab/ci/lint.gitlab-ci.yml index ce8bb32f8..cad060149 100644 --- a/.gitlab/ci/lint.gitlab-ci.yml +++ b/.gitlab/ci/lint.gitlab-ci.yml @@ -2,13 +2,6 @@ lint: image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine stage: test script: - - FMT_CMD="gofmt -w ." - - eval "$FMT_CMD" - - | - if ! git diff --ignore-submodules=dirty --exit-code; then - echo "Some files are not formatted. Please format with \`$FMT_CMD\`" - exit 1; - fi - golangci-lint --version # Use default .golangci.yml file from the image if one is not present in the project root. - '[ -e .golangci.yml ] || cp /golangci/.golangci.yml .' diff --git a/.golangci.yml b/.golangci.yml index 8565474f2..ccf71c623 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,6 +2,7 @@ linters: enable: - errcheck - gosimple + - gofmt - govet - ineffassign - staticcheck -- GitLab