87 lines
3.4 KiB
YAML
87 lines
3.4 KiB
YAML
name: 铸渊 · Receive SYSLOG · 飞书机器人 → GitHub → Notion
|
||
|
||
# 链路3:SYSLOG 回传
|
||
# 飞书机器人发来的 SYSLOG → 存入仓库 + 创建 Notion 条目 + 创建霜砚工单
|
||
#
|
||
# 依赖 Secrets:
|
||
# NOTION_TOKEN Notion API token
|
||
# NOTION_SYSLOG_DB_ID SYSLOG 收件箱数据库 ID
|
||
# NOTION_TICKET_DB_ID 霜砚工单数据库 ID
|
||
#
|
||
# dispatch payload:
|
||
# syslog SYSLOG JSON 全文
|
||
|
||
on:
|
||
repository_dispatch:
|
||
types: [receive-syslog]
|
||
|
||
jobs:
|
||
receive-syslog:
|
||
name: 📥 接收 SYSLOG 回传
|
||
runs-on: ubuntu-latest
|
||
permissions:
|
||
contents: write
|
||
|
||
steps:
|
||
- name: Checkout
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Setup Node.js
|
||
uses: actions/setup-node@v4
|
||
with:
|
||
node-version: '20'
|
||
|
||
- name: 📥 处理 SYSLOG
|
||
env:
|
||
SYSLOG_JSON: ${{ toJSON(github.event.client_payload.syslog) }}
|
||
NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}
|
||
NOTION_SYSLOG_DB_ID: ${{ secrets.NOTION_SYSLOG_DB_ID }}
|
||
NOTION_TICKET_DB_ID: ${{ secrets.NOTION_TICKET_DB_ID }}
|
||
run: node scripts/receive-syslog.js
|
||
|
||
- name: 💾 提交 SYSLOG 文件到仓库
|
||
run: |
|
||
git config user.name "zhuyuan-bot"
|
||
git config user.email "zhuyuan-bot@guanghulab.com"
|
||
git add syslog/
|
||
if git diff --cached --quiet; then
|
||
echo "No new syslog files to commit"
|
||
else
|
||
git pull --rebase origin main || true
|
||
git commit -m "📥 铸渊接收 SYSLOG 回传 [skip ci]"
|
||
git push origin main
|
||
fi
|
||
|
||
- name: 🔴 失败告警 → 飞书通知
|
||
if: failure()
|
||
env:
|
||
FEISHU_APP_ID: ${{ secrets.FEISHU_APP_ID }}
|
||
FEISHU_APP_SECRET: ${{ secrets.FEISHU_APP_SECRET }}
|
||
ALERT_CHAT_ID: ${{ secrets.FEISHU_ALERT_CHAT_ID }}
|
||
run: |
|
||
if [ -z "$ALERT_CHAT_ID" ]; then
|
||
echo "⚠️ 未配置 FEISHU_ALERT_CHAT_ID,跳过告警"
|
||
exit 0
|
||
fi
|
||
node -e "
|
||
const https = require('https');
|
||
function post(url, body) {
|
||
return new Promise((resolve, reject) => {
|
||
const payload = JSON.stringify(body);
|
||
const u = new URL(url);
|
||
const req = https.request({ hostname: u.hostname, port: 443, path: u.pathname, method: 'POST',
|
||
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) }
|
||
}, res => { let d=''; res.on('data', c => d+=c); res.on('end', () => resolve(d)); });
|
||
req.on('error', reject); req.write(payload); req.end();
|
||
});
|
||
}
|
||
(async () => {
|
||
const tokenRes = JSON.parse(await post('https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal',
|
||
{ app_id: process.env.FEISHU_APP_ID, app_secret: process.env.FEISHU_APP_SECRET }));
|
||
const token = tokenRes.tenant_access_token;
|
||
const payload = JSON.stringify({ text: '🔴 GitHub Action 失败告警\n\n工作流: receive-syslog\n时间: ' + new Date().toISOString() + '\n请检查 GitHub Actions 日志。' });
|
||
await post('https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=chat_id',
|
||
JSON.stringify({ receive_id: process.env.ALERT_CHAT_ID, msg_type: 'text', content: payload }));
|
||
})().catch(e => console.error(e.message));
|
||
"
|