Never run carthage bootstrap again
The title is a bit clickbaity — hopefully, you continue reading anyway 🙂
Ever got tired of running into bugs or build errors caused by an outdated dependency your colleague updated earlier? You don’t want to guide your PO, designer or Android developer how to install dependencies before hitting run in Xcode? Carthage Workflows will save you!
To automatically install dependencies, an option would be to just put
carthage bootstrap --bootstrap --platform iOS --cache-builds into build phase script. So Xcode will run it every time you build. But bootstrapping takes some time, even when everything is actually up to date. For example, running bootstrap one of our current projects with 12 dependencies takes over 50 seconds to complete.
But thankfully this can be much improved. There is a repository with opinionated workflows built on top of Carthage containing a
carthage-verify script that does exactly what we want — without performing any long-running tasks.
Just add the linked repository as a submodule to your project (or copy the verify script if you are super lazy). Then, add a run script build-phase with the following content:
./carthage-workflows/carthage-verify --no_skip_missingif [ "$?" -ne "0" ]; then
carthage bootstrap --platform iOS --cache-builds
echo "All dependencies in sync"
And VOILA! Just hitting run in Xcode will now make sure your Carthage build folder is kept in sync with your
Cartfile.resolve file. So nobody will ever fail running your project because they forgot to update or download some dependencies.
Have a look at Carthage-Auto-Checkout for seeing the script in action.
Thanks for reading!