Skip to content

Commit efe5a5b

Browse files
[CI] Fix detecting usage of private emails (#19394)
fixes #17675 Currently, in the workflow, we only check the email that was used for the latest commit in the PR. This email can differ from the email settings on the GH UI, from which PR will be authored, once we merge it. --------- Signed-off-by: Agarwal, Udit <[email protected]>
1 parent 004f38e commit efe5a5b

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

.github/workflows/email-check.yaml

Lines changed: 22 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/>
@@ -39,6 +55,9 @@ jobs:
3955
[{"body" : "$COMMENT"}]
4056
EOF
4157
58+
# Fail this job.
59+
false
60+
4261
- uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 #v4.3.0
4362
if: always()
4463
with:

0 commit comments

Comments
 (0)