Tests in pre-commit hooks and alternatives
Tags: swift, git
Published: 2019-08-24 15:13:09

---
title: Tests in pre-commit hooks and alternatives
published: true
tags: swift,git
canonical_url: https://zeitschlag.net/tests-in-pre-commit-hooks-and-alternatives/
---

A few months ago, I bought myself a fancy MacBook Pro. You know, one of those fancy devices with the fancy TouchBar, a nice Retina screen and a [broken-by-default keyboard](https://support.apple.com/keyboard-service-program-for-mac-notebooks). And to make myself feel better, 'cause you never know what might happen in the next couple of years, I bought an AppleCare Plus-package as well.

In the beginning, I was pretty happy with this setup — it was amazingly fast: Everything was just there! Wow! Mindblowing! And then the space bar started to trigger twice. A few weeks later, the left CMD-key as well as some other keys behaved the same way. And so I brought the computer to an Apple reseller last week to send it to Apple to have them replace the entire keyboard.

And in the meantime I've used my old computer. It's a 2014 Macbook Air with a 1.4Ghz CPU and 4GB of RAM. I've kept it as a backup computer and I'm really disappointed, that I have to rely on it after a fews months. Compared to the 2018 Macbook Pro, it's pretty slow but hey, it has a working keyboard, at least. And I relied on that MBA for more than 4 and a half years and it has never let me down.

In July, Max and me recorded an episode of our german [Codestammtisch-podcast](https://codestammtis.ch). Together with our [guest Dominik we discussed Knowledge Transfer](https://codestammtis.ch/2019/07/15/cst032-wissenstransfer-mit-dom/) and during that episode, Dominik mentioned, that it's possible to [automate tests in iOS with git-hooks](https://medium.com/@pearsontsp/automate-tests-in-ios-with-git-hooks-8d97b66e0f36). This week, I actually tried that, as I really like the idea. I set up the tests to run in a pre-commit hook. Before every commit, the project is compiled, all of my unit tests are run and if — and only if — they succeed, the commit is created.

Unfortunately, this doesn't make a lot of fun on my fallback-MBA as compiling the Swift-code and running the test takes roughly one minute. That means, that creating a new commit takes one minute every single time. That means a lot of time wasted waiting.

What are my alternatives? I could move this from a pre-commit hook to a pre-push hook as suggested in the [aforementioned blog post](https://medium.com/@pearsontsp/automate-tests-in-ios-with-git-hooks-8d97b66e0f36).

Or I could use something like [Windmill](https://www.windmill.io) or a local [Jenkins](https://jenkins.io), but that wouldn't solve the problem as those tools would still run locally on my oldie-but-a-goldie MBA. Neither would using [Gitlab CI](https://about.gitlab.com/product/continuous-integration/), as its runners still run locally on my machine. I don't have another spare computer flying around to use it as a build server.

Antother alternative would be the free hobby plan of [bitrise](https://www.bitrise.io). Or I could open-source my project and profit from [Travis CI](https://travis-ci.org). Or I could pay them. Or I could rent a Mac from [MacStadium](https://www.macstadium.com) for example, and have it run a Gitlab Runner, or my own Jenkins, or Xcode Bots.

So many possibilities to choose from! I might choose the most affordable way until my MBP is back. Just hit `CMD+U` after every `CMD+S`. Let's see, because:

> [Pressing `CMD+U` is] a hard habit to form, especially for us iOS developers.
> 
> — [Source](https://medium.com/@pearsontsp/automate-tests-in-ios-with-git-hooks-8d97b66e0f36)

<!--kg-card-end: markdown-->