diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cd6aa8d3..6282e995 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,5 @@ -name: Tests +name: Test + on: pull_request: branches: [ main ] @@ -12,6 +13,7 @@ on: - 'README.md' - 'CHANGELOG.md' - 'website/*' + jobs: build: name: Build @@ -19,37 +21,43 @@ jobs: timeout-minutes: 5 steps: - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: '1.17' - id: go + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: '1.17' + id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v3 + - name: Check out code into the Go module directory + uses: actions/checkout@v3 - - name: Go fmt - run: | - make fmt + - name: Run linters + uses: golangci/golangci-lint-action@v3 + with: + version: latest - - name: Go vet - run: | - make vet + - name: Generate + run: make generate - - name: Build - run: | - go build -v . + - name: Confirm no diff + run: | + git diff --compact-summary --exit-code || \ + (echo "*** Unexpected differences after code generation. Run 'make generate' and commit."; exit 1) + - name: Build + run: make build -# run acceptance tests in a matrix with Terraform core versions test: - name: Matrix Test + name: 'Acc. Tests (OS: ${{ matrix.os }} / TF: ${{ matrix.terraform }})' needs: build - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} timeout-minutes: 15 strategy: fail-fast: false matrix: + os: + - macos-latest + - windows-latest + - ubuntu-latest terraform: - '0.12.*' - '0.13.*' @@ -57,22 +65,22 @@ jobs: - '0.15.*' - '1.0.*' - '1.1.*' - steps: - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: '1.17' - id: go + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: '1.17' + check-latest: true + + - name: Check out code + uses: actions/checkout@v3 - - name: Check out code into the Go module directory - uses: actions/checkout@v3 + - name: Setup Terraform ${{ matrix.terraform }} + uses: hashicorp/setup-terraform@v2 + with: + terraform_version: ${{ matrix.terraform }} + terraform_wrapper: false - - name: TF acceptance tests - timeout-minutes: 10 - env: - TF_ACC: "1" - TF_ACC_TERRAFORM_VERSION: ${{ matrix.terraform }} - run: | - go test -v -cover ./internal/provider/ + - name: Run acceptance test + run: make testacc diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..6b74d23f --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,17 @@ +linters: + # Default linters enabled + # See: https://golangci-lint.run/usage/linters/#enabled-by-default-linters + + # Additional linters enabled + enable: + - durationcheck + - exportloopref + - godot + - gofmt + - makezero + - misspell + - nilerr + - predeclared + - tenv + - unconvert + - unparam diff --git a/GNUmakefile b/GNUmakefile index 455a8eed..70a92d1d 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,44 +1,25 @@ -TEST?=$$(go list ./...) -GOFMT_FILES?=$$(find . -name '*.go') -PKG_NAME=http - default: build -build: fmtcheck - go install +build: + go build -v ./... -test: fmtcheck - go test -i $(TEST) || exit 1 - echo $(TEST) | \ - xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4 +install: build + go install -v ./... -testacc: fmtcheck - TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m +# See https://golangci-lint.run/ +lint: + golangci-lint run -vet: - @echo "go vet ." - @go vet $$(go list ./...) ; 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 +generate: + go generate ./... fmt: - gofmt -w $(GOFMT_FILES) - -fmtcheck: - @sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'" + gofmt -s -w -e . -errcheck: - @sh -c "'$(CURDIR)/scripts/errcheck.sh'" +test: + go test -v -cover -timeout=120s -parallel=4 ./... -test-compile: - @if [ "$(TEST)" = "./..." ]; then \ - echo "ERROR: Set TEST to a specific package. For example,"; \ - echo " make test-compile TEST=./$(PKG_NAME)"; \ - exit 1; \ - fi - go test -c $(TEST) $(TESTARGS) +testacc: + TF_ACC=1 go test -v -cover -timeout 120m ./... -.PHONY: build test testacc vet fmt fmtcheck errcheck test-compile +.PHONY: build install lint generate fmt test testacc diff --git a/scripts/errcheck.sh b/scripts/errcheck.sh deleted file mode 100755 index de1be362..00000000 --- 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 ./...)) - -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 diff --git a/scripts/gofmtcheck.sh b/scripts/gofmtcheck.sh deleted file mode 100755 index 408835d5..00000000 --- a/scripts/gofmtcheck.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -# Check gofmt -echo "==> Checking that code complies with gofmt requirements..." -gofmt_files=$(gofmt -l `find . -name '*.go'`) -if [[ -n ${gofmt_files} ]]; then - echo 'gofmt needs running on the following files:' - echo "${gofmt_files}" - echo "You can use the command: \`make fmt\` to reformat code." - exit 1 -fi - -exit 0