Using fastlane

      No Comments on Using fastlane

fastlane is a very popular automation tool for developers. It can do so much for you: manage code signing, create screenshots, publish betas, upload release builds to iTunes Connect, manage your app’s metadata… Over the last couple of weeks we’ve talked about using match for code signing and using snapshot to automatically generate screenshots. This week we’ll talk about using fastlane to upload your app to iTunes Connect for processing.

What’s The Plan

By the end of this article we’ll do all of these steps automatically with only one terminal command:

  • generate screenshots for our app
  • update the metadata
  • increase the version of the app
  • create a tag with the version
  • commit it to the repo
  • upload the app to iTunes Connect for processing
  • send a slack message

Before you begin you’ll have to create your next app version on iTunes Connect:

I’ll assume you know how to do that ๐Ÿ™‚

Setting Up fastlane

If you’ve been following the tutorials these last few weeks, chances are you already have fastlane set up, just in case you haven’t been following, install the latest command line tools:

After that, install fastlane:

And add this to your .bash_profile:

That’s all the setup you need. On to the project…

Project Setup

Go to your project directory, open up the terminal and initialise fastlane:

fastlane will ask you a couple of simple questions, just follow the wizard.ย We’ll be automating the app store distribution, so select that option when you see these options:

At one point, fastlane will ask you if you want it to manage your app’s metadata, select yes:

When you’re finished with these steps you’ll find a new directory in your project directory:

Xcode Project

Open up your project in Xcode and make sure that Xcode is not automatically managing signing:

You will also need to change the versioning system and the initial project version. Select your target, go to ‘Build Settings’ and find the ‘Versioning’ section. Make sure you select ‘Apple Generic’ and set your current project version:

That’s it for the project setup. Let’s check out some of the files fastlane created for us.

App Metadata

Since we’ve asked fastlane to manage our app’s metadata we can see a folder with our existing metadata:

All the metadata is conveniently organised in ‘.txt’ files. If you wish to change any of it for your next release you can simply edit these files and commit your changes to git. You should at least update the ‘release_notes.txt’ file for your next release. If you have your metadata in other locales, they will appear in their respective folders (just like ‘en-US’ is in its folder above).

Fastfile

One of the files fastlane created for us is called ‘Fastfile’ this is the main setup file that you’ll use. We’ll create one lane in this file called ‘release’. This is how my ‘Fastfile’ looks like:

Let’s go over it from the top. We named our lane ‘release’, this is what we’ll type in the terminal after ‘fastlane’ you can call yours anything you like. We sync our distribution provisioning profiles and certificates. This is done using match. After which we increment the build number and build the app. We’re saving the build number from this step, we’ll use it later.

When the build completes we’ll create the screenshots. Screenshots are created using snapshot, you can read about it in one of the previous articles. In the next step, we’re actually uploading the app to the app store.

After the upload, we’re getting the version number of the app. We’ll use the version number and the build number to create a commit message and we’ll commit the version bump. All that’s left is to tag the repo and push all our local commits to remote.

We’re sending a slack message in the last step, this step is optional, but I find it very useful. We’re all set to run.

Watch It Run

Open up the terminal, navigate to your project directory and type:

If you’re sending a notification to your slack channel, make sure you have your webhook url ready. If you’re not using it then there shouldn’t be any interactive steps for you after the above terminal command.

Depending on your project size, this step can last a couple of minutes. It’s time to get some tea/coffee ๐Ÿ™‚

After a few minutes you will be greeted with a success message from fastlane:

If you have slack integration enabled, you will also see the message:

You should see the tag in your git repo as well:

If you go to the iTunes Connect and check your new app version, you should see the metadata updated, in our case the screenshots:

Check out the activities tab, your release build should be there ready for you:

As you already know, processing builds takes some time. If you use the ‘Connect’ app from Apple you’ll receive a push when your build has finished processing. When you do, you just add the build to your new app version and submit your app for review.

This last step is not automated, you’ll have to do it yourself.

Conclusion

This article is the culmination in the series of articles on how to automate your release process. It will definitely save you loads of time. Especially if you release your apps frequently. It takes a couple of minutes to set up and it will pay for itself right after your first app release. It’s definitely worth setting up.

In this article we’ve just scratched the surface of what fastlane can do, you can check out their website for more advanced uses. The knowledge you’ll gain from this article will be enough for you to get you up and running quickly.

I hope you’ve learned something new today and that you’ve enjoyed the article.

Have a nice day ๐Ÿ™‚
~D;

More resources

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.