Skip to content

Commit 8c7a35d

Browse files
Mikalai Radchukm1kola
authored andcommitted
Adds lint, tidy and verify make targets
Signed-off-by: Mikalai Radchuk <[email protected]>
1 parent 68f6f98 commit 8c7a35d

File tree

7 files changed

+1061
-0
lines changed

7 files changed

+1061
-0
lines changed

.bingo/Variables.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ $(GINKGO): $(BINGO_DIR)/ginkgo.mod
3535
@echo "(re)installing $(GOBIN)/ginkgo-v2.1.4"
3636
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=ginkgo.mod -o=$(GOBIN)/ginkgo-v2.1.4 "github.com/onsi/ginkgo/v2/ginkgo"
3737

38+
GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.53.3
39+
$(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod
40+
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
41+
@echo "(re)installing $(GOBIN)/golangci-lint-v1.53.3"
42+
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.53.3 "github.com/golangci/golangci-lint/cmd/golangci-lint"
43+
3844
GORELEASER := $(GOBIN)/goreleaser-v1.16.2
3945
$(GORELEASER): $(BINGO_DIR)/goreleaser.mod
4046
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.

.bingo/golangci-lint.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT
2+
3+
go 1.19
4+
5+
require github.com/golangci/golangci-lint v1.53.3 // cmd/golangci-lint

.bingo/golangci-lint.sum

Lines changed: 954 additions & 0 deletions
Large diffs are not rendered by default.

.bingo/variables.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ CONTROLLER_GEN="${GOBIN}/controller-gen-v0.10.0"
1414

1515
GINKGO="${GOBIN}/ginkgo-v2.1.4"
1616

17+
GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.53.3"
18+
1719
GORELEASER="${GOBIN}/goreleaser-v1.16.2"
1820

1921
KIND="${GOBIN}/kind-v0.15.0"

.github/workflows/sanity.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: sanity
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
verify:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- uses: actions/setup-go@v4
17+
with:
18+
go-version-file: "go.mod"
19+
- name: Run verification checks
20+
run: make verify
21+
lint:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v3
25+
26+
- uses: actions/setup-go@v4
27+
with:
28+
go-version-file: "go.mod"
29+
30+
- name: Run golangci linting checks
31+
run: make lint GOLANGCI_LINT_ARGS="--out-format github-actions"

.golangci.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
run:
2+
# Default timeout is 1m, up to give more room
3+
timeout: 4m
4+
5+
linters:
6+
enable:
7+
- asciicheck
8+
- bodyclose
9+
- errorlint
10+
- ginkgolinter
11+
- gofmt
12+
- goimports
13+
- gosec
14+
- importas
15+
- misspell
16+
- nestif
17+
- nonamedreturns
18+
- prealloc
19+
- revive
20+
- stylecheck
21+
- tparallel
22+
- unconvert
23+
- unparam
24+
- unused
25+
- whitespace
26+
27+
linters-settings:
28+
errorlint:
29+
errorf: false
30+
31+
importas:
32+
alias:
33+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
34+
alias: metav1
35+
- pkg: k8s.io/apimachinery/pkg/api/errors
36+
alias: apierrors
37+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
38+
alias: apiextensionsv1
39+
- pkg: k8s.io/apimachinery/pkg/util/runtime
40+
alias: utilruntime
41+
- pkg: "^k8s\\.io/api/([^/]+)/(v[^/]+)$"
42+
alias: $1$2
43+
- pkg: sigs.k8s.io/controller-runtime
44+
alias: ctrl
45+
- pkg: github.com/operator-framework/rukpak/api/v1alpha1
46+
alias: rukpakv1alpha1
47+
goimports:
48+
local-prefixes: github.com/operator-framework/operator-controller
49+
50+
output:
51+
format: tab

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ help: ## Display this help.
6161

6262
##@ Development
6363

64+
.PHONY: lint
65+
lint: $(GOLANGCI_LINT) ## Run golangci linter.
66+
$(GOLANGCI_LINT) run --build-tags $(GO_BUILD_TAGS) $(GOLANGCI_LINT_ARGS)
67+
68+
.PHONY: tidy
69+
tidy: ## Update dependencies.
70+
$(Q)go mod tidy
71+
6472
.PHONY: manifests
6573
manifests: $(CONTROLLER_GEN) ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
6674
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
@@ -69,6 +77,10 @@ manifests: $(CONTROLLER_GEN) ## Generate WebhookConfiguration, ClusterRole and C
6977
generate: $(CONTROLLER_GEN) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
7078
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
7179

80+
.PHONY: verify
81+
verify: tidy fmt generate ## Verify the current code generation.
82+
git diff --exit-code
83+
7284
.PHONY: fmt
7385
fmt: ## Run go fmt against code.
7486
go fmt ./...

0 commit comments

Comments
 (0)