name: Auto Merge Forward Dependabot PRs

on:
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: auto-merge-forward
  cancel-in-progress: false

jobs:
  count-open-dependabot-prs:
    name: Count Open Dependabot PRs
    runs-on: ubuntu-latest
    outputs:
      prs_count: ${{ steps.count.outputs.prs_count }}
    steps:
      - name: Checkout
        id: checkout
        uses: actions/checkout@v4
      - id: count
        env:
          GH_TOKEN: ${{ github.token }}
        run: echo "prs_count=$(gh pr list --app dependabot --state open --json number --jq length)" >> $GITHUB_OUTPUT

  merge-forward:
    name: Merge Forward
    runs-on: ubuntu-latest
    needs: [count-open-dependabot-prs]
    if: needs.count-open-dependabot-prs.outputs.prs_count == 0
    permissions:
      contents: write
    steps:
      - name: Checkout
        id: checkout
        uses: actions/checkout@v4
      - name: Setup GitHub User
        id: setup-gh-user
        run: |
          git config user.name 'github-actions[bot]'
          git config user.email 'github-actions[bot]@users.noreply.github.com'
      - name: Run Merge Forward
        id: run-auto-merge-forward
        uses: marcusdacoregio/auto-merge-forward@9eac812bc73673e1a358766ac2ce319bd31ce0f8
        with:
          branches: '6.1.x, 6.2.x, main'
          dry-run: false
          from-author: dependabot[bot]
