fix(ci): deploy_notify.py 修复 black 格式问题
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 1535h0m36s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 1535h0m46s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 1535h0m50s
CI/CD Pipeline / Build Production Runtime Images (pull_request) Failing after 1535h1m2s
CI/CD Pipeline / Build & Push Staging (Watchtower auto-deploy) (pull_request) Failing after 1535h1m4s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 1535h32m26s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 1535h0m36s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 1535h0m46s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 1535h0m50s
CI/CD Pipeline / Build Production Runtime Images (pull_request) Failing after 1535h1m2s
CI/CD Pipeline / Build & Push Staging (Watchtower auto-deploy) (pull_request) Failing after 1535h1m4s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 1535h32m26s
This commit is contained in:
+43
-33
@@ -16,7 +16,6 @@ import os
|
||||
import sys
|
||||
import urllib.request
|
||||
|
||||
|
||||
STATUS_CONFIG = {
|
||||
"success": {
|
||||
"emoji": "✅",
|
||||
@@ -39,13 +38,13 @@ STATUS_CONFIG = {
|
||||
def build_card(status: str, detail: str) -> dict:
|
||||
"""构建飞书卡片消息。"""
|
||||
cfg = STATUS_CONFIG.get(status, STATUS_CONFIG["failure"])
|
||||
|
||||
|
||||
commit = os.environ.get("GITHUB_SHA", "unknown")[:8]
|
||||
branch = os.environ.get("GITHUB_REF_NAME", "unknown")
|
||||
actor = os.environ.get("GITHUB_ACTOR", "system")
|
||||
run_id = os.environ.get("GITHUB_RUN_ID", "-")
|
||||
repo = os.environ.get("GITHUB_REPOSITORY", "xiaoxia/xiaoxia-saas")
|
||||
|
||||
|
||||
elements = [
|
||||
{
|
||||
"tag": "div",
|
||||
@@ -61,33 +60,37 @@ def build_card(status: str, detail: str) -> dict:
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# 如果有 run_id,加一个查看详情按钮
|
||||
if run_id and run_id != "-":
|
||||
run_url = f"https://git.xiaoxiajianji.com/{repo}/actions/runs/{run_id}"
|
||||
elements.append({
|
||||
"tag": "action",
|
||||
"actions": [
|
||||
elements.append(
|
||||
{
|
||||
"tag": "action",
|
||||
"actions": [
|
||||
{
|
||||
"tag": "button",
|
||||
"text": {"tag": "plain_text", "content": "查看构建详情"},
|
||||
"url": run_url,
|
||||
"type": "primary",
|
||||
}
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
# 加 Staging 访问链接
|
||||
elements.append(
|
||||
{
|
||||
"tag": "note",
|
||||
"elements": [
|
||||
{
|
||||
"tag": "button",
|
||||
"text": {"tag": "plain_text", "content": "查看构建详情"},
|
||||
"url": run_url,
|
||||
"type": "primary",
|
||||
"tag": "plain_text",
|
||||
"content": "Staging: https://staging.xiaoxiajianji.com",
|
||||
}
|
||||
],
|
||||
})
|
||||
|
||||
# 加 Staging 访问链接
|
||||
elements.append({
|
||||
"tag": "note",
|
||||
"elements": [
|
||||
{
|
||||
"tag": "plain_text",
|
||||
"content": "Staging: https://staging.xiaoxiajianji.com",
|
||||
}
|
||||
],
|
||||
})
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
"msg_type": "interactive",
|
||||
"card": {
|
||||
@@ -107,14 +110,14 @@ def send_notification(webhook: str, status: str, detail: str) -> bool:
|
||||
"""发送通知到 webhook。"""
|
||||
payload = build_card(status, detail)
|
||||
data = json.dumps(payload).encode("utf-8")
|
||||
|
||||
|
||||
req = urllib.request.Request(
|
||||
webhook,
|
||||
data=data,
|
||||
headers={"Content-Type": "application/json"},
|
||||
method="POST",
|
||||
)
|
||||
|
||||
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=10) as resp:
|
||||
resp.read()
|
||||
@@ -127,18 +130,25 @@ def send_notification(webhook: str, status: str, detail: str) -> bool:
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Staging 部署通知")
|
||||
parser.add_argument("--status", required=True, choices=["success", "failure", "rollback"],
|
||||
help="部署状态")
|
||||
parser.add_argument(
|
||||
"--status",
|
||||
required=True,
|
||||
choices=["success", "failure", "rollback"],
|
||||
help="部署状态",
|
||||
)
|
||||
parser.add_argument("--detail", default="", help="详情描述")
|
||||
parser.add_argument("--webhook", default=os.environ.get("CI_NOTIFY_WEBHOOK", ""),
|
||||
help="Webhook URL (也可通过 CI_NOTIFY_WEBHOOK 环境变量设置)")
|
||||
|
||||
parser.add_argument(
|
||||
"--webhook",
|
||||
default=os.environ.get("CI_NOTIFY_WEBHOOK", ""),
|
||||
help="Webhook URL (也可通过 CI_NOTIFY_WEBHOOK 环境变量设置)",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
if not args.webhook:
|
||||
print("未配置 webhook URL,跳过通知")
|
||||
return 0
|
||||
|
||||
|
||||
send_notification(args.webhook, args.status, args.detail)
|
||||
return 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user