That's an screenshot of my GitHub contributions for the last year. Almost 50,000 commits is a ridiculous number for one person to make in a year. Obviously I had some help.
The explanation is in my previous article GitHub Actions for semi-static web sites. In that article I explained how I was using GitHub Actions to rebuild a number of web sites every few hours. It doesn't take very many of those web sites before you start getting into dozens of automated commits every day. And it is, of course, those automated commits that are artificially inflating my commit count.
This has been mildly worrying me over the last year. I decided that I needed to do something about it. I needed to find a way to separate my real commits from these automated ones.
The previous article includes a sample GitHub Workflow file that I was using to run these sites. And it's easy to see what's causing the problem. There's a step that commits the newly-generated site and that step includes the following:
git config --global user.name 'Dave Cross'
git config --global user.email 'my email address'
That email address is associated with my GitHub account and, therefore, those commits are seen as being made by me.
A few weeks ago, I made the first step towards fixing this. I changed that configuration to this:
git config --global user.name 'Automated Workflow'
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
We're using a more descriptive name and an email address that GitHub generates for us based on the username of the user who is running the workflow. This is better (as it won't assign commits to me if someone were to fork my repo and run the workflow) but it's still using an email address which GitHub has assigned to me and, therefore, the automated commits are still associated with me.
Yesterday I had another dig into this problem and I have found the solution. The new version I use it this:
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
It turns out that there is a special GitHub user account that can be used to commit to your repos. This user is specifically there to solve the exact problem that I wanted to solve. It's just not particularly well-documented (or, if it is, it's not in the documentation that I've been looking at!)
You might notice that I've also removed the --global
setting from the commands. On reflection, it seemed pointless to make global changes on a Docker container that is going to cease to exist in a minute or so.
So that's what I now use on all of my workflows that regenerate web sites. It will mean that I make substantially fewer commits this year and I can no longer be accused of trying to game the system in order to artificially inflate my number of commits.
Oh, and as a bonus, the GitHub Actions Bot has its own Octocat avatar that now appears in the commits for my repos.
It's possible, of course, that I'm the last person in the world to realise this. But, hopefully, sharing the information will be useful to someone out there.