name: Auto API update check
permissions:
  actions: write
  checks: write
  contents: write
on:
  # Scheduled trigger is disabled by default
  # Uncommenting the following two lines will enable it
  # schedule:
  #   - cron: '0 16 * * *'
  workflow_dispatch:
  repository_dispatch:
jobs:
  run:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Setup Bun
        uses: oven-sh/setup-bun@v2
      - name: Install dependencies
        run: bun install
      - name: Create config auth
        env:
          CONFIG_AUTH_YAML_CTX: ${{ secrets.CONFIG_AUTH_YAML }}
        run: |
          mkdir -p config
          echo "$CONFIG_AUTH_YAML_CTX" > config/config_auth.yaml
      - name: Run archive script
        uses: nick-fields/retry@v3
        with:
          max_attempts: 5
          timeout_minutes: 10
          command: bun run src/main.ts archive
      - name: Format output data
        run: bun x oxfmt output
      - name: Git staging, commit, push
        continue-on-error: true
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git add output
          git commit -m '[Auto] API update'
          git push
