name: update-versions

on:
  schedule:
    - cron: '0 1 * * *'   # 每天 UTC 01:00（北京时间 09:00）
  workflow_dispatch:

# 调用 eco.dameng.com 公开 API，无需境内专线，使用标准 runner 即可
jobs:
  update:
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - uses: actions/checkout@v4

      - name: 更新下载链接
        run: bash scripts/update-versions.sh versions.json

      - name: 检查是否有变更
        id: diff
        run: |
          if git diff --quiet versions.json; then
            echo "changed=false" >> "$GITHUB_OUTPUT"
          else
            echo "changed=true" >> "$GITHUB_OUTPUT"
          fi

      - name: 提交变更
        if: steps.diff.outputs.changed == 'true'
        run: |
          git config user.name  "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add versions.json
          git commit -m "chore: update download versions $(date -u +%Y-%m-%d)"
          git push
