feat: 新增 Execution Status → Notion 同步 job

在 daily-maintenance.yml 中新增 sync-execution-status-to-notion job:
- 读取 brain/system-health.json, automation-map.json, repo-map.json
- 通过 Notion API 写入执行层状态数据库 (41971982-4a17-47c0-afe3-21458c44f154)
- 字段映射:仓库版本/执行模块/自动化状态/Notion连接/任务队列/同步来源
- 依赖 maintenance job 完成后运行,失败不阻塞巡检
- 复用 NOTION_TOKEN secret

Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-14 07:03:16 +00:00
parent 8f4bf0b2f8
commit f39fcc23b3
1 changed files with 74 additions and 0 deletions

View File

@ -142,3 +142,77 @@ jobs:
}]
}" 2>&1 | tail -1
echo "✅ Notion 回报请求已发送"
# ── 同步执行层状态到 Notion Execution Status 数据库 ──
sync-execution-status-to-notion:
name: 同步执行层状态到 Notion
needs: maintenance
runs-on: ubuntu-latest
if: ${{ !cancelled() }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Read brain data and sync to Notion
env:
NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}
run: |
if [ -z "$NOTION_TOKEN" ]; then
echo "⚠️ NOTION_TOKEN 未配置,跳过 Execution Status 同步"
exit 0
fi
HEALTH=$(cat brain/system-health.json 2>/dev/null || echo '{"version":"unknown","system_health":"unknown"}')
AUTO=$(cat brain/automation-map.json 2>/dev/null || echo '{"workflows":[]}')
REPO=$(cat brain/repo-map.json 2>/dev/null || echo '{"directories":{}}')
VERSION=$(echo "$HEALTH" | jq -r '.version // "unknown"')
STATUS=$(echo "$HEALTH" | jq -r '.system_health // "unknown"')
WF_COUNT=$(echo "$AUTO" | jq '[.workflows // [] | length] | .[0]' 2>/dev/null || echo '0')
CRON_COUNT=$(echo "$AUTO" | jq '[.workflows // [] | .[] | select(.cron)] | length' 2>/dev/null || echo '0')
DIR_COUNT=$(echo "$REPO" | jq '.directories // {} | keys | length' 2>/dev/null || echo '0')
case "$STATUS" in
normal) AUTO_S="🟢 Normal"; QUEUE_S="🟢 Active" ;;
partial) AUTO_S="🟡 Partial"; QUEUE_S="🟡 Backlog" ;;
*) AUTO_S="🔴 Down"; QUEUE_S="🔴 Blocked" ;;
esac
SYNC_DATE=$(date -u +%Y%m%d)
SYNC_TS=$(date -u +%Y-%m-%dT%H:%M:%S+00:00)
echo "📡 同步 Execution Status → Notion..."
echo " 版本: v${VERSION} · ${DIR_COUNT}+ dirs"
echo " 模块: ${WF_COUNT} workflow · ${CRON_COUNT} cron"
echo " 状态: ${AUTO_S}"
HTTP_CODE=$(curl -s -o /tmp/notion_resp.json -w "%{http_code}" \
-X POST 'https://api.notion.com/v1/pages' \
-H "Authorization: Bearer $NOTION_TOKEN" \
-H "Notion-Version: 2022-06-28" \
-H "Content-Type: application/json" \
-d "{
\"parent\": { \"database_id\": \"41971982-4a17-47c0-afe3-21458c44f154\" },
\"properties\": {
\"同步记录\": { \"title\": [{ \"text\": { \"content\": \"SYNC-${SYNC_DATE}-001\" } }] },
\"同步时间\": { \"date\": { \"start\": \"${SYNC_TS}\" } },
\"仓库版本\": { \"rich_text\": [{ \"text\": { \"content\": \"v${VERSION} · ${DIR_COUNT}+ dirs\" } }] },
\"执行模块\": { \"rich_text\": [{ \"text\": { \"content\": \"${WF_COUNT} workflow · ${CRON_COUNT} cron\" } }] },
\"自动化状态\": { \"select\": { \"name\": \"${AUTO_S}\" } },
\"Notion连接状态\": { \"select\": { \"name\": \"🟢 Connected\" } },
\"任务队列状态\": { \"select\": { \"name\": \"${QUEUE_S}\" } },
\"同步来源\": { \"select\": { \"name\": \"铸渊自动同步\" } },
\"备注\": { \"rich_text\": [{ \"text\": { \"content\": \"Daily Maintenance auto sync\" } }] }
}
}")
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
echo "✅ Execution Status synced to Notion (HTTP ${HTTP_CODE})"
else
echo "❌ Sync failed (HTTP ${HTTP_CODE})"
cat /tmp/notion_resp.json 2>/dev/null || true
exit 1
fi