How to build your own CocoaPod Library for iOS — Part 2
In previous tutorial I introduced to you how to release an iOS library to CocoaPod. So today I will guide you how to integrate with codecov and travis CI to make sure quality of the library when you want to update library any time. Beside that you also increase the reliability for users when they take a look your public document on github. That’s great!
The following are the main content you will get through this tutorial:
- Integrate with codecov
- Integrate with Travis CI
- Display results on github
Okay, let’s go!
Integrate with codecov
Codecov help you improve your code review workflow and quality. Codecov provides highly integrated tools to group, merge, archive, and compare coverage reports.
Now let sign in with your githup account to integreate with codecov. There are some easy steps to finish the authorization, just follow their notification.
After you finished the above step, you can add your github repo right now:
Click Add new repository to link your project with codecov. When you link success, Codecov will generate a token for you can use later. Example as the following:
Now let open Xcode to be enable Code coverage for the project. In this example, I only want to be enable the library, exclude the example project:
Choose Edit schema -> Test option -> Check on Code coverage
Then you try to run test cases for Xcode can generate the report, this report can be analyzed by Codecov later.
Click on Test navigator or Command + U to run test cases:
Okay, all test cases are passed. That’s wonderful!
You have to open terminal and move to current project to run codecov:
bash <(curl -s https://codecov.io/bash) -t uuid-repo-token # this is token has been generated before
After finish the processing, you come back to codecov.io to check the result:
Code has been covered 100%. Perfect! :)
Noticed that whenever you want to take code coverage, you must to run test cases and type command line again and again. This is bored. Now let integrate with Travis CI for it can runs automatic whenever you submit code.
Integrate with Travis CI
This is the description of Travis CI: The simplest way to test and deploy your projects.
You also need to sign in with your github account on Travis CI. This step is also easy, just follow the processing.
Now we will create a .travis.yml file for the project can communicate with travis CI. In current context of terminal that you ran the codecov before, let type:
touch .travis.yml
Then open this file with vim:
vim .travis.yml
Just paste the following content:
language: swift # or objective-cosx_image: xcode10.2script:- xcodebuild -scheme HPCalculator -workspace HPCalculator.xcworkspace -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone X,OS=11.4' build test # If you have changed with your new scheme, you must replace HPCalculator tooafter_success:- bash <(curl -s https://codecov.io/bash) -t uuid-repo-token # Replace with your toke
To get more knowledge about Travis CI, you should take time to visit their website at here.
One take note you should remind to specify SWIFT_VERSION for your target. In my example, I support swift 5 so I need to edit the build settings editor as the following:
Now let push the resources to github:
git add .
git commit -m "Add travis CI"
git push origin master
And let see the result on Travis CI::
You also come back to codecov to see the testing result of Travis CI:
Everything is good so far! But how to show all the results above on repository for uses can see as well improve the reliability.
Display results on github
We will code coverage badge and travis badge to README.md as the followings:
Copy the markdown script of codecov.io:
Also the same for travis CI:
Open README.md on github and paste all of them to this file:
Let preview it:
You can also add more badges to look better:
[](https://developer.apple.com/iphone/index.action)
[](https://developer.apple.com/swift)
[](http://mit-license.org)[](https://cocoapods.org/pods/HPCalculator)
[](https://github.com/quanghoang0101/HPCalculator/issues?state=open)
P/s: You need to change with your repo in three last badges.
You also take a look at markdown syntax to write a great document on README.md for user at here.
Okay, That’s it! I hope this tutorial is useful a lot for you.
Preferences: