Skip to content

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 2 commits into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/email-check.yaml
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 }}
Copy link
Collaborator

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.

Copy link
Collaborator

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 or noreply@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.

Copy link
Collaborator Author

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.


- 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.
`})