Skip to content
Merged
Changes from 1 commit
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
36 changes: 36 additions & 0 deletions .github/workflows/email-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: "Check for private emails used in PRs"
on: pull_request_target
permissions:
pull-requests: write

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