Skip to content

Commit d77b5c9

Browse files
committed
[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 #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 004f38e commit d77b5c9

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
@@ -21,14 +21,30 @@ jobs:
2121

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

0 commit comments

Comments
 (0)