name: weekly-retro

# 周复盘自动化（target state，skill orchestrator 模式）
#
# Issue 即闭环载体：
#   - open  = 本周改进未做完
#   - close = 闭环
#
# 触发：
#   - schedule: 周六 01:03 UTC (= 09:03 Asia/Shanghai)
#     选周六的理由：报告周六早上出来，团队周末有时间消化 + 讨论改进项，
#     周一开工就能直接动手；放周一会挤掉一上午的工作时间。
#   - workflow_dispatch: 手动触发
#
# 单步入口：bash scripts/ops/weekly-retro-runner.sh
#   runner.sh → claude -p (runner mode) → weekly-retro skill orchestrate:
#     - subprocess weekly-review.py 拉数据
#     - 查 Gitea 找当前 ISO 周 issue
#     - 决策树（CREATE / NOOP / REPAIR / WARNING）
#     - 命中分支 → 执行
#
# 完整流程见 docs/ops/weekly-retro-architecture.md
#
# ⚠️ 启用前置条件：
#   1. Gitea secret `WEEKLY_RETRO_TOKEN` 已配置（AIBot PAT，
#      scope: write:repository + write:issue）
#   2. Runner 镜像装好 claude CLI 并已登录（同 ai-review-runner 配置）
#   3. Runner 装好 python 3.10+（weekly-review.py 用）

permissions:
  contents: read
  issues: write

on:
  schedule:
    - cron: '3 1 * * 6'  # Sat 01:03 UTC = Sat 09:03 Asia/Shanghai
  workflow_dispatch:
    inputs:
      dry-run:
        description: 'dry-run（不真写 Gitea）'
        required: false
        default: 'false'
        type: choice
        options: [ 'false', 'true' ]

jobs:
  weekly-retro:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0  # weekly-review.py 内部 git log 拉一周提交

      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'

      - name: Verify claude CLI is available
        run: command -v claude && claude --version

      - name: Run weekly-retro skill (orchestrator)
        env:
          WEEKLY_RETRO_TOKEN: ${{ secrets.WEEKLY_RETRO_TOKEN }}
          WEEKLY_RETRO_DRY_RUN: ${{ inputs.dry-run == 'true' && '1' || '' }}
        run: bash scripts/ops/weekly-retro-runner.sh
