From 2c63aeb85795ba6af3d1ab8b963697bfe0b5af0d Mon Sep 17 00:00:00 2001 From: Arjun Naik Date: Wed, 26 Aug 2020 16:03:31 +0200 Subject: [PATCH] Switch to new boilerplate convention with golangci-lint Signed-off-by: Arjun Naik --- boilerplate/_lib/ensure.sh | 15 +++ .../golang_osd_cluster_operator/golangci.yml | 6 ++ .../golang_osd_cluster_operator/golint.sh | 92 ------------------- .../golang_osd_cluster_operator/standard.mk | 4 +- 4 files changed, 23 insertions(+), 94 deletions(-) create mode 100755 boilerplate/_lib/ensure.sh create mode 100644 boilerplate/openshift/golang_osd_cluster_operator/golangci.yml delete mode 100755 boilerplate/openshift/golang_osd_cluster_operator/golint.sh diff --git a/boilerplate/_lib/ensure.sh b/boilerplate/_lib/ensure.sh new file mode 100755 index 00000000..fbbce149 --- /dev/null +++ b/boilerplate/_lib/ensure.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -euo pipefail + +GOLANGCI_LINT_VERSION="1.30.0" +DEPENDENCY=${1:-} + +case "${DEPENDENCY}" in + golangci-lint) + GOPATH=$(go env GOPATH) + if [ ! -f "${GOPATH}/bin/golangci-lint" ]; then + DOWNLOAD_URL="https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz" + curl -sfL "${DOWNLOAD_URL}" | tar -C "${GOPATH}/bin" -zx --strip-components=1 "golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64/golangci-lint" + fi + ;; +esac diff --git a/boilerplate/openshift/golang_osd_cluster_operator/golangci.yml b/boilerplate/openshift/golang_osd_cluster_operator/golangci.yml new file mode 100644 index 00000000..bb4d20bf --- /dev/null +++ b/boilerplate/openshift/golang_osd_cluster_operator/golangci.yml @@ -0,0 +1,6 @@ +# options for analysis running +run: + # default concurrency is a available CPU number + concurrency: 10 + # timeout for analysis, e.g. 30s, 5m, default is 1m + timeout: 2m diff --git a/boilerplate/openshift/golang_osd_cluster_operator/golint.sh b/boilerplate/openshift/golang_osd_cluster_operator/golint.sh deleted file mode 100755 index 1bd7ef91..00000000 --- a/boilerplate/openshift/golang_osd_cluster_operator/golint.sh +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env bash - -CMD=${0##*/} - -# TODO(efried): Accept optional targets override -targets=$(go list -f '{{ .Dir }}' ./...) -# TODO(efried): Accept optional ignores regex override -# This is a grep-ish regex -ignores='/zz_generated.*\.go' - -usage () { - cat <&2 - exit -1 -} - -OPTS=$(getopt -o hf --long fix,help -n "$CMD" -- "$@") -[ $? != 0 ] && usage - -eval set -- "$OPTS" - -FIX= -while true; do - case "$1" in - -f | --fix ) - FIX=1 - shift - ;; - -h | --help ) usage;; - -- ) shift; break ;; - esac -done - -[ $@ ] && err "Unrecognized argument(s): '$@' -Specify -h for help." - -tmpd=`mktemp -d` -trap "rm -fr $tmpd" EXIT -lintylist=$tmpd/linty.list - -gofmt -s -l $targets | grep ".*\.go" | grep -v "$ignores" > $lintylist -if ! [ -s $lintylist ]; then - echo "You are lint free. Congratulations." - exit 0 -fi - -# Okay, we're linty. Print the diffs. -echo '==============' -echo 'YOU ARE LINTY!' -echo '==============' -cat $lintylist -echo '==============' -cat $lintylist | xargs gofmt -s -d -echo '==============' - -if [ -z $FIX ]; then - echo 'Specify `--fix` to write the above changes.' - exit 1 -fi - -echo "Fixing..." -cat $lintylist | xargs gofmt -s -w -echo "Done. Don't forget to commit the changes." - -exit 0 diff --git a/boilerplate/openshift/golang_osd_cluster_operator/standard.mk b/boilerplate/openshift/golang_osd_cluster_operator/standard.mk index 49ba2c4a..08371eb1 100644 --- a/boilerplate/openshift/golang_osd_cluster_operator/standard.mk +++ b/boilerplate/openshift/golang_osd_cluster_operator/standard.mk @@ -71,8 +71,8 @@ docker-push: push .PHONY: gocheck gocheck: ## Lint code - boilerplate/openshift/golang_osd_cluster_operator/golint.sh - ${GOENV} go vet ./cmd/... ./pkg/... + boilerplate/_lib/ensure.sh golangci-lint + GOLANGCI_LINT_CACHE=/tmp/golangci-cache golangci-lint run -c boilerplate/openshift/golang_osd_cluster_operator/golangci.yml ./... .PHONY: gogenerate gogenerate: