Skip to Content
Course content

153: Fastlane for iOS Automation

Click on the "Edit" button in the top corner of the screen to edit your slide content.

I'm sitting here watching the Xcode progress bar crawl across the screen for the third time today. Archive, wait, distribute, select the team, upload to TestFlight... it's a ritual we've all done a thousand times, and frankly, it's a waste of our brainpower. I've got a productivity app—let's call it "TaskMaster"—and every time I want to push a bug fix to my beta testers, I have to manually navigate these five or six menus. It's tedious, and it's where mistakes happen.

The Manual Grind

I decided today that I'm done with the manual dance. I've heard about Fastlane for years, but I always told myself, "I'll just do it manually, it only takes five minutes." But five minutes every day is hours a month. So, I'm opening the terminal. First thing: brew install fastlane. I'm expecting it to be a breeze, but as any iOS dev knows, the moment you touch the command line and Ruby, things get spicy. I'm seeing a few permission errors on my gems. I'll just use a version manager or sudo (though I hate doing that) to get it sorted. Once the fastlane command actually responds, we're in business.

Mapping the Automation

Now, I'll run fastlane init in the root of the TaskMaster project. Fastlane starts asking me questions. It wants to know my Apple ID, my team ID, and if I want to automate screenshots. I'll skip the screenshots for now—I just want the build to get to TestFlight without me clicking "Distribute App" for the millionth time. It generates a Fastfile. This is basically the script where we define our "lanes."

I'll start with a very basic lane. I'm thinking: I want to build the app and upload it. In Fastlane terms, that's gym (for building) and pilot (for TestFlight). Let's try this:

lane :beta do
  gym(scheme: "TaskMaster")
  pilot
end

I run fastlane beta. I'm expecting a victory lap, but instead, I get a wall of red text. "Code signing failed." Of course it did. Fastlane is trying to build the app, but it doesn't have the certificates or the provisioning profiles stored in a way it can access them without my manual intervention in Xcode.

The Provisioning Wall

This is the part where most people give up and go back to the Xcode GUI. But the "proper" way to handle this is using match. I've heard match is the gold standard because it stores certificates in a private Git repo, so every developer on the team uses the exact same ones. I don't want to set up a whole repo just for this quick test, so I'm going to try the "quick and dirty" fix first: I'll make sure my Xcode project is set to "Automatically manage signing" and see if gym can pick that up.

I adjust the gym call to be more explicit about the build settings. I'll add export_method: "app-store". I run it again. It's still complaining about the distribution profile. I realize that Fastlane is essentially acting as a separate entity from the Xcode IDE. I need to tell it exactly how to handle the signing. I'll dive into the Fastfile and add the setup_ci action, which helps Fastlane handle the certificates on a machine that might not have the IDE open.

lane :beta do
  setup_ci
  gym(scheme: "TaskMaster", export_method: "app-store")
  pilot
end

I trigger it again. This time... it actually works. I can see the ipa being generated in the fastlane/builds folder. Then, the magic happens: pilot takes that file and pushes it straight to App Store Connect. I didn't touch a single Xcode menu.

Refining the Pipeline

Now that it works, I'm thinking about the "Developer Experience." I don't want to stare at the terminal for ten minutes wondering if the build crashed or if it's just slow. I'll add a Slack notification. It's a tiny change, but it's the difference between "I think it's uploading" and "I'll get a ping on my phone when it's done."

I add the slack action to the end of the lane. I'll need a webhook URL from Slack, but once that's in, my lane looks like this:

lane :beta do
  setup_ci
  gym(scheme: "TaskMaster", export_method: "app-store")
  pilot
  slack(message: "TaskMaster Beta build successfully uploaded to TestFlight! 🚀")
end

I run fastlane beta one last time. The terminal scrolls, the IPA uploads, and then—ding—my phone buzzes. I've just turned a 15-minute manual chore into a single command that I can eventually move to a CI server like GitHub Actions or Bitrise. I can finally stop watching the progress bar.




📋 Practical Task

Exercise: Integrating Slack Alerts into the TaskMaster Build Pipe

You have been provided with a Fastfile that currently builds and uploads the "TaskMaster" app to TestFlight, but it provides no feedback upon completion. Your goal is to modify the Fastfile to include a notification system.

Requirements:

  • Modify the :beta lane to include the slack action.
  • The notification must trigger only after the pilot action has successfully completed.
  • The message sent to Slack must specifically include the text: "TaskMaster build is live on TestFlight" and an emoji of your choice.
  • Ensure that the setup_ci and gym actions remain in the correct logical order before the upload.

Starter Code:

lane :beta do
  setup_ci
  gym(scheme: "TaskMaster", export_method: "app-store")
  pilot
end
Rating
0 0

There are no comments for now.

to be the first to leave a comment.