New rules to make small changes easier #1
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: Bypass Review by Admin for Specific Files | |
on: | |
pull_request: | |
types: [opened, synchronize] | |
jobs: | |
bypass-review: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up GitHub CLI Authentication | |
env: | |
GH_TOKEN: ${{ secrets.ADMIN_PAT }} | |
run: | | |
AUTHOR=$(gh pr view ${{ github.event.pull_request.number }} --json author --jq '.author.login') | |
ADMIN_CHECK=$(gh api user/memberships/orgs/scidsg --jq '.role') | |
if [ "$ADMIN_CHECK" != "admin" ]; then | |
echo "User is not an admin or is not a public member of the organization. Exiting." | |
exit 1 | |
fi | |
- name: Check for specific files and approve if conditions are met | |
run: | | |
FILES=$(git diff --name-only main ${{ github.head_ref }}) | |
if echo "$FILES" | grep -qvE '(\.css$|^hushline/version.py$)'; then | |
echo "PR contains files other than .css or hushline/version.py. Exiting without approval." | |
exit 0 | |
fi | |
# Check if only .css files or only hushline/version.py is present | |
if echo "$FILES" | grep -qE '\.css$' && ! echo "$FILES" | grep -qE '^hushline/version.py$'; then | |
echo "Only .css files detected and user is an admin, approving PR" | |
gh pr review ${{ github.event.pull_request.number }} --approve --body "Approved: Only .css files detected and user is an admin." | |
elif echo "$FILES" | grep -qE '^hushline/version.py$' && ! echo "$FILES" | grep -qE '\.css$'; then | |
echo "Only hushline/version.py detected and user is an admin, approving PR" | |
gh pr review ${{ github.event.pull_request.number }} --approve --body "Approved: Only hushline/version.py detected and user is an admin." | |
elif echo "$FILES" | grep -qE '(\.css$|^hushline/version.py$)'; then | |
echo "Both .css files and hushline/version.py detected and user is an admin, approving PR" | |
gh pr review ${{ github.event.pull_request.number }} --approve --body "Approved: Both .css files and hushline/version.py detected and user is an admin." | |
else | |
echo "No matching files detected or user is not an admin, continuing with normal review process" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.ADMIN_PAT }} |