Skip to content

Commit

Permalink
Run pre-commit with make
Browse files Browse the repository at this point in the history
Updating pre-commit hook with make. pre-commit-golang
repo is no longer maintained[1]. Instead of using
unmaintained repo we can use make to run pre-commit.

[1] dnephin/pre-commit-golang#98

Signed-off-by: Amol Kahat <[email protected]>
  • Loading branch information
amolkahat committed Feb 28, 2023
1 parent 040b51c commit dc2e357
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 29 deletions.
61 changes: 36 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
ci:
autofix_prs: false
skip:
- 'make-manifests'
- 'make-generate'
- 'go-vet'
- 'golangci-lint'
- 'go-lint'
- 'make-operator-lint'

repos:

- repo: local
hooks:
- id: golangci-lint
name: golangci-lint
language: golang
types: [go]
entry: make
args: ["golangci-lint"]
pass_filenames: false
- id: gofmt
name: gofmt
language: system
entry: make
args: ["fmt"]
pass_filenames: false
- id: govet
name: govet
language: system
entry: make
args: ["vet"]
pass_filenames: false
- id: gotidy
name: gotidy
language: system
entry: make
args: ["tidy"]
pass_filenames: false
- id: make-manifests
name: make-manifests
language: system
Expand All @@ -30,20 +46,6 @@ repos:
args: ['operator-lint']
pass_filenames: false

- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
hooks:
- id: go-fmt
exclude: ^vendor
- id: go-vet
- id: go-mod-tidy
- id: go-lint

- repo: https://github.com/golangci/golangci-lint
rev: v1.50.1
hooks:
- id: golangci-lint

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand Down Expand Up @@ -72,4 +74,13 @@ repos:
rev: 2.1.1
hooks:
- id: bashate
entry: bashate --error . --ignore=E006,E040,E011,E020,E012
entry: bashate --error . --ignore=E006,E040,E020,E012
# Run bashate check for all bash scripts
# Ignores the following rules:
# E006: Line longer than 79 columns (as many scripts use jinja
# templating, this is very difficult)
# E040: Syntax error determined using `bash -n` (as many scripts
# use jinja templating, this will often fail and the syntax
# error will be discovered in execution anyway)
# E020: Function declaration not in format ^function name {$
# E012: here doc didn't end before EOF
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ vet: gowork ## Run go vet against code.
go vet ./...
go vet ./api/...

.PHONY: tidy
tidy: fmt
go mod tidy; \
pushd "$(LOCALBIN)/../api/"; \
go mod tidy; \
popd

.PHONY: golangci-lint
golangci-lint:
test -s $(LOCALBIN)/golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.51.2
$(LOCALBIN)/golangci-lint run --fix

PROCS?=$(shell expr $(shell nproc --ignore 2) / 2)
PROC_CMD = --procs ${PROCS}

Expand All @@ -112,7 +124,6 @@ test: manifests generate fmt vet envtest ginkgo ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) -v debug --bin-dir $(LOCALBIN) use $(ENVTEST_K8S_VERSION) -p path)" $(GINKGO) --trace --cover --coverpkg=../../pkg/neutronapi,../../controllers,../../api/v1beta1 --coverprofile cover.out --covermode=atomic --randomize-all ${PROC_CMD} ./test/...

##@ Build

.PHONY: build
build: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
Expand Down
6 changes: 3 additions & 3 deletions test/kuttl/common/assert_sample_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,17 @@ spec:
kind: Service
name: neutron-public
---
# the actual addresses of the apiEndpoints are platform specific, so we can't rely on
# the actual addresses of the apiEndpoints are platform specific, so we can't rely on
# kuttl asserts to check them. This short script gathers the addresses and checks that
# the three endpoints are defined and their addresses follow the default pattern
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
namespaced: true
commands:
- script: |
template='{{.status.apiEndpoint.admin}}{{":"}}{{.status.apiEndpoint.internal}}{{":"}}{{.status.apiEndpoint.public}}{{"\n"}}'
template='{{.status.apiEndpoint.admin}}{{":"}}{{.status.apiEndpoint.internal}}{{":"}}{{.status.apiEndpoint.public}}{{"\n"}}'
regex="http:\/\/neutron-admin-openstack\.apps.*:http:\/\/neutron-internal-openstack\.apps.*:http:\/\/neutron-public-openstack\.apps.*"
apiEndpoints=$(oc get -n openstack NeutronAPI neutron -o go-template="$template")
apiEndpoints=$(oc get -n openstack NeutronAPI neutron -o go-template="$template")
matches=$(echo "$apiEndpoints" | sed -e "s?$regex??")
if [[ -z "$matches" ]]; then
exit 0
Expand Down

0 comments on commit dc2e357

Please sign in to comment.