ci: add local checks (make check, pre-commit hook) and Gitea Actions workflow skeleton

This commit is contained in:
wbtiger 2026-05-29 23:58:51 +08:00
parent a4c93802a7
commit 6ded4851cb
2 changed files with 50 additions and 2 deletions

View File

@ -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."

25
scripts/pre-commit Executable file
View File

@ -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 ==="