diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 000000000..63a39d96b --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,30 @@ +name: golangci-lint +on: + push: + branches: + - main + pull_request: +permissions: + contents: read + pull-requests: read # Remove along with only-new-issues by 2025 +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Determine golangci-lint version + id: golangcilint + run: | + line=$(grep GOLANGCI_LINT_VERSION= GNUmakefile) + version=$(echo ${line} | cut -d = -f2) + echo "version=$version" >> "$GITHUB_OUTPUT" + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + args: --whole-files # Remove along with only-new-issues by 2025 + version: ${{ steps.golangcilint.outputs.version }} + only-new-issues: true # Remove along with pull-requests: read permission by 2025 diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 000000000..76de1758d --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,13 @@ +run: + modules-download-mode: readonly + skip-dirs: + - cmd/migration-tool +linters: + enable: + - errcheck + - goimports + - gosimple + - govet + - ineffassign + - staticcheck + - unused diff --git a/GNUmakefile b/GNUmakefile index 94a07e8db..c5a5a5141 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -11,6 +11,9 @@ ACCTEST_COUNT ?= 1 GOFMT_FILES ?=$$(find . -name '*.go' |grep -v vendor) PKG_NAME =equinix +GOLANGCI_LINT_VERSION=v1.56 +GOLANGCI_LINT=go run github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION} + ifneq ($(origin TESTS_REGEXP), undefined) TESTARGS = -run='$(TESTS_REGEXP)' endif @@ -45,6 +48,8 @@ clean: ${GOCMD} clean rm -f ${BINARY} +lint: + ${GOLANGCI_LINT} run -v vet: @echo "go vet ." @@ -117,4 +122,4 @@ tfproviderdocs-check: echo "Unexpected issues found in code with bflad/tfproviderdocs."; \ exit 1) -.PHONY: test testacc build install clean fmt fmtcheck errcheck test-compile docs-lint docs-lint-fix tfproviderlint tfproviderlint-fix tfproviderdocs-check +.PHONY: test testacc build install clean lint fmt fmtcheck errcheck test-compile docs-lint docs-lint-fix tfproviderlint tfproviderlint-fix tfproviderdocs-check