fix(ci): 同步develop上ci_notify_failure.py最新版(解决格式+冲突)

This commit is contained in:
2026-07-12 15:31:57 +08:00
parent 4a5ea8ee6f
commit ef8aa0fa10
+10
View File
@@ -1,15 +1,19 @@
#!/usr/bin/env python3
"""发送 CI 失败通知到飞书/项目群 webhook。"""
import json
import os
import sys
import urllib.request
def main() -> int:
webhook = os.environ.get("CI_NOTIFY_WEBHOOK", "")
if not webhook:
print("未配置 CI_NOTIFY_WEBHOOK,跳过通知")
print("如需启用,请在仓库 Settings -> Secrets and variables -> Actions 中添加 CI_NOTIFY_WEBHOOK")
return 0
failed_job = os.environ.get("FAILED_JOB", "Unknown Job")
branch = os.environ.get("GITHUB_REF_NAME", "unknown")
commit = os.environ.get("GITHUB_SHA", "unknown")[:8]
@@ -17,6 +21,7 @@ def main() -> int:
run_id = os.environ.get("GITHUB_RUN_ID", "unknown")
repo = os.environ.get("GITHUB_REPOSITORY", "unknown")
run_url = f"https://git.xiaoxiajianji.com/{repo}/actions/runs/{run_id}"
payload = {
"msg_type": "interactive",
"card": {
@@ -55,6 +60,7 @@ def main() -> int:
],
},
}
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(
webhook,
@@ -69,6 +75,10 @@ def main() -> int:
except Exception as e:
print(f"通知发送失败: {e}", file=sys.stderr)
return 1
return 0
if __name__ == "__main__":
sys.exit(main())