For the complete documentation index, see llms.txt. This page is also available as Markdown.

React Native & iOS Pipeline

Build and publish a React Native iOS app to TestFlight using Fastlane in Harness CI.

Harness CI Cloud offers Mac infrastructure that you can use to build, test, and publish iOS applications.

React Native is an open source UI framework from Meta. React Native enables developers to write natively-rendered Android and iOS applications in the React framework.

This tutorial covers how to build, test, and publish a React Native iOS app to Apple's TestFlight service with Fastlane.

Prerequisites

For this tutorial, you need the following:

  • A Harness account with Harness CI Cloud Mac infrastructure enabled.

  • Access to a Git provider.

  • An Apple account enrolled in the Apple Developer Program or admin access to App Store Connect for an existing account.

Currently, macOS platforms for Harness Cloud are behind a feature flag with limited availability. You can submit a request to enable the feature.

Create React Native app

Some of the steps demonstrated in this tutorial are also available in the React Native quickstart guide. More details are provided for those who are new to React Native.

  1. Generate a sample project with the react-native-cli.

    npx react-native@0.73.6 init --package-name PACKAGE_NAME APP_NAME

    Passing --package-name PACKAGE_NAME ensures a unique Bundle ID for the application. PACKAGE_NAME should be in reverse-DNS format.

    For example, since Apple owns apple.com, all Apple bundle IDs are prefixed with com.apple..

    Your app's bundle ID must be a uniform type identifier (UTI) and case insensitive.

    APP_NAME is the name of your application, it must be alphanumeric and less than 30 characters.

  2. Answer the necessary prompts.

iOS simulator

  1. Change to the application directory

  2. Run your app in the iOS Simulator.

The app takes a few minutes to build and install the app in the simulator.

Changes to the App.tsx file are immediately reflected in the simulator.

Git repository

  1. Create a new repository in your Git provider, and then commit and push the contents of your application.

App icons

This sample application won't have an app icon; however, an icon is required to submit the app to TestFlight.

  1. Open ios/APP_NAME.xcodeproj in Xcode, and then select Images and AppIcon.

  2. Generate a set of icons with a service like appicon.co, and then drag each generated icon into the appropriate location.

  3. Commit and push these changes to your Git repository.

Fastlane

Fastlane is a command line tool that helps automate beta deployments and releases for mobile applications.

  1. Follow the setup guide to configure Fastlane in your app's ios directory. When running fastlane init, choose the "Manual setup" option. This creates a fastlane directory with two files: Appfile and Fastfile.

Appfile

  1. At a minimum, you must set app_identifier and apple_id in fastlane/Appfile.

    app_identifier is the Bundle ID of the app (referred to as PACKAGE_NAME in the init command in Create React Native app).

    apple_id is the Apple email address used to authenticate when publishing the app.

    These values can be hard-coded or they can passed as environment variables, for example:

  2. If you have different credentials for App Store Connect and the Apple Developer, you must set team_id and itc_team_id.

    Go to Fastlane's Appfile documentation for details on writing this file for your App Store Connect account.

  3. Commit and push all changes to your Git repository.

Match

Fastlane has an action called match that makes it easier to share signing credentials across teams and to your Harness pipeline.

match creates the required certificates and provisioning profiles, and then stores them in a separate Git repository, Google Cloud storage, or Amazon S3 bucket. Every team member with access to the selected storage can use those credentials for code signing.

  1. Follow the setup guide to configure match in your app project's ios directory. This creates the fastlane/Matchfile file.

The next step requires Developer permissions in your App Store Connect account.

  1. When using a Git repository for storage, you are prompted for a password to encrypt all files in the repository. Securely store this password, and then create a Harness text secret named MATCH_PASSWORD containing this password in your project.

  2. Commit and push all changes to your Git repository.

App Store Connect API Key

  1. Follow Apple's documentation to Create API Keys for App Store Connect API to create a Team Key. An Individual Key won't work.

This step requires Admin permissions in your App Store Connect account.

  1. Store the Issuer ID as a text secret named APPLE_API_KEY_ISSUER_ID in your project.

  2. Store the Key ID as a text secret named APPLE_API_KEY_ID in your project.

The API key itself is a file, so it must be base64 encoded before it can be stored as a secret.

  1. Save the API key to a file (such as api-key.p8), and then encode it using your terminal. For example:

  2. Save the encoded string as a text secret named APPLE_API_KEY_CONTENT in your project.

Fastfile

The fastlane/Fastfile file stores the automation configuration that you can run with Fastlane. The file consists of lanes that define each step in your app's workflow.

In this example, you'll create lanes to build and sign the app, and then publish it to Apple's TestFlight service with a unique build number based on the Harness pipeline execution ID.

Your fastlane/Fastfile currently looks like this:

Modify this file to add lanes to the platform: ios section.

  1. Add a lane to run an action that loads the Apple Store Connect API key information:

  2. Add a lane to run the match action:

  3. Add a lane to run the deliver action to upload the app to TestFlight:

  4. Add a lane to run all lanes and publish the app to TestFlight. This lane uses the update_code_signing_settings, increment_build_number, and build_app actions.

    Replace instances of APP_NAME and PACKAGE_NAME with the values from the init command.

    Replace TEAM_ID with your App Store Connect team ID.

  5. Add a lane that builds, but doesn't publish, the app. You can use this lane in pull request pipelines to ensure the app can be built successfully.

    Replace instances of APP_NAME with the value from the init command.

  6. Commit and push all changes to your Git repository.

Create Harness pipeline

  1. In your Harness account, select a Harness project, then select the Continuous Integration module.

  2. Use the Get Started wizard to connect your Git provider, activate your iOS app repository, and create an initial pipeline.

Add security scans stage

  1. Add a Build stage to your pipeline named Security.

  2. On the stage Infrastructure tab, select the Harness CI Cloud Linux platform.

  3. Switch to the YAML editor using the switch at the top of the Pipeline Studio.

  4. In the pipeline YAML editor, add a Run step named NPM Install:

  5. Add parallel steps for Owasp and Gitleaks scans.

Add unit tests

You'll make some code changes related to unit tests. Your project will have a tests/App.test.tsx file with one Jest unit test.

  1. Run the tests from the root of your repository.

    You'll get the following output:

Harness supports test results that are in JUnit XML format, which is supported by jest-junit.

  1. Install jest-junit.

  2. Edit the file jest.config.js.

  3. Run the tests again.

    The tests generate a junit.xml file that Harness can ingest.

  4. Optionally, you can optionally add junit.xml to your repository's .gitignore file.

    There is no need to check this file into your repository, since it is automatically generated.

  5. Commit and push all changes to your Git repository.

Build stage

  1. Add a Build stage to your pipeline named Build.

  2. On the stage Infrastructure tab, select the Harness CI Cloud macOS platform.

  3. Switch to the YAML editor using the switch at the top of the Pipeline Studio.

  4. In the pipeline YAML editor, add a Run step named Run NPM Tests.

  5. Add a Run step named Install Build Dependencies.

  6. Add a Run step named Build.

    Replace APPLE_ID_USERNAME with your Apple ID username.

    You may need to pass additional match secrets.

    For example, if you are storing your certificates in Git, you will also need to pass MATCH_GIT_BASIC_AUTHORIZATION.

Trigger pipeline

  1. Save and run the pipeline.

  2. Observe the build logs while the pipeline runs.

    Here's an example of the Security Scans stage execution:

    And this is an example of the Build stage execution:

    When complete, Fastlane prints a success message:

  3. To see your published build:

    1. Login to https://appstoreconnect.apple.com.

    2. Select Apps.

    3. Select your app from the list.

    4. Select the TestFlight tab.

    5. Your app's build appears in the list.

Next steps

Last updated

Was this helpful?