diff --git a/.travis.yml b/.travis.yml index 9e56f84..ec4d95c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ -dist: trusty +dist: xenial sudo: required services: - docker language: go go: -- "1.9.x" +- "1.12.x" +env: GOFLAGS=-mod=vendor install: # This script is used by the Travis build to install a cookie for @@ -12,12 +13,12 @@ install: # packages that live there. # See: https://github.com/golang/go/issues/12933 - bash scripts/gogetcookie.sh -- go get github.com/kardianos/govendor +- make install-tools script: +- make lint - make test -- make vendor-status -- make vet +- make website-lint - make website-test # branches: diff --git a/Dockerfile b/Dockerfile index 768351b..d6da9f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.11.6-alpine3.9 +FROM golang:1.12.5-alpine3.9 RUN apk add --update \ bash \ @@ -8,6 +8,10 @@ RUN apk add --update \ shadow \ vim +# Additional go tools +RUN go get -u github.com/client9/misspell/cmd/misspell +RUN go get -u github.com/golangci/golangci-lint/cmd/golangci-lint + # Some environment variables to influence Terraform behavior ENV TF_LOG=TRACE TF_LOG_PATH=/var/log/terraform.log diff --git a/GNUmakefile b/GNUmakefile index 0629349..531cfae 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,5 +1,4 @@ TEST?=$$(go list ./... |grep -v 'vendor') -GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor) WEBSITE_REPO=github.com/hashicorp/terraform-website PKG_NAME=citrixitm DOCKER_SOURCE_DIR=/terraform-provider-$(PKG_NAME) @@ -17,26 +16,23 @@ test: fmtcheck testacc: fmtcheck 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 +install-tools: + GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell + GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint + +lint: + @echo "==> Checking source code against linters..." + @golangci-lint run ./$(PKG_NAME) fmt: - gofmt -w $(GOFMT_FILES) + @echo "==> Fixing source code with gofmt..." + gofmt -s -w ./$(PKG_NAME) +# Currently required by tf-deploy compile fmtcheck: + @echo "==> Checking source code against gofmt..." @sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'" -errcheck: - @sh -c "'$(CURDIR)/scripts/errcheck.sh'" - -vendor-status: - @govendor status test-compile: @if [ "$(TEST)" = "./..." ]; then \ @@ -53,6 +49,10 @@ ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO))) endif @$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME) +website-lint: + @echo "==> Checking website against linters..." + @misspell -error -source=text website/ + website-test: ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO))) echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..." @@ -102,4 +102,4 @@ else @docker run -it --name $(DOCKER_CONTAINER_NAME) --env ITM_BASE_URL --env ITM_CLIENT_ID --env ITM_CLIENT_SECRET --mount type=bind,src=$(PWD),dst=$(DOCKER_SOURCE_DIR) --mount type=bind,src=$(ITM_HOST_MODULE_DIR),dst=/terraform-module $(DOCKER_IMAGE_NAME) /bin/bash endif -.PHONY: build test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test +.PHONY: build fmt fmtcheck install-tools lint test test-compile testacc website website-lint website-test diff --git a/scripts/errcheck.sh b/scripts/errcheck.sh deleted file mode 100755 index 15464f5..0000000 --- a/scripts/errcheck.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/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