Skip to content

Commit

Permalink
chore(ci): lint with golangci-lint (#726)
Browse files Browse the repository at this point in the history
This introduces linting in CI to help maintain code quality and identify
issues that may not be caught by tests. To avoid a big PR that resolves
all existing linting issues, the CI workflow is configured to only look
at files that are changed in a particular PR or commit; we'll need to
keep an eye on this to make sure it's working as expected. This will
allow us to chip away at existing issues over time. Eventually (ideally
within a few months), the CI workflow should be updated to always lint
the entire codebase.

This PR also introduces a `make lint` task for local execution, but this
task lints the entire codebase and, for the time being, will catch some
issues that are not flagged for a particular PR or commit in CI.
  • Loading branch information
ctreatma authored Jul 16, 2024
1 parent 17f240c commit 09d97b2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
run:
modules-download-mode: readonly
skip-dirs:
- cmd/migration-tool
linters:
enable:
- errcheck
- goimports
- gosimple
- govet
- ineffassign
- staticcheck
- unused
7 changes: 6 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,6 +48,8 @@ clean:
${GOCMD} clean
rm -f ${BINARY}

lint:
${GOLANGCI_LINT} run -v

vet:
@echo "go vet ."
Expand Down Expand Up @@ -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

0 comments on commit 09d97b2

Please sign in to comment.