Check Author #91
This file contains hidden or 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: Check Author | |
| on: | |
| workflow_run: | |
| workflows: ["Check Commit Signatures"] | |
| types: [completed] | |
| jobs: | |
| check_authors: | |
| if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request_target' }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| contents: read | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Download PR context from triggering run | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: pr-context | |
| github-token: ${{ github.token }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - name: Export PR_NUMBER env | |
| run: | | |
| PR_NUMBER=$(jq -r .number pr-context.json) | |
| echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV | |
| echo "GITHUB_PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV | |
| echo "HEAD_SHA=${{ github.event.workflow_run.head_sha }}" >> $GITHUB_ENV | |
| echo "GITHUB_HEAD_REF=${{ github.event.workflow_run.head_branch }}" >> $GITHUB_ENV | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.13' | |
| - run: pip install requests | |
| - name: Upload PR context | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pr-context | |
| path: pr-context.json | |
| - name: Check Author for Security | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GITHUB_REPOSITORY: ${{ github.repository }} | |
| run: python tools/validate_pr_paths.py | |
| - name: Notify PR about invalid file edits | |
| if: failure() | |
| run: | | |
| curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| --request POST \ | |
| --data '{"body": "One or more files modified outside the allowed directory. Please modify files under directory named as your Github-Username only and re-submit the PR."}' \ | |
| "https://api.github.com/repos/${{ github.repository }}/issues/$GITHUB_PR_NUMBER/comments" | |
| - name: Close the PR | |
| if: failure() | |
| run: | | |
| curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| --request PATCH \ | |
| --data '{"state": "closed"}' \ | |
| "https://api.github.com/repos/${{ github.repository }}/pulls/$GITHUB_PR_NUMBER" | |