DEV Community

Cover image for πŸš€ Automate iOS Builds and Uploads to TestFlight Using Fastlane
Amit Kumar
Amit Kumar

Posted on • Edited on

πŸš€ Automate iOS Builds and Uploads to TestFlight Using Fastlane

In the previous blog, we explored how to integrate Fastlane for Android builds and Firebase App Distribution. Now, moving forward, let's shift gears and focus on the iOS side of automationβ€”specifically, building your iOS app and uploading it to TestFlight using Fastlane.

This guide is perfect for React Native developers who want to streamline iOS releases and reduce manual efforts.


Why Fastlane for iOS?

Fastlane simplifies the complex process of iOS builds and deployments by:

  • Automating tedious tasks
  • Reducing human error
  • Saving hours of manual work
  • Providing consistent builds every time

🧰 Getting Started with Fastlane for iOS

βœ… 1. Install Fastlane

First, install Fastlane using RubyGems:

sudo gem install fastlane -NV

Enter fullscreen mode Exit fullscreen mode

The -NV flags ensure a verbose and non-documentation install, which is faster.


βœ… 2. React Native Project Setup (iOS)

Navigate into your iOS directory:

cd ios
fastlane init

Enter fullscreen mode Exit fullscreen mode

You’ll be prompted with the question:

"What would you like to use fastlane for?"

Refer to the screenshot below and select option 2:
πŸ‘‰ Automate beta distribution to TestFlight

Image description

During this initialization process, Fastlane will ask for your iOS bundle identifier (e.g., com.example.app). Once completed, a fastlane directory will be created inside the ios folder


πŸ” 3. Set Up App-Specific Password for Fastlane

To upload builds to TestFlight, Apple requires an app-specific password. Here’s how to create one:

  1. Visit: Apple.com
  2. Sign in with your Apple Developer account.
  3. Go to Sign-In and Security > App-Specific Passwords
  4. Click Generate an app-specific password, name it (e.g., "fastlane"), and copy the password and paste it in .env file

Image description

Then, create a .env file inside the ios/fastlane directory:
Paste the following line:

And once done now paste the password here

FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD=paste_your_password_here

Enter fullscreen mode Exit fullscreen mode

This ensures that Fastlane can authenticate securely when uploading builds to TestFlight.


πŸ”„ Fastlane Configuration (iOS)

Now that the environment is ready, here’s the Fastlane configuration for building your app and uploading it to TestFlight.

default_platform(:ios)

platform :ios do
  desc "Build and upload to TestFlight"
  lane :build_and_upload do

    # Configuration
    app_identifier = "com.xxxx.xxxx.xxx" # Replace with your actual bundle ID
    profile_name = "YOUR PROJECT NAME - Prod Distribution" # Found in Xcode > Signing & Capabilities

    build_ios_app(
      workspace: "YOUR_PROJECT.xcworkspace",
      scheme: "YOUR_SCHEME", # Typically the same as your project name
      export_method: "app-store",
      clean: true,
      export_options: {
        provisioningProfiles: {
          app_identifier => profile_name
        },
        method: "app-store"
      },
      output_directory: "./build",
      output_name: "YOURIPANAME.ipa"
    )

    upload_to_testflight(
      ipa: "./build/YOURIPANAME.ipa",
      skip_waiting_for_build_processing: true,
      changelog: File.read(File.expand_path("../../release_notes.txt", File.dirname(__FILE__)))
    )
  end
end

Enter fullscreen mode Exit fullscreen mode

Make sure to replace the placeholders like:

  • YOUR_PROJECT.xcworkspace
  • YOUR_SCHEME
  • YOURIPANAME.ipa
  • app_identifier

πŸ“œ Creating release_notes.txt

Place this file in your root directory (above ios):

release_notes.txt

Enter fullscreen mode Exit fullscreen mode

Example contents:

πŸš€ New Features
- Added support for voice recognition
- Improved video playback performance

🐞 Bug Fixes
- Fixed crash on iOS 17 during startup
- Resolved notification issues on background mode

Enter fullscreen mode Exit fullscreen mode

This file is used by Fastlane to add release notes to the TestFlight build.

πŸš€ Run the Lane

From the project’s ios directory, trigger your automated build and upload:

fastlane build_and_upload

Enter fullscreen mode Exit fullscreen mode

Fastlane will:

  • Build your iOS app.
  • Export the .ipa.
  • Upload it to TestFlight.
  • Attach your release notes.

πŸ’‘ Final Tips

  • πŸ” Keep .env out of version control by adding it to .gitignore.
  • βš™οΈ Automate the entire flow with CI/CD tools like GitHub Actions or Bitrise.
  • 🧼 Use Fastlane actions like clean_build_artifacts or clear_derived_data for a fresh build.
  • πŸ§ͺ Use --verbose flag for debugging when something goes wrong.

🎯 Wrapping Up

By automating your iOS builds and TestFlight uploads with Fastlane, you're saving time, reducing human error, and improving consistency across release cycles.

This setup is a great follow-up to the iOS Fastlane flow, making your entire React Native deployment process fully automated.

Top comments (1)

Collapse
 
fred_functional profile image
Fred Functional

Great guide! Automating iOS uploads with Fastlane is a huge time saver. Has anyone tried different Fastlane plugins or run into issues with CI/CD integration? Would love to hear your tips and experiences!