Skip to content

Commit

Permalink
Introduce Husky git hook manager (#37)
Browse files Browse the repository at this point in the history
* Introduce Husky git hook manager

* Fix Tilt download URL

---------

Co-authored-by: Richard Kovacs <[email protected]>
  • Loading branch information
mhmxs and Richard Kovacs authored Dec 13, 2023
1 parent 7907ccb commit e3d5889
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .husky/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

$PWD/bin/husky install
19 changes: 19 additions & 0 deletions .husky/hooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

if [[ "$SKIP_GIT_PUSH_HOOK" ]]; then exit 0; fi

set -e

if git status --short | grep -qv "??"; then
git stash
function unstash() {
git reset --hard
git stash pop
}
trap unstash EXIT
fi

make generate manifests
git diff --exit-code --quiet || (git status && exit 1)

make test
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@ CLUSTERCTL ?= $(LOCALBIN)/clusterctl
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
TILT ?= $(LOCALBIN)/tilt
ENVTEST ?= $(LOCALBIN)/setup-envtest
HUSKY ?= $(LOCALBIN)/husky

## Tool Versions
KUSTOMIZE_VERSION ?= v5.1.1
CTLPTL_VERSION ?= v0.8.22
CLUSTERCTL_VERSION ?= v1.5.3
CONTROLLER_TOOLS_VERSION ?= v0.13.0
TILT_VERSION ?= 0.33.6
HUSKY_VERSION ?= v0.2.16

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
Expand Down Expand Up @@ -185,9 +187,17 @@ $(CONTROLLER_GEN): $(LOCALBIN)
tilt: $(TILT) ## Download tilt locally if necessary. If wrong version is installed, it will be overwritten.
$(TILT): $(LOCALBIN)
test -s $(LOCALBIN)/tilt && $(LOCALBIN)/tilt version | grep -q $(TILT_VERSION) || \
(cd $(LOCALBIN) ; curl -fsSL https://github.com/tilt-dev/tilt/releases/download/v$(TILT_VERSION)/tilt.$(TILT_VERSION).linux.x86_64.tar.gz | tar -xzv tilt)
(cd $(LOCALBIN) ; curl -fsSL https://github.com/tilt-dev/tilt/releases/download/v$(TILT_VERSION)/tilt.$(TILT_VERSION).$(shell uname -s | tr '[:upper:]' '[:lower:]').$(shell uname -m).tar.gz | tar -xzv tilt)

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: husky
husky: $(HUSKY) ## Download husky locally if necessary.
@echo Execute install command to enable git hooks: ./bin/husky install
@echo Set any value for SKIP_GIT_PUSH_HOOK env variable to skip git hook execution.
$(HUSKY): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install github.com/automation-co/husky@$(HUSKY_VERSION)

0 comments on commit e3d5889

Please sign in to comment.