From cfcf36b09810cbc01a5041c4f3d78f71b2d32c5e Mon Sep 17 00:00:00 2001 From: Richard Kovacs Date: Wed, 8 Jun 2022 10:47:22 +0200 Subject: [PATCH] Introduce git push hook to validate source before push (#101) --- .husky/hooks/pre-commit | 3 +++ .husky/hooks/pre-push | 18 ++++++++++++++++++ Taskfile.yml | 16 +++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100755 .husky/hooks/pre-commit create mode 100755 .husky/hooks/pre-push diff --git a/.husky/hooks/pre-commit b/.husky/hooks/pre-commit new file mode 100755 index 0000000..a35ca0c --- /dev/null +++ b/.husky/hooks/pre-commit @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +husky install \ No newline at end of file diff --git a/.husky/hooks/pre-push b/.husky/hooks/pre-push new file mode 100755 index 0000000..e1ded86 --- /dev/null +++ b/.husky/hooks/pre-push @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -e + +if [[ -n "$(git status --short)" ]]; then + git stash + function unstash() { + git reset --hard + git stash pop + } + trap unstash EXIT +fi + +go fmt ./... +go vet ./... +golangci-lint run -c .golangci.yaml + +git diff --exit-code --quiet || (git status && exit 1) diff --git a/Taskfile.yml b/Taskfile.yml index 225fd31..7c5fc75 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -66,9 +66,23 @@ tasks: - bin-dir:init desc: install kubectl cmds: - - curl -Lo ./bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v{{.KUBECTL_VERSION}}/bin/{{OS}}/{{ARCH}}/kubectl && chmod +x ./bin/kubectl + - curl -Lo ./bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v{{.KUBECTL_VERSION}}/bin/{{OS}}/{{ARCH}}/kubectl + - chmod +x ./bin/kubectl status: - test -f ./bin/kubectl + fetch:husky: + deps: + - bin-dir:init + desc: install husky + cmds: + - cd bin ; curl -L https://github.com/automation-co/husky/releases/download/v0.2.8/husky_0.2.8_{{.CAP_ARCH}}_x86_64.tar.gz | tar -xz husky + - chmod +x ./bin/husky + - ./bin/husky install + vars: + CAP_ARCH: + sh: uname + status: + - test -f ./bin/husky fetch:all: desc: fetch all tools cmds: