feat: 原生 Git hooks 方案,增强版本升迁工作流
This commit is contained in:
101
Makefile
101
Makefile
@@ -1,5 +1,5 @@
|
||||
.PHONY: \
|
||||
lint test clean \
|
||||
lint test clean hooks-install hooks-check hooks-test \
|
||||
version-sync version-check version-bump \
|
||||
server-run server-build server-lint server-test server-clean \
|
||||
desktop-build-mac desktop-build-win desktop-build-linux \
|
||||
@@ -10,6 +10,7 @@
|
||||
_backend-lint _backend-test _backend-clean _backend-build \
|
||||
_versionctl-lint _versionctl-test \
|
||||
_frontend-install _frontend-build _frontend-check _frontend-test _frontend-dev _frontend-clean \
|
||||
_hooks-pre-commit _check-clean-worktree \
|
||||
_desktop-test _desktop-clean _desktop-prepare-frontend _desktop-prepare-embedfs _desktop-prepare-windows-resource \
|
||||
_server-run-backend _server-run-frontend \
|
||||
_check-linux-target-arch _check-windows-target-arch _ensure-appimagetool \
|
||||
@@ -62,6 +63,82 @@ test: _backend-test _frontend-test _desktop-test _versionctl-test
|
||||
clean: _backend-clean _frontend-clean _desktop-clean
|
||||
@printf 'Clean complete\n'
|
||||
|
||||
# ============================================
|
||||
# Git hooks
|
||||
# ============================================
|
||||
|
||||
hooks-install:
|
||||
@hooks_dir=$$(git rev-parse --git-path hooks); \
|
||||
mkdir -p "$$hooks_dir"; \
|
||||
cp scripts/git-hooks/pre-commit "$$hooks_dir/pre-commit"; \
|
||||
cp scripts/git-hooks/commit-msg "$$hooks_dir/commit-msg"; \
|
||||
chmod +x "$$hooks_dir/pre-commit" "$$hooks_dir/commit-msg"; \
|
||||
printf 'Installed Git hooks to %s\n' "$$hooks_dir"
|
||||
|
||||
hooks-check:
|
||||
@hooks_dir=$$(git rev-parse --git-path hooks); \
|
||||
status=0; \
|
||||
for hook in pre-commit commit-msg; do \
|
||||
if [ -x "$$hooks_dir/$$hook" ]; then \
|
||||
printf 'OK: %s\n' "$$hook"; \
|
||||
else \
|
||||
printf 'MISSING: %s (%s/%s)\n' "$$hook" "$$hooks_dir" "$$hook"; \
|
||||
status=1; \
|
||||
fi; \
|
||||
done; \
|
||||
exit $$status
|
||||
|
||||
hooks-test:
|
||||
@scripts/git-hooks/test-hooks.sh
|
||||
|
||||
_hooks-pre-commit:
|
||||
@set -e; \
|
||||
staged_files=$$(git diff --cached --name-only --diff-filter=ACM); \
|
||||
if [ -z "$$staged_files" ]; then \
|
||||
printf 'No staged files to check\n'; \
|
||||
exit 0; \
|
||||
fi; \
|
||||
printf '%s\n' "$$staged_files" | while IFS= read -r file; do \
|
||||
[ -n "$$file" ] || continue; \
|
||||
case "$$file" in scripts/git-hooks/*) continue ;; esac; \
|
||||
if git show ":$$file" 2>/dev/null | grep -Eq '^(<<<<<<<|=======|>>>>>>>)'; then \
|
||||
printf 'Found conflict markers in staged file: %s\n' "$$file" >&2; \
|
||||
printf 'Resolve conflict markers before committing.\n' >&2; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
size=$$(git cat-file -s ":$$file" 2>/dev/null || printf '0'); \
|
||||
if [ "$$size" -gt 512000 ] 2>/dev/null; then \
|
||||
if git show ":$$file" 2>/dev/null | LC_ALL=C grep -Iq .; then \
|
||||
printf 'Warning: large staged text file (%s bytes): %s\n' "$$size" "$$file" >&2; \
|
||||
fi; \
|
||||
fi; \
|
||||
case "$$file" in \
|
||||
backend/*.go) \
|
||||
rel=$${file#backend/}; \
|
||||
printf 'Go lint: backend/%s\n' "$$rel"; \
|
||||
(cd backend && go tool golangci-lint run "$$rel"); \
|
||||
;; \
|
||||
versionctl/*.go) \
|
||||
rel=$${file#versionctl/}; \
|
||||
printf 'Go lint: versionctl/%s\n' "$$rel"; \
|
||||
(cd versionctl && go tool golangci-lint run "$$rel"); \
|
||||
;; \
|
||||
frontend/*.ts|frontend/*.tsx) \
|
||||
rel=$${file#frontend/}; \
|
||||
printf 'Frontend lint: frontend/%s\n' "$$rel"; \
|
||||
(cd frontend && bunx eslint "$$rel"); \
|
||||
printf 'Frontend format: frontend/%s\n' "$$rel"; \
|
||||
(cd frontend && bunx prettier --check "$$rel"); \
|
||||
;; \
|
||||
frontend/*.scss) \
|
||||
rel=$${file#frontend/}; \
|
||||
printf 'Frontend format: frontend/%s\n' "$$rel"; \
|
||||
(cd frontend && bunx prettier --check "$$rel"); \
|
||||
;; \
|
||||
esac; \
|
||||
done; \
|
||||
printf 'Pre-commit checks passed\n'
|
||||
|
||||
# ============================================
|
||||
# 版本管理
|
||||
# ============================================
|
||||
@@ -73,13 +150,21 @@ version-check:
|
||||
go run ./versionctl check
|
||||
|
||||
version-bump: BUMP ?= patch
|
||||
version-bump:
|
||||
$(eval _BUMP_ARG := $(if $(SET_VERSION),$(SET_VERSION),$(BUMP)))
|
||||
$(eval _NEW_VERSION := $(shell go run ./versionctl bump $(_BUMP_ARG)))
|
||||
git add VERSION frontend/
|
||||
git commit -m "chore: 版本升迁 v$(_NEW_VERSION)"
|
||||
git tag "v$(_NEW_VERSION)"
|
||||
@printf '版本升迁完成: v%s\n' "$(_NEW_VERSION)"
|
||||
version-bump: lint test _check-clean-worktree
|
||||
@set -e; \
|
||||
bump_arg="$(if $(SET_VERSION),$(SET_VERSION),$(BUMP))"; \
|
||||
new_version=$$(go run ./versionctl bump "$$bump_arg"); \
|
||||
git add VERSION frontend/; \
|
||||
git commit -m "chore: 版本升迁 v$$new_version"; \
|
||||
git tag "v$$new_version"; \
|
||||
printf '版本升迁完成: v%s\n' "$$new_version"
|
||||
|
||||
_check-clean-worktree:
|
||||
@if [ -n "$$(git status --porcelain)" ]; then \
|
||||
printf '工作区不干净,请先提交或清理改动后再执行版本升迁。\n' >&2; \
|
||||
git status --short; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
# ============================================
|
||||
# Server 模式
|
||||
|
||||
Reference in New Issue
Block a user