# ═══════════════════════════════════════════════
# 🔺 Sovereign: TCS-0002∞ | Root: SYS-GLW-0001
# 📜 Copyright: 国作登字-2026-A-00037559
# ═══════════════════════════════════════════════
name: 铸渊 · Notion 工单轮询

on:
  schedule:
    - cron: '0 2 * * *'       # 每日 UTC 02:00 = 北京 10:00 同步一次（冰朔指令降频）
  workflow_dispatch:           # 事件触发：人工主动要求同步时手动触发

jobs:
  notion-poll:
    name: 📡 轮询 Notion 工单簿
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: 轮询工单簿 + 处理 + 回写
        id: poll
        env:
          NOTION_API_TOKEN:  ${{ secrets.ZY_NOTION_TOKEN }}
          WORKORDER_DB_ID:   ${{ vars.WORKORDER_DB_ID }}
          SIGNAL_LOG_DB_ID:  ${{ vars.SIGNAL_LOG_DB_ID }}
        run: node scripts/notion-signal-bridge.js poll

      - name: 提交信号日志
        if: success()
        run: |
          git config user.name "铸渊 (ZhùYuān)"
          git config user.email "zhuyuan@guanghulab.com"
          git add signal-log/ broadcasts-outbox/
          git diff --cached --quiet || git commit -m "📡 Notion 信号处理 · $(date +%Y-%m-%dT%H:%M)"
          git push
