Files
xiaoxia-saas/scripts/agent-commit.sh
T
xiaoxia 38c9c545cf
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 18s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 40s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m16s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m32s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 3m8s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 3m11s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 3m7s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m14s
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been cancelled
PR Automation / Auto Approve on CI Green (pull_request) Successful in 5m21s
AI Code Review / AI Code Review (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 5m29s
ci: PR构建验证 + Agent提交格式化脚本 + buildx清理
- 新增build-pr job:PR阶段只构建不推送,验证Dockerfile/构建脚本
- auto-approve/auto-merge的CONTEXTS加入3个PR Build检查
- build-staging构建后自动清理buildx builder,防磁盘泄漏
- 新增scripts/ci/docker_build_only.sh:PR构建专用(只读缓存不写)
- 新增scripts/agent-commit.sh:Agent提交前自动black+isort+ruff检查
2026-07-22 00:14:10 +08:00

100 lines
2.7 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Agent代码提交前自动格式化+质量检查脚本
# 用法: scripts/agent-commit.sh <commit_message> [files...]
# 效果: 自动跑black+isort+ruff check,通过后才commit+push
set -e
if [ $# -lt 1 ]; then
echo "用法: $0 <commit_message> [file1 file2 ...]"
echo "示例: $0 \"feat: add new api\" apps/api/src/"
exit 1
fi
COMMIT_MSG="$1"
shift
TARGETS="${@:-.}"
cd "$(dirname "$0")/.."
REPO_ROOT=$(pwd)
echo "仓库根目录: $REPO_ROOT"
echo "提交信息: $COMMIT_MSG"
echo "目标路径: $TARGETS"
echo ""
# 后端代码格式化(Python文件)
PYTHON_FILES=$(find $TARGETS -name "*.py" -type f 2>/dev/null | head -100 || true)
if [ -n "$PYTHON_FILES" ]; then
echo "=== Step 1/4: 后端代码格式化 (black) ==="
if command -v black &> /dev/null; then
black $TARGETS 2>&1 | tail -3
echo "✅ black 完成"
else
echo "⚠️ 未安装black,跳过"
fi
echo ""
echo "=== Step 2/4: import排序 (isort) ==="
if command -v isort &> /dev/null; then
isort $TARGETS 2>&1 | tail -3
echo "✅ isort 完成"
else
echo "⚠️ 未安装isort,跳过"
fi
echo ""
echo "=== Step 3/4: 代码质量检查 (ruff check) ==="
if command -v ruff &> /dev/null; then
RUFF_OUTPUT=$(ruff check $TARGETS 2>&1) || true
RUFF_ERRORS=$(echo "$RUFF_OUTPUT" | grep -c "^" || echo 0)
if [ "$RUFF_ERRORS" -le 2 ] || echo "$RUFF_OUTPUT" | grep -q "All checks passed"; then
echo "✅ ruff 检查通过(错误数: $RUFF_ERRORS"
else
echo "❌ ruff 发现以下问题:"
echo "$RUFF_OUTPUT" | head -30
echo ""
echo "请修复后重新提交,或手动忽略特定问题"
exit 1
fi
else
echo "⚠️ 未安装ruff,跳过"
fi
echo ""
else
echo "ℹ️ 未检测到Python文件,跳过后端格式化"
echo ""
fi
# 前端代码格式化(TS/TSX文件)
TS_FILES=$(find $TARGETS -name "*.ts" -o -name "*.tsx" -type f 2>/dev/null | head -100 || true)
if [ -n "$TS_FILES" ] && [ -f "apps/web/package.json" ]; then
echo "=== Step 4/4: 前端代码格式化 (prettier) ==="
if command -v npx &> /dev/null; then
cd apps/web && npx prettier --write "src/**/*.{ts,tsx}" 2>&1 | tail -3 || true
cd "$REPO_ROOT"
echo "✅ prettier 完成"
else
echo "⚠️ 未安装npx,跳过前端格式化"
fi
echo ""
fi
# Git操作
echo "=== 提交代码 ==="
git add -A
git diff --cached --stat
echo ""
git commit -m "$COMMIT_MSG"
echo ""
echo "✅ 本地提交完成"
# 可选:自动推送
if [ "$AGENT_AUTO_PUSH" = "true" ]; then
echo "正在推送到远程..."
git push
echo "✅ 推送完成"
else
echo "ℹ️ 本地已提交,如需推送执行: git push"
echo " 设置 AGENT_AUTO_PUSH=true 可自动推送"
fi