Skip to content

Commit

Permalink
Enhance auto-merge workflow for verifying maintainers (#20)
Browse files Browse the repository at this point in the history
* Enhance auto-merge workflow for verifying maintainers
  • Loading branch information
seokho-son authored Nov 15, 2023
1 parent 903f65d commit af2b437
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,36 @@ on:
types: [created]
jobs:
# Check auto merge contiditons of PR and proceed merging
automerge:
automerge:
# Apply this job if it is a PR and by OWNER with '/approve' comment
# TODO: the section contains('seokho-son jihoon-seo yunkon-kim') needs to be updated or automated
if: ${{ github.event.issue.pull_request && (contains('seokho-son jihoon-seo yunkon-kim', github.event.comment.user.login) || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/approve') }}
if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '/approve') }}

# This job runs on Ubuntu-latest (Ubuntu 20.04 LTS checked on 2022-09-06)
# See https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
runs-on: ubuntu-latest
steps:
# Check author_association is OWNER
- name: Check author_association
# Check the commenter is a member of the maintainer team of this repo
- name: Extract Repository Name
id: repo-name
run: echo "REPO_NAME=$(echo ${{ github.repository }} | cut -d'/' -f2)" >> $GITHUB_ENV

- name: Get Maintainer Team Members
id: check-team-members
run: |
echo event.comment.user.login is ${{ github.event.comment.user.login }}
echo event.comment.author_association is ${{ github.event.comment.author_association }}
echo Hello, this workflow is allowed to specific OWNERS.
TEAM_NAME="${{ env.REPO_NAME }}-maintainer"
TEAM_MEMBERS=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/orgs/cloud-barista/teams/${TEAM_NAME}/members | jq -r '.[] | .login')
echo "TEAM_MEMBERS=$TEAM_MEMBERS" >> $GITHUB_ENV
echo "GITHUB_ACTOR: ${GITHUB_ACTOR}"
echo "${TEAM_NAME}: ${TEAM_MEMBERS}"
- name: Verify if GITHUB_ACTOR is a Maintainer Team Member
run: |
if [[ ! " $TEAM_MEMBERS " =~ " ${GITHUB_ACTOR} " ]]; then
echo "User ${GITHUB_ACTOR} is not a member of the team. Stopping workflow."
exit 1
fi
# Apply 'approved' label when OWNER left '/approve' comment
- uses: actions/checkout@v4
Expand All @@ -37,7 +53,7 @@ jobs:
args: "--trace"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
MERGE_LABELS: "approved,lgtm,!wip,!hold"
MERGE_LABELS: "approved,!wip,!hold"
MERGE_REMOVE_LABELS: ""
MERGE_METHOD: "merge"
MERGE_COMMIT_MESSAGE: "pull-request-title"
Expand Down

0 comments on commit af2b437

Please sign in to comment.