Run GitHub Actions for specific number of approvals

Hello everyone!

I want to run a step in a job for a specific number of approvals on a PR. (please check the comment in below mentioned code)

Here is my workflow yaml:

name: MyWorkflow
on:
  issue_comment:
    types: [created]
    branches:
      - master

jobs:
     
  merge:  
    if: contains(github.event.comment.html_url, '/pull/') && startsWith(github.event.comment.body, '/merge')
    runs-on: ubuntu-latest
    steps:
      - name: Add a merge label 
        uses: actions-ecosystem/action-add-labels@v1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          labels: merge

## Here before I run the next step that is automerge   I want to check for a specific number of approvals on the PR.
## OR the other way is: in above step where we add label we can add label when specific number of people approved the PR.
      
      - name: automerge      
        uses: "pascalgn/automerge-action@f81beb99aef41bb55ad072857d43073fba833a98"
        env:          
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
          MERGE_LABELS: "merge,!WIP"
          MERGE_METHOD: "squash"
          MERGE_FORKS: "false"
          MERGE_RETRIES: "6"
          MERGE_RETRY_SLEEP: "10000"
          UPDATE_LABELS: ""
          UPDATE_METHOD: "rebase" 

Can anyone help me to generate this specific condition.

Q.2 And it will merge for the event /merge in the issue_comment can we restrict it to the role of the user who is commenting. Like if he’s the author or maintainer.

Thanks !

@uditgaurav ,

According to the introduction from the README of the action “pascalgn/automerge-action”, the action will automatically check if the required number of review approvals has been reached. If the number is not reached, it will not merge the PR.

In addition, the event you set for the workflow is not the right. You should set the events that are related to pull request, such as “pull_request”, “pull_request_review”, “pull_request_review_comment” or “pull_request_target”.
In your case, the “pull_request_review” event should be the suitable.

About the second question, you can try to set the “Branch protection rules” for target branch of the PR.

Awesome thanks @brightran

You’re welcome, @uditgaurav.
If you have any other questions about this topic, feel free to contact us.