From 7243176e448ae7fc474ca64a2f8559d68e05c24e Mon Sep 17 00:00:00 2001 From: Ian Howell Date: Thu, 28 May 2020 15:34:44 -0500 Subject: [PATCH] Add golint as a non-voting gate Change-Id: I9850528a720ff517a3f400553fa8ab66bf4b1b3b Closes: #253 --- Makefile | 15 ++++++++----- playbooks/airship-airshipctl-golint.yaml | 20 +++++++++++++++++ tools/golint | 28 ++++++++++++++++++++++++ zuul.d/jobs.yaml | 7 ++++++ zuul.d/projects.yaml | 1 + 5 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 playbooks/airship-airshipctl-golint.yaml create mode 100755 tools/golint diff --git a/Makefile b/Makefile index 902cfdfe..a51d1106 100644 --- a/Makefile +++ b/Makefile @@ -83,12 +83,6 @@ lint: $(LINTER) @echo "Performing linting step..." @./tools/whitespace_linter @./$(LINTER) run --config $(LINTER_CONFIG) - @# NOTE(howell): golangci-lint uses and embedded golint, but if we use it, it - @# will cause gate failures. For now, we'll install golint alongside - @# golangci-lint. Once all of golint's suggestions have been fulfilled, we'll - @# remove this and simply use the golint that's embedded in golangci-lint. - @go install golang.org/x/lint/golint - @golint ./... @echo "Linting completed successfully" .PHONY: tidy @@ -97,6 +91,10 @@ tidy: @./tools/gomod_check @echo "go.mod is up to date" +.PHONY: golint +golint: + @./tools/golint + .PHONY: images images: docker-image @@ -145,6 +143,11 @@ docker-image-lint: DOCKER_MAKE_TARGET = lint docker-image-lint: DOCKER_TARGET_STAGE = builder docker-image-lint: docker-image +.PHONY: docker-image-golint +docker-image-golint: DOCKER_MAKE_TARGET = golint +docker-image-golint: DOCKER_TARGET_STAGE = builder +docker-image-golint: docker-image + .PHONY: clean clean: @rm -fr $(BINDIR) diff --git a/playbooks/airship-airshipctl-golint.yaml b/playbooks/airship-airshipctl-golint.yaml new file mode 100644 index 00000000..5c57e6ca --- /dev/null +++ b/playbooks/airship-airshipctl-golint.yaml @@ -0,0 +1,20 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- hosts: primary + tasks: + - name: Run Auxiliary Linter + block: + - name: "make docker-image-golint" + make: + chdir: "{{ zuul.project.src_dir }}" + target: docker-image-golint diff --git a/tools/golint b/tools/golint new file mode 100755 index 00000000..1c2c6bbe --- /dev/null +++ b/tools/golint @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# Our primary linter (golangci-lint) uses an embedded variant golint. This +# embedded version will catch the most egregious of the issues that the +# standard golint will catch, but it will fail to catch missing documentation. +# The purpose of this script is to produce a nonzero return code if the +# standard golint detects any issues. +go install golang.org/x/lint/golint +issues="$(golint ./...)" + +if [[ -n "$issues" ]]; then + printf "ERROR: issues found when running 'golint ./...':\n" + printf "%s\n" "$issues" + exit 1 +fi diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml index 2d48a8b1..0a4ba07d 100644 --- a/zuul.d/jobs.yaml +++ b/zuul.d/jobs.yaml @@ -15,6 +15,13 @@ run: tests/ansible/role-test-runner.yaml nodeset: airship-airshipctl-single-node +- job: + name: airship-airshipctl-golint + pre-run: playbooks/airship-airshipctl-deploy-docker.yaml + run: playbooks/airship-airshipctl-golint.yaml + nodeset: airship-airshipctl-single-node + voting: false + - job: name: airship-airshipctl-lint-unit pre-run: playbooks/airship-airshipctl-deploy-docker.yaml diff --git a/zuul.d/projects.yaml b/zuul.d/projects.yaml index aed04abf..a865c173 100644 --- a/zuul.d/projects.yaml +++ b/zuul.d/projects.yaml @@ -20,6 +20,7 @@ - "roles/*" - openstack-tox-docs - airship-airshipctl-lint-unit + - airship-airshipctl-golint - airship-airshipctl-build-image # - airship-airshipctl-functional-existing-k8s TODO: Enable this when functional tests exist, and a cluster is up - airship-airshipctl-gate-test