Refactor commit author verification in workflow #2
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 Commit Author | |
| on: push | |
| jobs: | |
| author-check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 1 # only fetches the latest commit | |
| - name: Verify current commit author | |
| run: | | |
| # List of banned authors and emails | |
| banned_authors=("linus torvalds" "satoshi nakamoto" "elon musk") | |
| banned_emails=("[email protected]" "[email protected]" "[email protected]") | |
| # Get author name and email for the current commit only | |
| author=$(git show -s --format='%an' ${{ github.sha }}) | |
| email=$(git show -s --format='%ae' ${{ github.sha }}) | |
| # Check banned authors | |
| for banned in "${banned_authors[@]}"; do | |
| if [[ "${author,,}" == "${banned,,}" ]]; then | |
| echo "Blocked: Commit attributed to banned author '$banned'." | |
| exit 1 | |
| fi | |
| done | |
| # Check banned emails | |
| for banned in "${banned_emails[@]}"; do | |
| if [[ "${email,,}" == "${banned,,}" ]]; then | |
| echo "Blocked: Commit attributed to banned email '$banned'." | |
| exit 1 | |
| fi | |
| done | |
| echo "Author check passed. No banned commit author found." |