Skip to content

Commit

Permalink
ci(automerge): Update and improve auto-merge PR
Browse files Browse the repository at this point in the history
* Improved both auto approve and merge jobs
* Changed the committer to author instead github-action[bot]
* Now the workflow will only run if check suite has completed

Signed-off-by: Ryuu Mitsuki <dhefam31@gmail.com>
  • Loading branch information
mitsuki31 committed Aug 3, 2024
1 parent 4abea9d commit 15f9b45
Showing 1 changed file with 43 additions and 18 deletions.
61 changes: 43 additions & 18 deletions .github/workflows/dependabot-automerge.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,55 @@
name: Dependabot Auto-merge
name: Auto-merge Dependabot PR
on:
pull_request:

# Required to edit pull requests
permissions:
contents: write
pull-requests: write
check_suite:
types: [ completed ]

jobs:
build:
autoapprove:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]' # Only if the actor is Dependabot
if: ${{ github.actor == 'dependabot[bot]' }}

permissions:
contents: write
pull-requests: write

steps:
- name: Dependabot metadata
- name: Approve PR
uses: hmarr/auto-approve-action@v4
with:
github-token: ${{ secrets.M31_PAT }}
review-message: 'Auto approved PR'

automerge:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }} # Only if the actor is Dependabot

permissions:
contents: write
pull-requests: write

steps:
- name: Fetch Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Auto-merge Dependabot PR
- name: Merge PR
# Auto-merge all Dependabot PRs with patch updates
if: steps.metadata.outputs.update-type == 'version-update:semver-patch'
# Approve and merge the PR
run: |
gh pr review --approve "$PR_URL"
gh pr comment --body "@dependabot merge"
if: ${{ steps.metadata.outputs.update-type == 'version-update:semver-patch' }}
id: merge_pr
needs: metadata
uses: pascalgn/automerge-action@v0.16.3
env:
GITHUB_TOKEN: ${{ secrets.M31_PAT }}
MERGE_METHOD: merge
MERGE_COMMIT_MESSAGE: 'pull-request-title'

- name: Post-merge PR
needs: merge_pr
if: ${{ steps.automerge.outputs.mergeResult == 'merged' }}
run: >
gh pr comment --body 'Auto merged PR'
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.M31_PAT }}

0 comments on commit 15f9b45

Please sign in to comment.