Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

test pr-check action #1

test pr-check action

test pr-check action #1

Workflow file for this run

name: PR Check
on:
pull_request:
branches: [ main ]
jobs:
check-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check User Role
id: check-role
run: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
GITHUB_USER="${{ github.actor }}"
REPO="${{ github.repository }}"
ROLE=$(curl -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$REPO/collaborators/$GITHUB_USER/permission" \
| jq -r '.permission')
echo "User role: $ROLE"
if [[ "$ROLE" == "admin" || "$ROLE" == "write" ]]; then
echo "::set-output name=skip::true"
else
echo "::set-output name=skip::false"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check PR for Members
if: steps.check-role.outputs.skip == 'false'
run: |
GITHUB_USER="${{ github.actor }}"
MEMBER_DIR="./members/$GITHUB_USER"
if [ -d "$MEMBER_DIR" ]; then
echo "Member directory exists."
MODIFIED_FILES=$(git diff --name-only origin/main...$GITHUB_SHA)
for FILE in $MODIFIED_FILES; do
if [[ $FILE != $MEMBER_DIR/* ]]; then
echo "::error::You can only modify files in your own directory: $MEMBER_DIR"
exit 1
fi
done
else
echo "Member directory does not exist."
if git diff --name-only origin/main...$GITHUB_SHA | grep -q "^$MEMBER_DIR/"; then
PR_TITLE=$(jq -r ".pull_request.title" "$GITHUB_EVENT_PATH")
if [ "$PR_TITLE" != "Hello, Star Trek!" ]; then
echo "::error::For new member, the PR title must be 'Hello, Star Trek!'"
exit 1
fi
else
echo "::error::You must add a new directory with your username."
exit 1
fi