diff --git a/.github/workflows/golanglint-ci.yml b/.github/workflows/golanglint-ci.yml deleted file mode 100644 index 89fdec4dc9..0000000000 --- a/.github/workflows/golanglint-ci.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: golangci-lint -on: - push: - branches: - - main - pull_request: - -permissions: - contents: read - # Optional: allow read access to pull request. Use with `only-new-issues` option. - # pull-requests: read - -jobs: - golangci: - name: lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 - with: - go-version-file: ./go.mod - cache: false - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - # Require: The version of golangci-lint to use. - # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. - # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. - version: latest - - - name: Generate - run: make generate - - - name: Confirm no diff - run: | - git diff --compact-summary --exit-code || \ - (echo "*** Unexpected differences after code generation. Run 'make generate' and commit."; exit 1) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull-request.yml similarity index 100% rename from .github/workflows/pull_request.yml rename to .github/workflows/pull-request.yml diff --git a/.github/workflows/reviewdog-golanglint-ci.yml b/.github/workflows/reviewdog-golanglint-ci.yml new file mode 100644 index 0000000000..954d161924 --- /dev/null +++ b/.github/workflows/reviewdog-golanglint-ci.yml @@ -0,0 +1,24 @@ +name: golangci-lint +on: + push: + branches: + - main + pull_request: + +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version-file: ./go.mod + cache: false + - name: golangci-lint + uses: reviewdog/action-golangci-lint@v2 diff --git a/.github/workflows/reviewdog-staticcheck.yml b/.github/workflows/reviewdog-staticcheck.yml new file mode 100644 index 0000000000..6208b1e4c9 --- /dev/null +++ b/.github/workflows/reviewdog-staticcheck.yml @@ -0,0 +1,18 @@ +name: reviewdog +on: [pull_request] +jobs: + staticcheck: + name: runner / staticcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version-file: ./go.mod + cache: false + - uses: reviewdog/action-staticcheck@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-pr-review + filter_mode: nofilter + fail_on_error: true diff --git a/.reviewdog.yml b/.reviewdog.yml new file mode 100644 index 0000000000..cae280c47f --- /dev/null +++ b/.reviewdog.yml @@ -0,0 +1,8 @@ +runner: + golangci: + cmd: golangci-lint run --out-format=line-number --timeout 5m + errorformat: + - '%E%f:%l:%c: %m' + - '%E%f:%l: %m' + - '%C%.%#' + level: warning diff --git a/GNUmakefile b/GNUmakefile index 4c92b6c19e..089565e31f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,5 +1,8 @@ -default: build +default: install + +help: + @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-23s\033[0m %s\n", $$1, $$2}' build: go build -v ./... @@ -7,9 +10,26 @@ build: install: build go install -v ./... +mod: ## add missing and remove unused modules + go mod tidy -compat=1.20 +.PHONY: mod + +mod-check: mod ## check if there are any missing/unused modules + git diff --exit-code -- go.mod go.sum +.PHONY: mod-check + # See https://golangci-lint.run/ lint: - golangci-lint run + golangci-lint run ./... -v + +lint-fix: ## Run static code analysis, check formatting and try to fix findings + golangci-lint run ./... -v --fix +.PHONY: lint-fix + +pre-push: fmt lint mod docs ## Run a few checks before pushing a change (docs, fmt, mod, etc.) + +pre-push-check: docs-check lint-check mod-check; ## Run a few checks before pushing a change (docs, fmt, mod, etc.) +.PHONY: pre-push fmt: ## Run gofumpt @echo "==> Fixing source code with gofumpt..." @@ -18,14 +38,18 @@ fmt: ## Run gofumpt fumpt: fmt test: - go test -v -cover -timeout=120s -parallel=4 ./... + go test -v -cover -timeout=30m -parallel=4 ./... testacc: - TF_ACC=1 go test -v -cover -timeout 120m ./... + TF_ACC=1 go test -v -cover -timeout 30m -parallel=4 ./... docs: go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate +docs-check: docs ## check that docs have been generated + git diff --exit-code -- docs +.PHONY: docs-check + # Generate docs, terraform fmt the examples folder, and create copywrite headers generate: cd tools && go generate ./... @@ -58,4 +82,13 @@ clean-generator-%: ## Clean generated files for specified resource rm -f ./internal/sdk/$**_gen.go rm -f ./internal/sdk/$**_gen_*test.go -.PHONY: build install lint generate fmt test testacc tools docs +sweep: ## destroy the whole architecture; USE ONLY FOR DEVELOPMENT ACCOUNTS + @echo "WARNING: This will destroy infrastructure. Use only in development accounts." + @echo "Are you sure? [y/n]" >&2 + @read -r REPLY; \ + if echo "$$REPLY" | grep -qG "^[yY]$$"; then \ + SNOWFLAKE_ENABLE_SWEEP=1 go test -timeout 300s -run ^TestSweepAll ./pkg/sdk -v; \ + else echo "Aborting..."; \ + fi; + +.PHONY: build install lint generate fmt test testacc tools docs sweep