From 6ded4851cb303f6603214dd41eefdc546ea95288 Mon Sep 17 00:00:00 2001 From: wbtiger <28288271@qq.com> Date: Fri, 29 May 2026 23:58:51 +0800 Subject: [PATCH] ci: add local checks (make check, pre-commit hook) and Gitea Actions workflow skeleton --- Makefile | 27 +++++++++++++++++++++++++-- scripts/pre-commit | 25 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100755 scripts/pre-commit diff --git a/Makefile b/Makefile index 7f3ef79..6a9db7f 100644 --- a/Makefile +++ b/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." diff --git a/scripts/pre-commit b/scripts/pre-commit new file mode 100755 index 0000000..0542568 --- /dev/null +++ b/scripts/pre-commit @@ -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 ==="