|
| 1 | +name: Check Email |
| 2 | +description: Check Email |
| 3 | + |
| 4 | +inputs: |
| 5 | + email-suffix: |
| 6 | + description: The email suffix to check |
| 7 | + required: false |
| 8 | + default: '@tencent.com' |
| 9 | + ignore-email: |
| 10 | + description: The email to ignore |
| 11 | + required: false |
| 12 | + default: tdesign@tencent.com |
| 13 | + |
| 14 | +runs: |
| 15 | + using: composite |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + # 检查仓库当前检出的最新提交(作者/提交者邮箱) |
| 20 | + - name: check_github_primary_email |
| 21 | + shell: bash |
| 22 | + env: |
| 23 | + MAIL_SUFFIX: ${{ inputs.email-suffix }} |
| 24 | + IGNORE_MAIL: ${{ inputs.ignore-email }} |
| 25 | + run: | |
| 26 | + set -eu |
| 27 | +
|
| 28 | + # 获取最新提交的作者邮箱和提交者邮箱(可能为空) |
| 29 | + log_emails=$(git log --pretty=format:"%ae %ce" -1) |
| 30 | + if [[ -z "$log_emails" ]]; then |
| 31 | + echo "No commits found in checked-out ref" |
| 32 | + exit 0 |
| 33 | + fi |
| 34 | +
|
| 35 | + # 如果包含忽略邮箱,跳过验证 |
| 36 | + if [[ "$log_emails" == *"$IGNORE_MAIL"* ]]; then |
| 37 | + echo "$log_emails 跳过验证" |
| 38 | + exit 0 |
| 39 | + fi |
| 40 | +
|
| 41 | + # 如果包含默认后缀则视为非法(可通过 inputs 覆盖) |
| 42 | + if [[ "$log_emails" == *"$MAIL_SUFFIX"* ]]; then |
| 43 | + echo "默认邮箱 $log_emails 校验非法,可以去 https://github.com/settings/emails 更改" |
| 44 | + exit 2 |
| 45 | + fi |
| 46 | +
|
| 47 | + echo "邮箱 $log_emails 校验通过" |
| 48 | +
|
| 49 | + # 检出 PR 源分支(如果存在),以便检查 PR 里的最新提交 |
| 50 | + - name: Checkout PR head |
| 51 | + uses: actions/checkout@v4 |
| 52 | + with: |
| 53 | + ref: ${{ github.event.pull_request.head.sha }} |
| 54 | + |
| 55 | + # 检查 PR 源分支最新提交的邮箱 |
| 56 | + - name: check_local_email |
| 57 | + shell: bash |
| 58 | + env: |
| 59 | + MAIL_SUFFIX: ${{ inputs.email-suffix }} |
| 60 | + IGNORE_MAIL: ${{ inputs.ignore-email }} |
| 61 | + run: | |
| 62 | + set -eu |
| 63 | +
|
| 64 | + log_emails=$(git log --pretty=format:"%ae %ce" -1q) |
| 65 | + if [[ -z "$log_emails" ]]; then |
| 66 | + echo "No commits found in PR head" |
| 67 | + exit 0 |
| 68 | + fi |
| 69 | +
|
| 70 | + if [[ "$log_emails" == *"$IGNORE_MAIL"* ]]; then |
| 71 | + echo "$log_emails 跳过验证" |
| 72 | + exit 0 |
| 73 | + fi |
| 74 | +
|
| 75 | + if [[ "$log_emails" == *"$MAIL_SUFFIX"* ]]; then |
| 76 | + echo "本地提交邮箱 $log_emails 校验非法,需要本地更改重新提交" |
| 77 | + exit 2 |
| 78 | + fi |
| 79 | +
|
| 80 | + echo "邮箱 $log_emails 校验通过" |
0 commit comments