[CI] Add new approver #573
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: approve | |
on: | |
pull_request: | |
branches: [ "main" ] | |
types: [opened, synchronize, reopened] | |
jobs: | |
approve: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Get PR Approvals | |
run: | | |
# Get the PR number from the GitHub event | |
PR_NUMBER=$(jq --raw-output .number "$GITHUB_EVENT_PATH") | |
# Fetch approvers from the PR reviews API and join them in a single line | |
APPROVERS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER/reviews" \ | |
| jq -r '.[] | select(.state == "APPROVED") | .user.login' | tr '\n' ' ') | |
# Output approvers and ensure the format is correct for GITHUB_ENV | |
echo "APPROVERS=$APPROVERS" | |
echo "APPROVERS=$APPROVERS" >> $GITHUB_ENV | |
- name: Check for Specific Approver | |
run: | | |
# List of specific approvers to check | |
SPECIFIC_APPROVERS=("aoyulong" "zhaoyinglia" "heavyrain-lzy" "Caozhou1995") | |
APPROVED="false" | |
# Check if any of the specific approvers have approved the PR | |
for APPROVER in "${SPECIFIC_APPROVERS[@]}" | |
do | |
if echo "$APPROVERS" | grep -q "$APPROVER"; then | |
echo "The PR has been approved by the specific approver: $APPROVER." | |
APPROVED="true" | |
break | |
fi | |
done | |
# If no specific approvers are found, exit with an error | |
if [ "$APPROVED" = "false" ]; then | |
echo "The PR has not been approved by the specific approvers." | |
exit 1 | |
fi |