Replace lefthook with shell script

This commit is contained in:
Deluan 2020-07-16 17:52:59 -04:00
parent e7f6ba8f35
commit 037f6b606e
4 changed files with 43 additions and 25 deletions

View File

@ -48,16 +48,20 @@ setup:
@(cd ./ui && npm ci)
.PHONY: setup
setup-dev: setup
setup-dev: setup setup-git
@which wire || (echo "Installing Wire" && GO111MODULE=off go get -u github.com/google/wire/cmd/wire)
@which ginkgo || (echo "Installing Ginkgo" && GO111MODULE=off go get -u github.com/onsi/ginkgo/ginkgo)
@which goose || (echo "Installing Goose" && GO111MODULE=off go get -u github.com/pressly/goose/cmd/goose)
@which reflex || (echo "Installing Reflex" && GO111MODULE=off go get -u github.com/cespare/reflex)
@which golangci-lint || (echo "Installing GolangCI-Lint" && cd .. && GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.27.0)
@which lefthook || (echo "Installing Lefthook" && GO111MODULE=off go get -u github.com/Arkweid/lefthook)
@lefthook install
@which goimports || (echo "Installing goimports" && GO111MODULE=off go get -u golang.org/x/tools/cmd/goimports)
.PHONY: setup-dev
setup-git:
@mkdir -p .git/hooks
(cd .git/hooks && ln -sf ../../git/* .)
.PHONY: setup-git
Jamstash-master:
wget -N https://github.com/tsquillario/Jamstash/archive/master.zip
unzip -o master.zip
@ -68,11 +72,6 @@ Jamstash-master:
check_env: check_go_env check_node_env
.PHONY: check_env
check_hooks:
@lefthook add pre-commit
@lefthook add pre-push
.PHONY: check_hooks
check_go_env:
@(hash go) || (echo "\nERROR: GO environment not setup properly!\n"; exit 1)
@go version | grep -q $(GO_VERSION) || (echo "\nERROR: Please upgrade your GO version\nThis project requires version $(GO_VERSION)"; exit 1)

32
git/pre-commit Executable file
View File

@ -0,0 +1,32 @@
#!/bin/sh
# Copyright 2012 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# git gofmt pre-commit hook
#
# To use, store as .git/hooks/pre-commit inside your repository and make sure
# it has execute permissions.
#
# This script does not handle file names that contain spaces.
if which goimports > /dev/null; then
gofmtcmd=goimports
else
gofmtcmd=gofmt
fi
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.go$')
[ -z "$gofiles" ] && exit 0
unformatted=$($gofmtcmd -l $gofiles)
[ -z "$unformatted" ] && exit 0
# Some files are not gofmt'd. Print message and fail.
echo >&2 "Go files must be formatted with '$gofmtcmd'. Please run:"
for fn in $unformatted; do
echo >&2 " $gofmtcmd -w $PWD/$fn"
done
exit 1

4
git/pre-push Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
golangci-lint run
make test

View File

@ -1,17 +0,0 @@
pre-push:
parallel: true
commands:
unit-tests:
tags: tests
run: go test ./...
lint:
tags: tests
run: golangci-lint run
pre-commit:
parallel: false
commands:
gofmt:
tags: style
glob: "*.go"
run: gofmt -w {staged_files}; git add {staged_files}