Skip to content

Commit 0f03050

Browse files
[CI] Make email check workflow fail when author's email is private in Github UI (#148694)
**Problem** Currently, the email check workflow uses `git` to see email used for the last commit but the email address used when merging is actually governed by GitHub settings not what's stored in `git`. Due to this, the email check workflow passes even when the author's email is private in Github. We saw several such cases in our fork of llvm. See intel/llvm#17675 **Solution** Try to find user's email using GH's GraphQL APIs. User's email will be null if it's hidden in the profile. --------- Signed-off-by: Agarwal, Udit <[email protected]>
1 parent 8349bbd commit 0f03050

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

.github/workflows/email-check.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,30 @@ jobs:
2020

2121
- name: Extract author email
2222
id: author
23+
env:
24+
GH_TOKEN: ${{ github.token }}
2325
run: |
24-
git log -1
25-
echo "EMAIL=$(git show -s --format='%ae' HEAD~0)" >> $GITHUB_OUTPUT
26+
# Use Github GraphQL APIs to get the email associated with the PR author because this takes into account the GitHub settings for email privacy.
27+
query='
28+
query($login: String!) {
29+
user(login: $login) {
30+
email
31+
}
32+
}'
33+
34+
PR_AUTHOR=${{ github.event.pull_request.user.login }}
35+
36+
email=$(gh api graphql -f login="$PR_AUTHOR" -f query="$query" --jq '.data.user.email')
37+
echo "EMAIL_AUTHOR_GH_UI=$email" >> "$GITHUB_OUTPUT"
38+
2639
# Create empty comment file
2740
echo "[]" > comments
2841
42+
# When EMAIL_AUTHOR_GH_UI is NULL, author's email is hidden in GitHub UI.
43+
# In this case, we warn the user to turn off "Keep my email addresses private"
44+
# setting in their account.
2945
- name: Validate author email
30-
if: ${{ endsWith(steps.author.outputs.EMAIL, 'noreply.github.com') }}
46+
if: ${{ steps.author.outputs.EMAIL_AUTHOR_GH_UI == '' }}
3147
env:
3248
COMMENT: >-
3349
⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.<br/>

0 commit comments

Comments
 (0)