-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Add github workflow that checks if a private email address was used to contribute to the repo and warn in this case #80514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: "Check for private emails used in PRs" | ||
|
||
on: pull_request_target | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
validate_email: | ||
permissions: | ||
pull-requests: write | ||
runs-on: ubuntu-latest | ||
if: github.repository == 'llvm/llvm-project' | ||
steps: | ||
- name: Fetch LLVM sources | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
|
||
- name: Extract author email | ||
id: author | ||
run: | | ||
git log -1 | ||
echo "EMAIL=$(git show -s --format='%ae' HEAD~0)" >> $GITHUB_OUTPUT | ||
|
||
- name: Validate author email | ||
if: ${{ endsWith(steps.author.outputs.EMAIL, 'noreply.github.com') }} | ||
uses: actions/github-script@v6 | ||
env: | ||
EMAIL: ${{ steps.author.outputs.EMAIL }} | ||
with: | ||
script: | | ||
const { EMAIL } = process.env | ||
await github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo. | ||
Please turn off [Keep my email addresses private](https://github.com/settings/emails) setting in your account. | ||
`}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this getting the whole repo each time? I wonder if there are some "shallow checkout" options that would apply here.
Or we could get it from the PR event, maybe, but I guess you already looked for that and I don't want to derail the chosen solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is
user.email
in https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request. Would need testing to confirm, but I'd guess that checking for null ornoreply@github...
in the string would work.And possibly this could all be done in the YAML. Which is not necessarily a good thing so you don't have to change what you've got.
Just know that this is (allegedly) an option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emails could come from different places, but we mostly bother about email of author in the commit (which has to set up manually from via
git config
if one uses git CLI and private email address, so must be done explicitly) and I thought this is the most bullet-proof way to do this.