Dependabot auto-merge #199
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Dependabot auto-merge | |
| on: | |
| pull_request: | |
| types: [opened] | |
| schedule: | |
| - cron: "0 */6 * * *" | |
| workflow_dispatch: | |
| permissions: | |
| pull-requests: write | |
| contents: write | |
| jobs: | |
| auto-merge: | |
| if: github.actor == 'dependabot[bot]' || github.event_name != 'pull_request' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Find Dependabot PRs | |
| id: find-prs | |
| run: | | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| echo "numbers=${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT" | |
| else | |
| NUMBERS=$(gh pr list --author "dependabot[bot]" --state open --json number --jq '.[].number' | tr '\n' ' ') | |
| echo "numbers=$NUMBERS" >> "$GITHUB_OUTPUT" | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Wait for CI and merge | |
| if: steps.find-prs.outputs.numbers != '' | |
| run: | | |
| for PR in ${{ steps.find-prs.outputs.numbers }}; do | |
| echo "Processing PR #$PR..." | |
| for i in $(seq 1 60); do | |
| STATUS=$(gh pr checks "$PR" 2>&1) || true | |
| if echo "$STATUS" | grep -q "all checks passed"; then | |
| echo "CI passed on PR #$PR, merging." | |
| gh pr merge --rebase "$PR" | |
| continue 2 | |
| fi | |
| if echo "$STATUS" | grep -qE "fail|cancelled"; then | |
| echo "CI failed on PR #$PR, skipping." | |
| continue 2 | |
| fi | |
| echo "Checks pending on PR #$PR... ($i/60)" | |
| sleep 30 | |
| done | |
| echo "Timed out waiting for CI on PR #$PR, skipping." | |
| done | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |