cicd: Add a precommit hook to check formatting with gofmt. Add guide on how to add precommit hooks in the README
This commit is contained in:
parent
64b4de8b8a
commit
97eb04183b
2 changed files with 25 additions and 0 deletions
19
.githooks/pre-commit
Executable file
19
.githooks/pre-commit
Executable file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Reject commits containing Go files that aren't gofmt-formatted.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
files="$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$' || true)"
|
||||||
|
|
||||||
|
if [ -z "$files" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
unformatted="$(gofmt -l $files)"
|
||||||
|
|
||||||
|
if [ -n "$unformatted" ]; then
|
||||||
|
echo "gofmt: the following files are not formatted:"
|
||||||
|
echo "$unformatted"
|
||||||
|
echo
|
||||||
|
echo "Run 'gofmt -w <file>...' and re-stage before committing."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
@ -56,6 +56,12 @@ The intention for this project is to work as a template, where the developer sho
|
||||||
go run ./cmd
|
go run ./cmd
|
||||||
```
|
```
|
||||||
|
|
||||||
|
6. Enable the repo's git hooks (rejects commits with unformatted Go files):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git config core.hooksPath .githooks
|
||||||
|
```
|
||||||
|
|
||||||
## Migrations
|
## Migrations
|
||||||
|
|
||||||
`goose.sh` loads `.env` and passes through to goose (`up`, `down`, `status`, ...).
|
`goose.sh` loads `.env` and passes through to goose (`up`, `down`, `status`, ...).
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue