Skip to content

Commit

Permalink
Adding golangci-lint.yml and updating GNUmakefile and test.yml (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendbennett committed May 18, 2022
1 parent f269837 commit 3f41ccd
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 106 deletions.
78 changes: 43 additions & 35 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Tests
name: Test

on:
pull_request:
branches: [ main ]
Expand All @@ -12,67 +13,74 @@ on:
- 'README.md'
- 'CHANGELOG.md'
- 'website/*'

jobs:
build:
name: Build
runs-on: ubuntu-latest
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.*'
- '0.14.*'
- '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
17 changes: 17 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
49 changes: 15 additions & 34 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -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
24 changes: 0 additions & 24 deletions scripts/errcheck.sh

This file was deleted.

13 changes: 0 additions & 13 deletions scripts/gofmtcheck.sh

This file was deleted.

0 comments on commit 3f41ccd

Please sign in to comment.