|
| 1 | +name: Commit Email Check |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + validate: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + contents: read |
| 12 | + pull-requests: write |
| 13 | + issues: write |
| 14 | + steps: |
| 15 | + - name: Checkout PR branch |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Extract commit emails |
| 21 | + run: | |
| 22 | + BASE_SHA=${{ github.event.pull_request.base.sha }} |
| 23 | + HEAD_SHA=${{ github.event.pull_request.head.sha }} |
| 24 | + git log --format='%ae' $BASE_SHA..$HEAD_SHA | sort -u > commit-emails.txt |
| 25 | +
|
| 26 | + - uses: taiki-e/install-action@v2 |
| 27 | + with: |
| 28 | + tool: check-commits-email |
| 29 | + |
| 30 | + - name: Run validation |
| 31 | + id: check |
| 32 | + run: | |
| 33 | + check-commits-email \ |
| 34 | + --rules .github/email-blacklist.txt \ |
| 35 | + --emails commit-emails.txt \ |
| 36 | + --output github >> $GITHUB_OUTPUT |
| 37 | +
|
| 38 | + - name: Find Comment |
| 39 | + uses: peter-evans/find-comment@v3 |
| 40 | + id: find-comment |
| 41 | + with: |
| 42 | + issue-number: ${{ github.event.pull_request.number }} |
| 43 | + comment-author: 'github-actions[bot]' |
| 44 | + body-includes: Violation of email address detected |
| 45 | + |
| 46 | + - name: Post comment |
| 47 | + if: steps.check.outputs.violations != '' |
| 48 | + uses: peter-evans/create-or-update-comment@v4 |
| 49 | + with: |
| 50 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 51 | + issue-number: ${{ github.event.pull_request.number }} |
| 52 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 53 | + edit-mode: replace |
| 54 | + body: | |
| 55 | + ### ⚠️ Violation of email address detected |
| 56 | + The following email(s) match the blacklist rule: |
| 57 | +
|
| 58 | + ${{ steps.check.outputs.violations }} |
| 59 | +
|
| 60 | + <details> |
| 61 | + |
| 62 | + <summary>Correction steps</summary> |
| 63 | + |
| 64 | + 1. Modifying author information using interactive rebase |
| 65 | + ```bash |
| 66 | + git rebase -i HEAD~${{ github.event.pull_request.commits }} |
| 67 | + # Mark the commit that needs to be modified as edit |
| 68 | + ``` |
| 69 | +
|
| 70 | + 2. For each marked commit, execute: |
| 71 | + ```bash |
| 72 | + git commit --amend --author="username <other-email.com>" |
| 73 | + git rebase --continue |
| 74 | + ``` |
| 75 | +
|
| 76 | + 3. Force push update branch |
| 77 | + ```bash |
| 78 | + git push --force-with-lease |
| 79 | + ``` |
| 80 | + |
| 81 | + </details> |
| 82 | +
|
| 83 | + - name: Delete comment |
| 84 | + if: ${{ steps.find-comment.outputs.comment-id != '' && steps.check.outputs.violations == '' }} |
| 85 | + uses: detomarco/delete-comment@main |
| 86 | + with: |
| 87 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 89 | + |
0 commit comments