To use monorepo or not is an eternal debate. Each has its pros and cons. Let’s say you decide to go with monorepo, one major issue you will face over time is slow testing. Imagine a monorepo, consisting of an Android app, an iOS app, some backend code, some web frontend code. On only very few occasions will someone modify more than one of those simultaneously.
Further, most of these projects confined to their directories would be using different build systems as well, for example, gradle for Android, yarn/npm for Javascript, go/rust/java/npm for the backend. The total build time and test time will only grow over time. It annoys developers making small modifications to their part of the codebase. And it slows down the development velocity drastically.
At my previous job, I ended up writing an elementary version of the incremental testing system. We had a set of directories, most unrelated to each and some dependent on each other. As long as we come up with a good directory-dependency tree, a script can check if any files in the pull request modified any of those dependencies; if yes, the test continues, if not, it is skipped. In this way, we cut down a lot of extraneous builds. The goal was not to eliminate all extraneous builds but to minimize the biggest offenders. And that alone made the testing much more manageable. We saved money by reducing the number of Circle CI instances we reserved, and we increased our developer velocity. In a monorepo like ours, you can expect a 5-10x faster testing time.
The code is open-source, so I can easily reference it here. We used Circle CI, but the approach is generic enough and can be used on any other build system as well.
Consider, for example, protocol-test
|
|
The wrapper script
|
|
And the full script which finds out the patch of this pull request over the base branch can be seen here. The most crucial method being,
|
|