Creating iOS framework with CocoaPods, Carthage, SPM support and Travis for running test and Fastlane for release automation — Part 5
--
Creating Swift framework is easy but adding CocoaPods, Carthage and Swift Package Manager support at the same time can sounds like scary in the first place. In addition to that adding Travis to run test for all commits and adding Fastlane to automate release processes for all dependency managers looks like a horror movie. But don’t be afraid. After you finished this series, you can easily create your own Swift frameworks that uses all these tools to make it perfect!
This series consist of 5 parts:
Part 1 — Create CocoaPod and release it.
Part 3 — Add Swift Package Manager support
Part 4 — Integrate Travis to build example project and run tests for framework
Part 5 — Integrate Fastlane to automate release processes by running just one line of command.
Make sure you have the latest version of the Xcode command line tools installed:
xcode-select --install
Install fastlane using
[sudo] gem install fastlane -NV
or alternatively using brew cask install fastlane
Navigate your terminal to your project’s directory and run
cd ODCustomFrameworkfastlane init
3. Press 4 for manual setup when terminal asks.
4. Open Fastlane file inside ODCustomFramework/fastfile. Then paste the following lines:
After that open ODCustomFramework/Gemfile and paste following:
gem “cocoapods”
5. Commit and push all changes to the GitHub.
git add .
git commit -m "Fastlane integration"
git push
6. Navigate your terminal to your project’s directory:
cd ODCustomFramework
Run one of the followings:
exec fastlane patch // increments patch count -> 0.1.Xexec fastlane minor // increments minor count -> 0.X.0exec fastlane major // increments major count -> X.1.0
Let’s recap from Part 1, every time you want to release new version of your framework via CocoaPods, Carthage and Swift Package Manager, you have to go through following steps:
1- Implement changes for new version2- Run tests to be sure they are working3- Commit and push changes for new version.4- Tag new version to git
git tag 0.1.1
git push origin 0.1.1Carthage and Swift Package Manager installs your framework from GitHub. If you configure your framework correctly, it can be installed via Carthage or Swift Package Manager after this step. However, CocoaPods has 4 more steps to complete release processes.5- Increment podspec version => i.e. s.version = '0.1.1'6- Validate local podspec:
pod lib lint ODCustomFramework.podspec7- Validate pod for release
pod spec lint ODCustomFramework.podspec8- Release
pod trunk push ODCustomFramework.podspec
After Travis and Fastlane integration, steps 2, 4, 5, 6, 7 and 8 are automated and those steps are no longer needed to repeat every time you want to release new version.
1- Implement changes for new version2- Commit and push changes for new version.3- Travis runs tests automatically after every push.4- Run following fastlane command to automate all release processes. (step 4, 5, 6, 7, 8) exec fastlane major | minor | patch
That’s all. Now you have a framework that can be installed by CocoaPods or Carthage or Swift Package Manager. Besides that you don’t need to run tests for every changes. Travis will do that after you push changes to GitHub. Lastly, when you decide to release new version, only thing you need to do is running one line of command and Fastlane will do the rest.
You can find ODCustomFramework here, and if you want to see real life example, you can look ODScrollView which is developed by me.
Thanks!