2f1cb5c277
- 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.
100 lines
3.6 KiB
YAML
100 lines
3.6 KiB
YAML
# CI 管道 — moziplus v2.0
|
||
#
|
||
# 触发条件:
|
||
# - pull_request(opened, synchronize)
|
||
#
|
||
# 注意:只保留 pull_request 触发,避免 push + pull_request 双倍触发
|
||
#
|
||
# Gitea v1.26.2 已支持:
|
||
# - concurrency groups(#32751)
|
||
# - 可配置 GITEA_TOKEN 权限(#36173)
|
||
#
|
||
# 仍不支持:
|
||
# - failure() 表达式,用 always() + shell 条件判断替代
|
||
# - continue-on-error / timeout-minutes / permissions
|
||
|
||
name: CI
|
||
|
||
on:
|
||
pull_request:
|
||
types: [opened, synchronize]
|
||
|
||
concurrency:
|
||
group: ci-${{ gitea.ref }}
|
||
cancel-in-progress: true
|
||
|
||
jobs:
|
||
# ── Job 1: Lint ──────────────────────────────────────
|
||
lint:
|
||
runs-on: macos-arm64
|
||
steps:
|
||
- uses: actions/checkout@v4
|
||
|
||
- name: Setup Python
|
||
run: |
|
||
python3 -m venv /tmp/ci-venv-lint
|
||
/tmp/ci-venv-lint/bin/pip install --quiet flake8
|
||
|
||
- name: Lint with flake8
|
||
run: |
|
||
/tmp/ci-venv-lint/bin/flake8 src/ --max-line-length=120 --extend-ignore=E501
|
||
|
||
# ── Job 2: Test ──────────────────────────────────────
|
||
test:
|
||
runs-on: macos-arm64
|
||
needs: lint
|
||
steps:
|
||
- uses: actions/checkout@v4
|
||
|
||
- name: Setup Python
|
||
run: |
|
||
python3 -m venv /tmp/ci-venv-test
|
||
/tmp/ci-venv-test/bin/pip install --quiet fastapi pydantic pyyaml uvicorn requests pytest pytest-asyncio httpx
|
||
|
||
- name: Run tests (exclude E2E)
|
||
run: |
|
||
/tmp/ci-venv-test/bin/pytest tests/ -m "not e2e" -x -q
|
||
|
||
# ── Job 3: CI 失败通知 ───────────────────────────────
|
||
# 使用 needs.<job>.result 直接判断,不查询 commit status API
|
||
# 根因:notify 自身的 pending status 会污染 commit status 查询结果(竞态条件)
|
||
notify-on-failure:
|
||
runs-on: macos-arm64
|
||
needs: [lint, test]
|
||
if: always()
|
||
steps:
|
||
- name: Check results and notify
|
||
env:
|
||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||
LINT_RESULT: ${{ needs.lint.result }}
|
||
TEST_RESULT: ${{ needs.test.result }}
|
||
run: |
|
||
echo "Lint result: $LINT_RESULT"
|
||
echo "Test result: $TEST_RESULT"
|
||
|
||
# 只有 lint 或 test 明确失败时才发通知
|
||
if [ "$LINT_RESULT" = "failure" ] || [ "$TEST_RESULT" = "failure" ]; then
|
||
echo "CI has failures, sending notification..."
|
||
|
||
# 如果是 PR 事件,写评论通知
|
||
PR_NUMBER="${{ gitea.event.pull_request.number }}"
|
||
if [ -n "$PR_NUMBER" ]; then
|
||
# 构建失败摘要
|
||
FAILED_JOBS=""
|
||
[ "$LINT_RESULT" = "failure" ] && FAILED_JOBS="${FAILED_JOBS}lint "
|
||
[ "$TEST_RESULT" = "failure" ] && FAILED_JOBS="${FAILED_JOBS}test "
|
||
|
||
curl -sf -X POST \
|
||
-H "Authorization: token $GITEA_TOKEN" \
|
||
-H "Content-Type: application/json" \
|
||
"${{ gitea.api_url }}/repos/${{ gitea.repository }}/issues/${PR_NUMBER}/comments" \
|
||
-d "{\"body\": \"[CI] 失败\\n\\n分支: ${{ gitea.ref_name }}\\n触发 commit: \`${{ gitea.sha }}\`\\n失败 Job: ${FAILED_JOBS}\\n请检查 CI 日志并修复。\"}" \
|
||
|| echo "Failed to post PR comment"
|
||
echo "PR comment posted."
|
||
else
|
||
echo "Not a PR event, skipping PR comment."
|
||
fi
|
||
else
|
||
echo "No explicit failures (results: lint=$LINT_RESULT, test=$TEST_RESULT), no notification needed."
|
||
fi
|