From 15f9b452f0167b203b2c46df21d14613e3af10ba Mon Sep 17 00:00:00 2001 From: Ryuu Mitsuki Date: Sat, 3 Aug 2024 15:57:20 +0700 Subject: [PATCH] ci(automerge): Update and improve auto-merge PR * 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 --- .github/workflows/dependabot-automerge.yml | 61 +++++++++++++++------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/.github/workflows/dependabot-automerge.yml b/.github/workflows/dependabot-automerge.yml index 767fc35..8a80553 100644 --- a/.github/workflows/dependabot-automerge.yml +++ b/.github/workflows/dependabot-automerge.yml @@ -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 }}