name: Dependabot post-update
on:
  pull_request:
    types: [opened, synchronize, reopened]
    branches:
      - 'master'

env:
  HUSKY: '0'

permissions:
  contents: write
  pull-requests: write

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
  cancel-in-progress: true

jobs:
  post-update:
    if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'release-drafter/release-drafter'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          ref: ${{ github.event.pull_request.head.ref }}
      - uses: ./.github/actions/common-setup

      - run: npm run build

      - name: Commit and push if needed
        run: |
          git add .
          if [ -z "$(git status --porcelain)" ]; then
            echo "💾 no changes to dist/index.js"
            exit 0
          fi
          git config --local user.email "github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git commit -m "Apply dist/index.js changes"
          git push
          echo "💾 pushed dist/index.js changes"
