ci: add local checks (make check, pre-commit hook) and Gitea Actions workflow skeleton
This commit is contained in:
parent
a4c93802a7
commit
6ded4851cb
27
Makefile
27
Makefile
|
|
@ -3,7 +3,7 @@ BINARY := gitlink-cli
|
|||
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
||||
LDFLAGS := -s -w -X '$(MODULE)/cmd.Version=$(VERSION)'
|
||||
|
||||
.PHONY: build install clean test
|
||||
.PHONY: build install clean test check vet fmt cover
|
||||
|
||||
build:
|
||||
go build -ldflags "$(LDFLAGS)" -o $(BINARY) .
|
||||
|
|
@ -15,4 +15,27 @@ clean:
|
|||
rm -f $(BINARY)
|
||||
|
||||
test:
|
||||
go test ./...
|
||||
go test -race ./...
|
||||
|
||||
vet:
|
||||
go vet ./...
|
||||
|
||||
fmt:
|
||||
@unformatted=$$(gofmt -s -l .); \
|
||||
if [ -n "$$unformatted" ]; then \
|
||||
echo "Files not formatted:"; \
|
||||
echo "$$unformatted"; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
cover:
|
||||
go test -coverprofile=coverage.out ./...
|
||||
go tool cover -func=coverage.out
|
||||
|
||||
check: fmt vet test
|
||||
@echo "All checks passed."
|
||||
|
||||
hooks:
|
||||
cp scripts/pre-commit .git/hooks/pre-commit
|
||||
chmod +x .git/hooks/pre-commit
|
||||
@echo "Pre-commit hook installed."
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
#!/bin/sh
|
||||
# Pre-commit hook: run fmt + vet + test before every commit.
|
||||
# Install: make hooks
|
||||
|
||||
set -e
|
||||
|
||||
echo "=== gofmt ==="
|
||||
unformatted=$(gofmt -s -l .)
|
||||
if [ -n "$unformatted" ]; then
|
||||
echo "ERROR: these files are not formatted:"
|
||||
echo "$unformatted"
|
||||
echo "Run: gofmt -s -w ."
|
||||
exit 1
|
||||
fi
|
||||
echo " OK"
|
||||
|
||||
echo "=== go vet ==="
|
||||
go vet ./...
|
||||
echo " OK"
|
||||
|
||||
echo "=== go test ==="
|
||||
go test -race ./...
|
||||
echo " OK"
|
||||
|
||||
echo "=== pre-commit passed ==="
|
||||
Loading…
Reference in New Issue