iOS Deployments using Fastlane ๐ŸŽ๏ธ

iOS Deployments using Fastlane ๐ŸŽ๏ธ

  • redgoose
  • 2 minutes
  • June 27, 2020

In this post, weโ€™ll talk about deploying mobile apps using Fastlane.

Step - 1: Install Fastlane

The first step is to install Fastlane tools on your iOS Project.

To do that, step into the root of your project in a terminal and initialize the bundler. Yes, this is the same bundler that the good folks in the rails community use.

  $ cd /path/to/your/red-goose 
  red-goose$ bundle init

The command above will write a new Gemfile at /path/to/your/red-goose/Gemfile. And while youโ€™re at it, you might want to add the following massive gist on your .gitignore file:

Now open your project on visual studio code (not xcode!) and replace the contents of the Gemfile with the following:

  // Gemfile:
  source "https://rubygems.org"

  gem "fastlane"
  gem "dotenv"

And then run $ bundle install to install both Fastlane and Dotenv to your project. Once the installation has completed, check the Fastlane version with:

$ fastlane --version

I was on version fastlane 2.159.0 at the time of writing this guide.

Done. The first step is complete.

Step - 2: Set up Fastlane

The next step for us is to initialize and configure Fastlane for our iOS builds.

To do that:

  red-goose$ fastlane init
[โœ”] ๐Ÿš€
[โœ”] Looking for iOS and Android projects in current directory...
[13:26:38]: Created new folder './fastlane'.
[13:26:38]: Detected an iOS/macOS project in the current directory: 'Red.Goose.xcworkspace'
[13:26:38]: -----------------------------
[13:26:38]: --- Welcome to fastlane ๐Ÿš€ ---
[13:26:38]: -----------------------------
[13:26:38]: fastlane can help you with all kinds of automation for your mobile app
[13:26:38]: We recommend automating one task first, and then gradually automating more over time
[13:26:38]: What would you like to use fastlane for?
1. ๐Ÿ“ธ  Automate screenshots
2. ๐Ÿ‘ฉโ€โœˆ๏ธ  Automate beta distribution to TestFlight
3. ๐Ÿš€  Automate App Store distribution
4. ๐Ÿ›   Manual setup - manually setup your project to automate your tasks
?

Fastlane will ask four ways to install itself.

Weโ€™ll go with the fourth optionโ€“manual setupโ€“for the purpose of this article.

During installation, Fastlane will ask a few more things. Just press enter to continue setting up with defaults. Now youโ€™ll see a new directory called fastlane inside your project containing the following two files:

  red-goose$ ls
  Gemfile                               Pods                                  goose.red.xcworkspace
  Gemfile.lock                          README.md                             goose.redTests
  fastlane                              goose.redUITests
  Podfile                               goose.red
  Podfile.lock                          goose.red.xcodeproj
  
  $ cd fastlane && ls
  1. Appfile
  2. Fastlane

We will be using the Fastlane file to specify the lanes or the tasks that our iOS app is going to need to build with and leave the Appfile untouched because for environment variables we will use the dotenv instead.

Letโ€™s start on the lanes for our Fastlane setup.

Step-3: Stubbing out the lanes

On your Fastlane file copy the following contents:

platform :ios do

desc "Create app on the Developer Portal and App Store Connect"
  lane :create do
    create_app_online # Or produce
  end

  desc "Sync sign using"
  lane :sign do
    create # The sign lane above.
    sync_code_signing	# Or match
  end

  desc "Generate the binaries"
  lane :build do
    sign # The sign lane above.
  end

  desc "Upload to App store"
  lane :release do
    build # The build lane above.
    # build_app(workspace: "goose.red.xcworkspace", scheme: "goose.red")
    # upload_to_app_store(skip_metadata: true, skip_screenshots: true)
  end
end

Notice that each lane has a single responsibility and is chained to the next lane in a sequence.


Written by: Marvin Danig, CEO of the Red Goose. Follow me on Twitter or on Github!

About the author

Marvin Danig

I write code with my bare hands. ๐Ÿ’ช๐Ÿป Yammer about Bubblin all day.

https://bubblin.io/marvin