Github Release of iOS app to App Store with Fastlane

Continuous Integration for iOS using Fastlane

Lito
5 min readOct 13, 2021

This article will guide you on how to prepare our Fastlane to launch new releases using tagging versions with Semantic Versioning, Github Releases in our Github repository, and much more in an automated way with Fastlane.

Keep in mind that it is necessary to follow the past article because this is a continuation.

Steps to follow in the post

  1. Organize our Fastlane directory
  2. Export common functions in Utils folder
  3. We going to make two private lanes, one of them for build to Testflight and another one for making new releases
  4. Modifying Fastfile

1. Organize our Fastlane directory

This will be our structure of the Fastlane folder

Our tree Fastlane folder structure

We’ll have two new folders named Lanes and Utils. The Lanes folder has within private lanes, and Utils the common functions used by these lanes.

So, you can get the project from the last post that you should have and start to modify it to have this new structure.

2. Export common functions in the Utils folder

Well, it’s time to pull out the common functions in our current Fastfile.

In the first step, we going to create the following ‘.rb’ files inside the Utils folder Env.rb, Git.rb, Keychain.rb, Slack.rb and put inside of each file the following content, take into account that some functions are new, for example, contents of Git.rb

  • Env.rb

In Env.rb we can add the next code:

Env.rb

As you can see, we put the .env properties inside the file.

  • Git.rb

Next is Git.rb, and this file is the manager for all the git tasks that are needed:

Git.rb

In our case, we only use to collect git commit messages from the changelog.

ℹ️ Take into account you can choose your current development branch in the between param.

  • Keychain.rb

The following is a file called Keychain.rb and how the name says is in charge of manage all interactions for Keychain:

Keychain.rb
  • Slack.rb

And the last one is Slack.rbwith a unique task will manage all Slack interactions, and its aspect is the next:

Slack.rb

So, we have finished with the Utils folder, ensure that you have the correct files inside this and we can continue with the lanes folder.

3. Private lanes

The main idea of these folder files will be to have the processes in separated files in order to maintain them in a better way.

So, we can start with our existing lane named Testflight.rb, and contents are the same that still we should have but modifying some things like a functions calls.

  • Testflight.rb

The content will be the next:

Testflight.rb

The code is self-explained, if you have some doubt, you can ask me.

The idea is to push a new version to app store connect, and when this finishes make a commit with a new build data.

Well, the next one is the newest script for manage new Github Releases, its name will be Release.rb and the content is the following:

  • Release.rb
Release.rb

So, this script is similar for the Testflight, but the difference is that it makes a new Github release with the messages of commits between your chosen branches, this is the main difference.

On method set_github_release yo can modify the parameter commitish with your correct root branch, usually master or main.

The idea is the same as Testflight, make all necessary tasks for pushing a new version in the App Store Connect and manage all Git tasks, the next thing that you need to do is going to App Store Connect a finish the process manually, I prefer to do like that in order to prevent surprises.

4. Modifying Fastfile

Well, we’re near to finish, this file is very easy to understand, the main idea is to create two public lanes for calling the privates lanes.

Ok, we have all the necessary files for use and modify our Fastfile, so we can remove all the content of it and add the below code in order to call and import all the recent files that we been created.

  • Fastfile (medium doesn’t allow add more code blocks)
https://gist.github.com/litoarias/486891ab88fcfe59b70ff69a215a1b89

So, when you want to send a new Testflight version should call:

fastlane beta

And when you want to send a new Github release, you need to choose one type of version, major, minor, or patch, this will do it in the following ways:

  • New patch version:
fastlane release bump:patch
  • New minor version:
fastlane release bump:minor
  • New major version:
fastlane release bump:major

The logic inside the script ensures the user puts a bump param, if not the script back an error.

The numerical sequence of the versions will be automatically incremented according to the latest released tags, you don’t need to remember the version, it will be an automated process 🤘.

When for example you launch a Minor version, you’ll see on your repo main page the new release, in our case is the first and the new tag is v0.1.0:

And if you access to Releases on your repo you can see the complete release that we are pushing:

The same for our git history on Sourcetree:

And in your Slack channel also we have noticed:

You now can deploy new Testflight versions and releases without effort, the git tagging will be managed by Fastlane, the Slack channels will be informed of the process, and now you have an automated process 💪

Example project:

https://github.com/litoarias/CDProject

That’s all for the CD series, I hope that you are able to do this process, if you have any queries, ask me!!

Cheers 🍻

Collaborate

Thanks for your support! 😃

Resources

--

--

Lito

iOS developer at Kairos DS | iOS Lover | Valencian living on Madrid | Sometimes I try to be a writer