feat(ci): 完善CI通知体系 - 全job失败告警 + develop成功通知
- 所有CI job失败均发送飞书卡片告警(含告警关键词) - Validate/Integration Tests/Frontend Lint/Deploy Staging全覆盖 - develop/main构建成功发送镜像已就绪通知 - 配置 CI_NOTIFY_WEBHOOK secret 即可启用
This commit is contained in:
+184
-2
@@ -216,7 +216,7 @@ print(f'状态: {"PASS ✅" if line_rate >= 65 else "FAIL ❌"}')
|
||||
"header": {
|
||||
"title": {
|
||||
"tag": "plain_text",
|
||||
"content": "❌ CI 构建失败"
|
||||
"content": "⚠️ CI告警:构建失败"
|
||||
},
|
||||
"status": "red"
|
||||
},
|
||||
@@ -490,7 +490,7 @@ print(f'状态: {"PASS ✅" if line_rate >= 50 else "FAIL ❌"}')
|
||||
"header": {
|
||||
"title": {
|
||||
"tag": "plain_text",
|
||||
"content": "🔴 CI 集成测试失败"
|
||||
"content": "⚠️ CI告警:集成测试失败"
|
||||
},
|
||||
"template": "red"
|
||||
},
|
||||
@@ -627,6 +627,67 @@ EOF
|
||||
-w /workspace/apps/web \
|
||||
docker.m.daocloud.io/library/node:20 \
|
||||
sh -lc 'npx vitest run src/test'
|
||||
|
||||
- name: Notify CI failure
|
||||
if: failure()
|
||||
shell: sh
|
||||
run: |
|
||||
set +e
|
||||
echo "=== CI 失败通知 ==="
|
||||
|
||||
FAILED_JOB="Frontend Lint"
|
||||
BRANCH="${GITHUB_REF_NAME:-unknown}"
|
||||
COMMIT="${GITHUB_SHA:0:8}"
|
||||
ACTOR="${GITHUB_ACTOR:-unknown}"
|
||||
RUN_ID="${GITHUB_RUN_ID:-unknown}"
|
||||
REPO="${GITHUB_REPOSITORY:-unknown}"
|
||||
RUN_URL="https://git.xiaoxiajianji.com/${REPO}/actions/runs/${RUN_ID}"
|
||||
|
||||
PAYLOAD=$(cat <<EOF
|
||||
{
|
||||
"msg_type": "interactive",
|
||||
"card": {
|
||||
"header": {
|
||||
"title": {
|
||||
"tag": "plain_text",
|
||||
"content": "⚠️ CI告警:前端Lint失败"
|
||||
},
|
||||
"template": "red"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"tag": "div",
|
||||
"text": {
|
||||
"tag": "lark_md",
|
||||
"content": "**任务:** Frontend Lint / Vitest\n**分支:** '"${BRANCH}"'\n**提交:** '"${COMMIT}"'\n**提交者:** '"${ACTOR}"'\n**Run ID:** '"${RUN_ID}"'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag": "action",
|
||||
"actions": [
|
||||
{
|
||||
"tag": "button",
|
||||
"text": {
|
||||
"tag": "plain_text",
|
||||
"content": "查看日志"
|
||||
},
|
||||
"url": "'"${RUN_URL}"'",
|
||||
"type": "danger"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
if [ -n "${CI_NOTIFY_WEBHOOK:-}" ]; then
|
||||
curl -s -X POST -H "Content-Type: application/json" "${CI_NOTIFY_WEBHOOK}" -d "$PAYLOAD" > /dev/null 2>&1 && echo "通知已发送" || echo "通知发送失败"
|
||||
else
|
||||
echo "未配置 CI_NOTIFY_WEBHOOK,跳过通知"
|
||||
fi
|
||||
|
||||
deploy-staging:
|
||||
name: Build & Push Staging (Watchtower auto-deploy)
|
||||
runs-on: saas
|
||||
@@ -759,6 +820,127 @@ EOF
|
||||
echo "Commit: ${GITHUB_SHA}"
|
||||
|
||||
|
||||
- name: Notify deploy failure
|
||||
if: failure()
|
||||
shell: sh
|
||||
run: |
|
||||
set +e
|
||||
echo "=== 部署失败通知 ==="
|
||||
|
||||
FAILED_JOB="Build & Push Staging"
|
||||
BRANCH="${GITHUB_REF_NAME:-unknown}"
|
||||
COMMIT="${GITHUB_SHA:0:8}"
|
||||
ACTOR="${GITHUB_ACTOR:-unknown}"
|
||||
RUN_ID="${GITHUB_RUN_ID:-unknown}"
|
||||
REPO="${GITHUB_REPOSITORY:-unknown}"
|
||||
RUN_URL="https://git.xiaoxiajianji.com/${REPO}/actions/runs/${RUN_ID}"
|
||||
|
||||
PAYLOAD=$(cat <<EOF
|
||||
{
|
||||
"msg_type": "interactive",
|
||||
"card": {
|
||||
"header": {
|
||||
"title": {
|
||||
"tag": "plain_text",
|
||||
"content": "⚠️ CI告警:Staging部署失败"
|
||||
},
|
||||
"template": "red"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"tag": "div",
|
||||
"text": {
|
||||
"tag": "lark_md",
|
||||
"content": "**任务:** Staging镜像构建与部署\n**分支:** '"${BRANCH}"'\n**提交:** '"${COMMIT}"'\n**提交者:** '"${ACTOR}"'\n**Run ID:** '"${RUN_ID}"'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag": "action",
|
||||
"actions": [
|
||||
{
|
||||
"tag": "button",
|
||||
"text": {
|
||||
"tag": "plain_text",
|
||||
"content": "查看日志"
|
||||
},
|
||||
"url": "'"${RUN_URL}"'",
|
||||
"type": "danger"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
if [ -n "${CI_NOTIFY_WEBHOOK:-}" ]; then
|
||||
curl -s -X POST -H "Content-Type: application/json" "${CI_NOTIFY_WEBHOOK}" -d "$PAYLOAD" > /dev/null 2>&1 && echo "通知已发送" || echo "通知发送失败"
|
||||
else
|
||||
echo "未配置 CI_NOTIFY_WEBHOOK,跳过通知"
|
||||
fi
|
||||
|
||||
- name: Notify staging success (镜像已就绪)
|
||||
if: success() && (github.ref_name == 'develop' || github.ref_name == 'main')
|
||||
shell: sh
|
||||
run: |
|
||||
set +e
|
||||
echo "=== Staging 部署成功通知 ==="
|
||||
|
||||
BRANCH="${GITHUB_REF_NAME:-unknown}"
|
||||
COMMIT="${GITHUB_SHA:0:8}"
|
||||
ACTOR="${GITHUB_ACTOR:-unknown}"
|
||||
RUN_ID="${GITHUB_RUN_ID:-unknown}"
|
||||
REPO="${GITHUB_REPOSITORY:-unknown}"
|
||||
RUN_URL="https://git.xiaoxiajianji.com/${REPO}/actions/runs/${RUN_ID}"
|
||||
COMMIT_URL="https://git.xiaoxiajianji.com/${REPO}/commit/${GITHUB_SHA}"
|
||||
|
||||
PAYLOAD=$(cat <<EOF
|
||||
{
|
||||
"msg_type": "interactive",
|
||||
"card": {
|
||||
"header": {
|
||||
"title": {
|
||||
"tag": "plain_text",
|
||||
"content": "✅ CI告警:Staging镜像已就绪"
|
||||
},
|
||||
"template": "green"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"tag": "div",
|
||||
"text": {
|
||||
"tag": "lark_md",
|
||||
"content": "**环境:** Staging\n**状态:** 镜像已推送,Watchtower自动拉取部署中\n**分支:** '"${BRANCH}"'\n**提交:** ['"${COMMIT}"']('"${COMMIT_URL}"')\n**提交者:** '"${ACTOR}"'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag": "action",
|
||||
"actions": [
|
||||
{
|
||||
"tag": "button",
|
||||
"text": {
|
||||
"tag": "plain_text",
|
||||
"content": "查看流水线"
|
||||
},
|
||||
"url": "'"${RUN_URL}"'",
|
||||
"type": "primary"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
if [ -n "${CI_NOTIFY_WEBHOOK:-}" ]; then
|
||||
curl -s -X POST -H "Content-Type: application/json" "${CI_NOTIFY_WEBHOOK}" -d "$PAYLOAD" > /dev/null 2>&1 && echo "成功通知已发送" || echo "成功通知发送失败"
|
||||
else
|
||||
echo "未配置 CI_NOTIFY_WEBHOOK,跳过通知"
|
||||
fi
|
||||
|
||||
|
||||
staging-e2e:
|
||||
name: Staging E2E Tests
|
||||
runs-on: saas
|
||||
|
||||
Reference in New Issue
Block a user