Files
sanguo_moziplus_v2/.gitea/workflows/deploy.yml
T
cfdaily 2f1cb5c277
CI / lint (pull_request) Failing after 14m13s
CI / test (pull_request) Has been skipped
CI / notify-on-failure (pull_request) Failing after 12m7s
fix(lint): resolve all 37 flake8 issues
- Remove 7 unused imports (F401)
- Fix 4 f-strings without placeholders (F541)
- Fix indentation and blank line issues (E127/E302/E402)
- Remove trailing whitespace on 22 blank lines (W293)

Pure formatting changes, no logic modifications.
2026-06-11 08:55:05 +08:00

95 lines
3.2 KiB
YAML
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.
# 部署管道 — moziplus v2.0
#
# 触发条件:
# - push 到 main 分支
#
# Gitea v1.26.2 已支持:
# - concurrency groups#32751
# - 可配置 GITEA_TOKEN 权限(#36173
#
# 仍不支持:
# - failure() 表达式,用 always() + shell 条件判断替代
# - permissions
#
# 部署脚本 scripts/deploy.sh,支持 --version/--rollback/--health-check
name: Deploy
on:
push:
branches: [main]
concurrency:
group: deploy-${{ gitea.ref }}
cancel-in-progress: false
jobs:
# ── Job 1: CI(main 分支跑完整测试)─────────────────
ci:
runs-on: macos-arm64
steps:
- uses: actions/checkout@v4
- name: Setup Python
run: |
python3 -m venv /tmp/ci-venv-deploy
/tmp/ci-venv-deploy/bin/pip install --quiet flake8 fastapi pydantic pyyaml uvicorn requests pytest pytest-asyncio httpx
- name: Lint
run: |
/tmp/ci-venv-deploy/bin/flake8 src/ --max-line-length=120 --extend-ignore=E501
- name: Unit & Integration Tests
run: |
/tmp/ci-venv-deploy/bin/pytest tests/ -m "not e2e" -x -q
# ── Job 2: 部署 ─────────────────────────────────────
deploy:
runs-on: macos-arm64
needs: ci
steps:
- uses: actions/checkout@v4
- name: Record current version
run: |
bash scripts/deploy.sh --version || echo "No deploy history yet"
- name: Deploy
run: |
bash scripts/deploy.sh --source="$GITHUB_WORKSPACE" --target="$HOME/.sanguo_projects/sanguo_moziplus_v2" --health-check
# 回滚由 notify-deploy-failure job 检测失败后通知人工介入
# ── Job 3: 部署失败通知 ──────────────────────────────
notify-deploy-failure:
runs-on: macos-arm64
needs: [ci, deploy]
if: always()
steps:
- name: Check deploy result and notify
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: |
STATUS=$(curl -sf \
-H "Authorization: token $GITEA_TOKEN" \
"${{ gitea.api_url }}/repos/${{ gitea.repository }}/commits/${{ gitea.sha }}/status" \
| python3 -c "import sys,json; print(json.load(sys.stdin).get('state',''))" 2>/dev/null || echo "")
echo "Deploy status: $STATUS"
if [ "$STATUS" != "success" ]; then
echo "Deploy failed, creating Issue for manual intervention..."
# 创建 Issue 通知人工介入
curl -sf -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
"${{ gitea.api_url }}/repos/${{ gitea.repository }}/issues" \
-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 "Issue created for deploy failure."
else
echo "Deploy succeeded."
fi