DEV Community

Cover image for Robo-committer for automated commits
Dave Cross
Dave Cross

Posted on

Robo-committer for automated commits

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'
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

GitHub commits

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.

Top comments (5)

Collapse
 
cicirello profile image
Vincent A. Cicirello

Not only is it "not particularly well-documented", I'm not sure if it is officially documented at all. At least I haven't seen it documented. I've been using the github actions bot for automated commits for a while now. One of the GitHub Actions that I maintain makes commits. And when I was working on that functionality, I stumbled upon the approach of committing as the github actions bot while looking at the source of other actions to see how they were doing it (after failing to find anything in docs). I wanted to avoid artificially inflating commit counts for all of my users.

Collapse
 
leandrobarbosafr profile image
Leandro Barbosa

Can you provide all the repository for the bot??? if is it a bot

Collapse
 
davorg profile image
Dave Cross

I don't think it has a repository (if it does, it's probably a private repo somewhere in github.com/github).

I found the information in this support discussion - github.com/orgs/community/discussi...

Collapse
 
leandrobarbosafr profile image
Leandro Barbosa

i will check it out thanks

Collapse
 
waleedh profile image
Waleedh Nihal

WOW 😲!