name: Open Collective Backers

on:
  schedule:
    # Run once a week on Sunday at 12:00 AM UTC
    - cron: '0 0 * * 0'
  workflow_dispatch:

permissions:
  contents: write

jobs:
  update-backers:
    runs-on: ubuntu-latest
    env:
      README_UPDATER_TOKEN: ${{ secrets.README_UPDATER_TOKEN }}
      REPO: ${{ github.repository }}
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          persist-credentials: false
      - name: Setup Ruby & RubyGems
        uses: ruby/setup-ruby@d45b1a4e94b71acab930e56e79c6aa188764e7f9 # v1.316.0
        with:
          ruby-version: ruby
          rubygems: default
          bundler: default
          bundler-cache: true

      - name: README Update
        if: ${{ env.README_UPDATER_TOKEN != '' }}
        env:
          # Keep GITHUB_TOKEN for any tools/scripts expecting it, mapped to the same secret
          GITHUB_TOKEN: ${{ env.README_UPDATER_TOKEN }}
        run: |
          git config user.name 'autobolt'
          git config user.email 'autobots@9thbit.net'
          # Use the configured token for authenticated pushes
          git remote set-url origin "https://x-access-token:${README_UPDATER_TOKEN}@github.com/${REPO}.git"
          bin/kettle-readme-backers
          # Push back to the same branch/ref that triggered the workflow (default branch for schedule)
          git push origin HEAD
