Tests in pre-commit hooks and alternatives

zeitschlag

Nathan Mattes

Posted on August 24, 2019

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. 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. Together with our guest Dominik we discussed Knowledge Transfer and during that episode, Dominik mentioned, that it's possible to automate tests in iOS with git-hooks. 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.

Or I could use something like Windmill or a local Jenkins, 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, 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. Or I could open-source my project and profit from Travis CI. Or I could pay them. Or I could rent a Mac from MacStadium 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

💖 💪 🙅 🚩
zeitschlag
Nathan Mattes

Posted on August 24, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related