chore: 添加 CI 工具链 — golangci-lint + gofumpt + goimports + Makefile
.golangci.yml:
- 启用 linter: errcheck, gosec, govet, staticcheck, ineffassign, unused,
revive, contextcheck, errorlint, errname, misspell
- 启用 formatter: gofumpt + goimports
Makefile:
- fmt/fmt-check: gofumpt + goimports 格式检查
- lint/lint-strict: golangci-lint 报告/阻断模式
- test: go test -race
- ci: 完整 CI 流程 (fmt-check + lint)
docs/code-style.md:
- 新增 AI 执行协议 + 代码格式化/自动化检查/MUST规则
- 集成 golangci-lint 检查项与规范对照
This commit is contained in:
46
scripts/ci.sh
Executable file
46
scripts/ci.sh
Executable file
@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
# CI 流水线脚本
|
||||
# 调用方式:bash scripts/ci.sh [--strict]
|
||||
# --strict 阻断模式(lint 失败则 exit 1)
|
||||
# 默认 报告模式(lint 只输出不阻断)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
export PATH="$HOME/go/bin:$PATH"
|
||||
|
||||
cd "$ROOT"
|
||||
|
||||
STRICT=false
|
||||
if [[ "${1:-}" == "--strict" ]]; then
|
||||
STRICT=true
|
||||
fi
|
||||
|
||||
echo "========================================"
|
||||
echo " CI Pipeline"
|
||||
echo " Mode: $( $STRICT && echo 'STRICT' || echo 'REPORT' )"
|
||||
echo "========================================"
|
||||
|
||||
# 1. 格式检查
|
||||
echo ""
|
||||
echo "==> 1/3 格式检查 (gofumpt + goimports)"
|
||||
make fmt-check
|
||||
|
||||
# 2. 编译检查
|
||||
echo ""
|
||||
echo "==> 2/3 编译检查 (go build)"
|
||||
go build ./...
|
||||
|
||||
# 3. 静态分析
|
||||
echo ""
|
||||
echo "==> 3/3 静态分析 (golangci-lint)"
|
||||
if $STRICT; then
|
||||
make lint-strict
|
||||
else
|
||||
make lint
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "========================================"
|
||||
echo " CI Pipeline 完成"
|
||||
echo "========================================"
|
||||
12
scripts/pre-push
Normal file
12
scripts/pre-push
Normal file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
# Git pre-push hook — push 前跑 CI 检查
|
||||
# 安装:cp scripts/pre-push .git/hooks/pre-push && chmod +x .git/hooks/pre-push
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||
|
||||
echo ""
|
||||
echo "==> Pre-push CI check..."
|
||||
bash "$ROOT/scripts/ci.sh" --strict
|
||||
echo "==> OK"
|
||||
Reference in New Issue
Block a user