|
| 1 | +name: Auto-merge Dependabot PR |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + pr_number: |
| 7 | + description: 'Pull request number to merge' |
| 8 | + required: true |
| 9 | + type: number |
| 10 | + pr_title: |
| 11 | + description: 'Pull request title for commit message' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + secrets: |
| 15 | + github_token: |
| 16 | + description: 'GitHub token with PR merge permissions' |
| 17 | + required: true |
| 18 | + |
| 19 | +jobs: |
| 20 | + auto-merge: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Check if all jobs succeeded |
| 24 | + run: | |
| 25 | + echo "All required checks have passed for Dependabot PR #${{ inputs.pr_number }}" |
| 26 | + echo "PR Title: ${{ inputs.pr_title }}" |
| 27 | + |
| 28 | + - name: Approve PR |
| 29 | + uses: actions/github-script@v6 |
| 30 | + with: |
| 31 | + github-token: ${{ secrets.github_token }} |
| 32 | + script: | |
| 33 | + await github.rest.pulls.createReview({ |
| 34 | + owner: context.repo.owner, |
| 35 | + repo: context.repo.repo, |
| 36 | + pull_number: ${{ inputs.pr_number }}, |
| 37 | + event: 'APPROVE', |
| 38 | + body: '✅ Auto-approved by PR validation workflow - all checks passed!' |
| 39 | + }); |
| 40 | + console.log('PR approved successfully'); |
| 41 | + |
| 42 | + - name: Merge PR |
| 43 | + uses: actions/github-script@v6 |
| 44 | + with: |
| 45 | + github-token: ${{ secrets.github_token }} |
| 46 | + script: | |
| 47 | + await github.rest.pulls.merge({ |
| 48 | + owner: context.repo.owner, |
| 49 | + repo: context.repo.repo, |
| 50 | + pull_number: ${{ inputs.pr_number }}, |
| 51 | + commit_title: `Auto-merge: ${{ inputs.pr_title }}`, |
| 52 | + commit_message: 'Automatically merged Dependabot PR after all validation checks passed', |
| 53 | + merge_method: 'squash' |
| 54 | + }); |
| 55 | + console.log('PR merged successfully'); |
| 56 | + |
| 57 | + - name: Comment on merged PR |
| 58 | + if: success() |
| 59 | + uses: actions/github-script@v6 |
| 60 | + with: |
| 61 | + github-token: ${{ secrets.github_token }} |
| 62 | + script: | |
| 63 | + await github.rest.issues.createComment({ |
| 64 | + owner: context.repo.owner, |
| 65 | + repo: context.repo.repo, |
| 66 | + issue_number: ${{ inputs.pr_number }}, |
| 67 | + body: '🤖 **Automatically merged by PR Validation workflow**\n\n' + |
| 68 | + '✅ All validation checks passed\n' + |
| 69 | + 'PR was automatically approved and merged.' |
| 70 | + }); |
0 commit comments