An Even Better Way to Automate Tests

Mark McWiggins
2 min readApr 14, 2023

I wrote earlier on automated testing after git pushes, but these require access and cooperation from the git server authorities, either from Github itself or from the administrators of your Github Enterprise server.

Here’s one more way that doesn’t require any of that, just command-line access to the git repo you’re interested in automating.

You use the command git log, which typically gives you the email address of the person updating the repo, in reverse order of the pushes.

As I wrote in my earlier article, some email systems are so overwhelmed that a Your Latest Push Broke the Tests email can easily get lost. That’s why I prefer to use Slack.

Slack Logo

If you want to do it this way, you’ll have to start by collecting a table relating email IDs to Slack IDs. I’d suggest SQLite is plenty adequate for this purpose, but if you already have another db running (PostgreSQL or MySQL or whatever) any should work fine for this.

CREATE TABLE EMAILTOSLACK (int id, email string, slackid string);

Then just run git log in a loop collecting the push information.

Basically you are looking for any new pushes, ‘new’ defined as pushed after your run started.

Start with this command: git log | head -1 >current.commit

Then run in a loop

while true
do
git log -5 | check_for_latest_pushes
sleep 5
done

We use ‘git log -5’ in case there are multiple pushes in 5 seconds. This is unlikely but possible.

When the ‘check_for_later_pushes’ command runs and finds one (or more) matches …

it launches the ‘tester’ script:

./tester.sh @slackid [… @slackid2 ] repo-name

Then if one of the test scripts fails to run to completion,

the slack bot runs and sends a message to the userid or userids (impossible to tell which one broke the tests, but this should be a rare case anyway) on our #YouBrokeit channel.

This method works without any cooperation from Github or the local Github Enterprise administrator. It could be Just the Thing for automating your tests!

--

--