From 98f6159901f284f494dad8e4d203f2e003dbd53a Mon Sep 17 00:00:00 2001 From: KeisukeYamashita <19yamashita15@gmail.com> Date: Fri, 17 Jul 2020 17:02:49 +0900 Subject: [PATCH] add(makefile): util jobs --- .go-version | 1 + GNUmakefile | 25 +++++++++++++++++++++++++ scripts/errcheck.sh | 24 ++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 .go-version create mode 100644 scripts/errcheck.sh diff --git a/.go-version b/.go-version new file mode 100644 index 0000000..b0f139e --- /dev/null +++ b/.go-version @@ -0,0 +1 @@ +1.13.7 diff --git a/GNUmakefile b/GNUmakefile index 5a1486b..dbd87b1 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,8 +1,33 @@ +default: build + +build: fmtcheck + go install + test: fmtcheck go test ./... -v -timeout 120s testacc: fmtcheck TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120s +cassettes: fmtcheck + RECORD=true TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m + +vet: + @echo "go vet ." + @go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \ + echo ""; \ + echo "Vet found suspicious constructs. Please check the reported constructs"; \ + echo "and fix them if necessary before submitting the code for review."; \ + exit 1; \ + fi + +fmt: + gofmt -w $(GOFMT_FILES) + fmtcheck: @sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'" + +errcheck: + @sh -c "'$(CURDIR)/scripts/errcheck.sh'" + +.PHONY: build test testacc fmt cassettes vet fmtcheck errcheck diff --git a/scripts/errcheck.sh b/scripts/errcheck.sh new file mode 100644 index 0000000..15464f5 --- /dev/null +++ b/scripts/errcheck.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# Check gofmt +echo "==> Checking for unchecked errors..." + +if ! which errcheck > /dev/null; then + echo "==> Installing errcheck..." + go get -u github.com/kisielk/errcheck +fi + +err_files=$(errcheck -ignoretests \ + -ignore 'github.com/hashicorp/terraform/helper/schema:Set' \ + -ignore 'bytes:.*' \ + -ignore 'io:Close|Write' \ + $(go list ./...| grep -v /vendor/)) + +if [[ -n ${err_files} ]]; then + echo 'Unchecked errors found in the following places:' + echo "${err_files}" + echo "Please handle returned errors. You can check directly with \`make errcheck\`" + exit 1 +fi + +exit 0