I prefer to have my email and do everything under my name and email address so everything goes under my Github statistics and everybody sees what I did when developing with multiple developers so I don't like the `git config user.email "[email protected]" approach and I commit a failed deployment and when I want to deploy, I have a GitHub account logged in in another browser that can commit to Vercel. There I do a dummy README space/space removal commit in the browser and deploy.
To automate a process where a dummy commit is made using a specific email when a commit is made by someone not using Vercel email I have created a .github/workflows/dummy-commit.yml
:
name: Dummy commit if someone else than [email protected]
on:
push:
branches:
- main # Replace with your branch
jobs:
enforce-email:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get commit email
id: get_email
run: |
email=$(git log -1 --pretty=format:'%ae')
echo "Commit email: $email"
echo "email=$email" >> $GITHUB_ENV
- name: Check email and perform dummy commit if necessary
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EMAIL: ${{ env.email }}
run: |
if [ "${{ env.EMAIL }}" != "[email protected]" ]; then
echo "Email does not match. Performing dummy commit."
git config user.name "username or Name Surname"
git config user.email "[email protected]"
echo "Dummy commit at $(date)" > dummyfile.txt
git add dummyfile.txt
git commit -m "Dummy commit to deploy"
git push
else
echo "Email matches. No action needed."
fi
Now, create in your project's root a dummyfile.txt
and replace [email protected]
in 2 places and username or Name Surname
with the Vercel hobby plan Github email/username (or name). Also, replace the main
branch if needed. Also, give permissions:
It works, and I'm in a hurry now, but I also plan to squash the dummy commit with the commit that triggered it so as not to clutter the commit history with every second commit being a dummy. I'll update here when done.