Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing to CocoaPods from Travis

How would you go about pushing to CocoaPods from Travis? I would like for each tagged commit to do a pod trunk push, but is it a good idea to pod trunk register Travis? Trunk's docs say it registers a machine, rather than a user, so would that inadvertently open up the Pod to pushes from other people who use Travis?

Does anyone have an example of a repo that's already doing this?

You can do this with RubyGems using private API keys pushed with the Travis command line tool, as described in RubyGems Deployment.

like image 553
Dov Avatar asked Oct 15 '14 11:10

Dov


2 Answers

Cocoapods support authentication with a Token.

First, you need get the Token from the password field of ~/.netrc. After calling pod trunk register, you'll see a section that looks like this:

machine trunk.cocoapods.org
   login [email protected]
   password 0000000011111111

Then you can update podspec on CI with the Token (which is insecure):

export COCOAPODS_TRUNK_TOKEN=0000000011111111
pod trunk push path/to.podspec

You can also encrypt the Token in Travis-CI with

travis encrypt COCOAPODS_TRUNK_TOKEN=0000000011111111 --add env

Update

You can now set environment variable directly in your plan's Settings. If you turn off Display value in build log (which is disabled by default), it treats it as a secure variable. That way, you don't need to mess with the Travis command line tools, or add junk to your yaml file, and can make changes without altering your repo.

Travis environment variables

like image 51
Quanlong Avatar answered Sep 19 '22 11:09

Quanlong


Thanks @Quanlong for info regarding in which file the password can be found.

You can extract the password from said file using this command

grep -s password ~/.netrc | awk '{print $2}'

So if you are using fastlane or any other CI suite you can set the token like this

ENV['COCOAPODS_TRUNK_TOKEN'] = sh "grep -s password ~/.netrc | awk '{print $2}'"

Which works in fastlane. Otherwise you might wanna call the grep command in some other way, maybe system("grep ... ")

like image 34
Sajjon Avatar answered Sep 20 '22 11:09

Sajjon