Announcing Commit Cannon - A tool for automating changes across multiple git repos

Christopher Szatmary
TouchBistro Software Development
3 min readMar 11, 2020
Photo by Thomas DiRoma on Unsplash

At TouchBistro we have a number of different services. To make our CI/CD pipeline easier to support, we require various files (CI config, Dockerfile, etc) to be consistent across services.

We found that trying to make bulk changes to these files could be very tedious and time-consuming as we applied the same changes in each repository and created the corresponding pull requests. And as with any repetitive task, it was possible to space out and make an error in one of your changes.

Doing this manually was a real drag and a lot of unnecessary work. Automation to the rescue!

We created commit cannon, a tool that makes a series of changes to multiple GitHub repos. It supports various file manipulation operations and can even be used to run shell commands against target repositories.

By default cannon will push all changes to the target GitHub repositories, automatically creating Pull Requests for you.

Example usage

cannon uses a YAML configuration file (cannon.yml) that defines what repositories to apply the changes to and what actions to take.

An action is any change that cannon is able to apply — such as replacing a line of text or creating a file.

Recently we had to update how we were launching a number of node services. We had also discovered a way to update our Dockerfile to take better advantage of layer caching, so we wanted to replace the existing Dockerfile in each repository. Below is the YAML script we used to apply the change to seven separate repositories.

repos:
- name: TouchBistro/loyalty-gateway-service
- name: TouchBistro/ordering-ooa-service
- name: TouchBistro/partners-api-service
- name: TouchBistro/partners-config-service
- name: TouchBistro/partners-etl-service
- name: TouchBistro/touchbistro-node-boilerplate
- name: TouchBistro/venue-provisioning-service
actions:
- type: replaceText
source: node — no-deprecation dist/index.js
target: node dist/index.js
path: package.json
- type: replaceFile
source: files/Dockerfile
path: Dockerfile
- type: runCommand
run: SHELL >> if [[ ! -d data ]]; then mkdir data; touch data/.gitkeep; fi

The first thing in the file is the list of repos that we’d like to apply the changes to. It would be tedious to go in and modify each of these repositories one at a time so I’m glad we have cannon to streamline things.

Next we define our list of actions.

First, the action type replaceText, unsurprisingly, will allow us to replace a line of text matching node dist/index.js with node — no-deprecation dist/index.js in the package.json file.

Second, we want to replace the Dockerfile in the root of the project with a new Dockerfile we’ve created at files/Dockerfile relative to where we ran cannon.

To support the changes in the new Dockerfile, we need to ensure that every repo has a data directory. So, in the final action, we have commit-cannon run shell commands to create a data directory with a .gitkeep file, if it does not exist already.

Now that we have our actions defined, all we need to do is run commit-cannon. The CLI is simple: cannon -m <commit message> will use the cannon.yml file found in the current working directory. cannon will apply our changes, push the new branches to GitHub, and open Pull Requests to the target repositories (see below).

Example pull request message

While cannon is not the most complicated bit of tooling we’ve created, it has been a huge time saver for us here at TouchBistro. And it has prevented us from making dumb mistakes when trying to apply the same tedious changes across multiple repositories. If you think this tool could be helpful to you, feel free to check out the README.md in the GitHub repo for more detailed instructions on how to use cannon. We welcome any feedback you may have here or via the GitHub repository.

We are already hard at work tidying up the next tool to get it ready to be open-sourced. We look forward to sharing that with you soon.

Does TouchBistro sound like somewhere you might like to work? We are always looking for talented new team members. Check out https://www.touchbistro.com/careers/#open-positions to find the role that is right for you.

--

--