fix(ci): 去掉push触发避免双倍触发 + 修复notify误报
1. 触发器:去掉 push,只保留 pull_request(opened, synchronize) - 每次 push 到 PR 分支不再跑 2 次 CI 2. notify-on-failure:只有明确的 failure 状态才发通知 - 之前:空状态/unknown/pending 都触发通知(误报根因) - 现在:只有 STATUS=failure 才发通知 3. venv 路径:统一用 /tmp/ci-venv-lint 和 /tmp/ci-venv-test - 避免 host 模式下与开发目录 .venv 冲突
This commit is contained in:
+14
-15
@@ -1,9 +1,10 @@
|
||||
# CI 管道 — moziplus v2.0
|
||||
#
|
||||
# 触发条件:
|
||||
# - push(非 main 分支)
|
||||
# - pull_request(opened, synchronize)
|
||||
#
|
||||
# 注意:只保留 pull_request 触发,避免 push + pull_request 双倍触发
|
||||
#
|
||||
# Gitea v1.23.4 限制注意:
|
||||
# - 不支持 failure() 表达式,用 always() + shell 条件判断替代
|
||||
# - 不支持 concurrency / continue-on-error / timeout-minutes / permissions
|
||||
@@ -13,10 +14,6 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '**'
|
||||
- '!main'
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
|
||||
@@ -29,12 +26,12 @@ jobs:
|
||||
|
||||
- name: Setup Python
|
||||
run: |
|
||||
python3 -m venv .venv
|
||||
.venv/bin/pip install --quiet flake8
|
||||
python3 -m venv /tmp/ci-venv-lint
|
||||
/tmp/ci-venv-lint/bin/pip install --quiet flake8
|
||||
|
||||
- name: Lint with flake8
|
||||
run: |
|
||||
.venv/bin/flake8 src/ --max-line-length=120 --extend-ignore=E501
|
||||
/tmp/ci-venv-lint/bin/flake8 src/ --max-line-length=120 --extend-ignore=E501
|
||||
|
||||
# ── Job 2: Test ──────────────────────────────────────
|
||||
test:
|
||||
@@ -45,15 +42,16 @@ jobs:
|
||||
|
||||
- name: Setup Python
|
||||
run: |
|
||||
python3 -m venv .venv
|
||||
.venv/bin/pip install --quiet -r requirements.txt
|
||||
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: |
|
||||
.venv/bin/pytest tests/ -m "not e2e" -x -q
|
||||
/tmp/ci-venv-test/bin/pytest tests/ -m "not e2e" -x -q
|
||||
|
||||
# ── Job 3: CI 失败通知 ───────────────────────────────
|
||||
# v1.23 不支持 failure(),用 always() + shell 检查 commit status 替代
|
||||
# 修复:只有明确的 failure 才发通知,空状态/未知状态不发(避免误报)
|
||||
notify-on-failure:
|
||||
runs-on: macos-arm64
|
||||
needs: [lint, test]
|
||||
@@ -69,10 +67,11 @@ jobs:
|
||||
"${{ 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 "Commit status: $STATUS"
|
||||
echo "Commit status: [$STATUS]"
|
||||
|
||||
if [ "$STATUS" != "success" ]; then
|
||||
echo "CI failed or status unknown, sending notification..."
|
||||
# 只在明确 failure 时发通知(空/unknown/success/pending 都不发)
|
||||
if [ "$STATUS" = "failure" ]; then
|
||||
echo "CI explicitly failed, sending notification..."
|
||||
|
||||
# 如果是 PR 事件,写评论通知
|
||||
PR_NUMBER="${{ gitea.event.pull_request.number }}"
|
||||
@@ -88,5 +87,5 @@ jobs:
|
||||
echo "Not a PR event, skipping PR comment."
|
||||
fi
|
||||
else
|
||||
echo "CI passed, no notification needed."
|
||||
echo "CI status is [$STATUS], no failure notification needed."
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user