1 Commits

Author SHA1 Message Date
cfdaily 55ae2e3551 dedup verify test
CI / lint (push) Successful in 6s
CI / lint (pull_request) Successful in 7s
CI / test (push) Successful in 3s
CI / test (pull_request) Successful in 3s
CI / notify-on-failure (push) Successful in 1s
CI / notify-on-failure (pull_request) Successful in 1s
2026-06-09 08:04:59 +08:00
7 changed files with 76 additions and 72 deletions
+4 -4
View File
@@ -47,17 +47,17 @@ jobs:
- name: Setup Python - name: Setup Python
run: | run: |
python3 -m venv /tmp/ci-venv-test python3 -m venv .venv
if [ -f pyproject.toml ]; then if [ -f pyproject.toml ]; then
/tmp/ci-venv-test/bin/pip install --quiet -e ".[dev]" .venv/bin/pip install --quiet -e ".[dev]"
else else
/tmp/ci-venv-test/bin/pip install --quiet pytest echo "No pyproject.toml, skipping dev install"
fi fi
- name: Run tests (exclude E2E) - name: Run tests (exclude E2E)
run: | run: |
if [ -d tests ]; then if [ -d tests ]; then
/tmp/ci-venv-test/bin/pytest tests/ -m "not e2e" -x -q .venv/bin/pytest tests/ -m "not e2e" -x -q
else else
echo "No tests/ directory, skipping tests" echo "No tests/ directory, skipping tests"
fi fi
+71 -48
View File
@@ -1,4 +1,14 @@
# CD 管道 — moziplus-v2 测试 # 部署管道 — moziplus v2.0
#
# 触发条件:
# - push 到 main 分支 → 完整 CIlint + test + coverage+ 部署
#
# 注意:非 main 分支的 CI 由 ci.yml 负责(快速门控)
#
# Gitea v1.23.4 限制注意:
# - 不支持 failure() 表达式
# - 不支持 concurrency / permissions
# - 部署脚本占位,等姜维确认 act-runner 环境后再补具体命令
name: Deploy name: Deploy
@@ -7,6 +17,7 @@ on:
branches: [main] branches: [main]
jobs: jobs:
# ── Job 1: CI(main 分支跑完整测试)─────────────────
ci: ci:
runs-on: macos-arm64 runs-on: macos-arm64
steps: steps:
@@ -14,85 +25,97 @@ jobs:
- name: Setup Python - name: Setup Python
run: | run: |
python3 -m venv /tmp/ci-venv-deploy python3 -m venv .venv
/tmp/ci-venv-deploy/bin/pip install --quiet flake8 pytest .venv/bin/pip install --quiet -e ".[dev]"
- name: Lint - name: Lint
run: | run: |
/tmp/ci-venv-deploy/bin/flake8 src/ --max-line-length=120 --extend-ignore=E501 || echo "No lint issues or src/ missing" test -d src && .venv/bin/ruff check src/ || echo "No src/ directory, skipping lint"
- name: Tests - name: Unit & Integration Tests
run: | run: |
if [ -d tests ]; then if [ -d tests ]; then
/tmp/ci-venv-deploy/bin/pytest tests/ -x -q .venv/bin/pytest tests/ -m "not e2e" -x -q
else else
echo "No tests/" echo "No tests/ directory, skipping tests"
fi fi
- name: Coverage Report
run: |
if [ -d tests ] && [ -d src ]; then
.venv/bin/pytest tests/ -m "not e2e" --cov=src --cov-report=term-missing -q
else
echo "No tests/ or src/ directory, skipping coverage"
fi
# ── Job 2: 部署 ─────────────────────────────────────
deploy: deploy:
runs-on: macos-arm64 runs-on: macos-arm64
needs: ci needs: ci
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Deploy to test target - name: Record current version
run: | run: |
TARGET="$HOME/.sanguo_projects/moziplus-v2-cd-test" echo "Deploying commit: ${{ gitea.sha }}"
echo "🚀 Deploying to $TARGET" echo "Branch: ${{ gitea.ref }}"
mkdir -p "$TARGET" echo "Timestamp: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
# TODO: bash scripts/deploy.sh --version
# 等姜维确认 act-runner 环境后再补
# Sync code (exclude git/tests/docs) - name: Deploy
rsync -a --delete \ run: |
--exclude='.git/' \ echo "=== Deploy step (placeholder) ==="
--exclude='docs/' \ echo "Source: ${{ gitea.workspace }}"
--exclude='tests/' \ # TODO: 实际部署脚本
--exclude='__pycache__/' \ # bash scripts/deploy.sh --source="$GITHUB_WORKSPACE" --target="$HOME/.sanguo_projects/sanguo_moziplus_v2" --health-check
--exclude='.venv/' \ echo "Deploy placeholder completed."
./ "$TARGET/" # placeholder: 后续替换为实际部署脚本
true
echo "✅ Deploy completed"
- name: Health check - name: Health check
run: | run: |
# 验证部署文件存在 echo "=== Health check (placeholder) ==="
TARGET="$HOME/.sanguo_projects/moziplus-v2-cd-test" # TODO: 等服务启动后做健康检查
if [ -f "$TARGET/src/hello.py" ]; then # curl -sf http://localhost:8083/api/health || exit 1
echo "Health check passed — hello.py deployed" echo "Health check placeholder passed."
else # placeholder: 后续替换为实际健康检查
echo "❌ Health check failed — hello.py not found" true
exit 1
fi
- name: Record deploy version # ── 失败时回滚 ────────────────────────────────
run: | # v1.23 不支持 if: failure()
TARGET="$HOME/.sanguo_projects/moziplus-v2-cd-test" # 回滚逻辑改由 notify-on-failure job 检测 commit status 后通知人工介入
mkdir -p "$TARGET/data" # 后续可升级到 v1.24+ 后改用 failure() 表达式
echo "{\"timestamp\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\",\"commit\":\"${{ gitea.sha }}\"}" >> "$TARGET/data/deploy-history.jsonl"
echo "📝 Deploy history recorded"
notify-on-failure: # ── Job 3: 部署失败通知 ──────────────────────────────
notify-deploy-failure:
runs-on: macos-arm64 runs-on: macos-arm64
needs: [ci, deploy] needs: [ci, deploy]
if: always() if: always()
steps: steps:
- name: Check results and notify - name: Check deploy result and notify
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} CI_TOKEN: ${{ secrets.CI_TOKEN }}
CI_RESULT: ${{ needs.ci.result }}
DEPLOY_RESULT: ${{ needs.deploy.result }}
run: | run: |
if [ "$CI_RESULT" = "failure" ] || [ "$DEPLOY_RESULT" = "failure" ]; then STATUS=$(curl -sf \
echo "Pipeline failed, creating Issue..." -H "Authorization: token $CI_TOKEN" \
FAILED_JOBS="" "${{ gitea.api_url }}/repos/${{ gitea.repository }}/commits/${{ gitea.sha }}/status" \
[ "$CI_RESULT" = "failure" ] && FAILED_JOBS="${FAILED_JOBS}ci " | python3 -c "import sys,json; print(json.load(sys.stdin).get('state',''))" 2>/dev/null || echo "")
[ "$DEPLOY_RESULT" = "failure" ] && FAILED_JOBS="${FAILED_JOBS}deploy "
echo "Deploy status: $STATUS"
if [ "$STATUS" != "success" ]; then
echo "Deploy failed, creating Issue for manual intervention..."
# 创建 Issue 通知人工介入
curl -sf -X POST \ curl -sf -X POST \
-H "Authorization: token $GITEA_TOKEN" \ -H "Authorization: token $CI_TOKEN" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
"${{ gitea.api_url }}/repos/${{ gitea.repository }}/issues" \ "${{ gitea.api_url }}/repos/${{ gitea.repository }}/issues" \
-d "{\"title\": \"[CD] 部署失败: ${{ gitea.sha }}\", \"body\": \"CI/CD pipeline 失败\\n\\nCommit: \`${{ gitea.sha }}\`\\nFailed: ${FAILED_JOBS}\"}" \ -d "{\"title\": \"🔴 部署失败: commit ${{ gitea.sha }}\", \"body\": \"部署失败,需人工介入排查。\\n\\n触发 commit: \`${{ gitea.sha }}\`\\n分支: main\\n\\n请检查 deploy 日志并手动处理。\", \"labels\": [\"bug\", \"priority:high\"]}" \
|| echo "Failed to create issue" || echo "Failed to create issue"
echo "Issue created for deploy failure."
else else
echo "Pipeline succeeded." echo "Deploy succeeded."
fi fi
+1
View File
@@ -0,0 +1 @@
dedup test
-1
View File
@@ -1 +0,0 @@
"""moziplus v2 test module"""
-9
View File
@@ -1,9 +0,0 @@
"""Hello module for CD testing."""
def greet(name: str) -> str:
"""Return greeting message."""
return f"Hello, {name}!"
def health() -> dict:
"""Return health status."""
return {"status": "ok", "version": "1.0.0"}
View File
-10
View File
@@ -1,10 +0,0 @@
"""Tests for hello module."""
from src.hello import greet, health
def test_greet():
assert greet("World") == "Hello, World!"
def test_health():
result = health()
assert result["status"] == "ok"