Tutorial - React Native and 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.
Create React Native app
Generate a sample project with the react-native-cli.
npx react-native@0.73.6 init --package-name PACKAGE_NAME APP_NAMEPassing
--package-name PACKAGE_NAMEensures a unique Bundle ID for the application.PACKAGE_NAMEshould 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_NAMEis the name of your application, it must be alphanumeric and less than 30 characters.Answer the necessary prompts.
iOS simulator
Change to the application directory
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
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.
Open
ios/APP_NAME.xcodeprojin Xcode, and then select Images and AppIcon.
App icons Generate a set of icons with a service like appicon.co, and then drag each generated icon into the appropriate location.
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.
Follow the setup guide to configure Fastlane in your app's
iosdirectory. When runningfastlane init, choose the "Manual setup" option. This creates afastlanedirectory with two files:AppfileandFastfile.
Appfile
At a minimum, you must set
app_identifierandapple_idinfastlane/Appfile.app_identifieris the Bundle ID of the app (referred to asPACKAGE_NAMEin theinitcommand in Create React Native app).apple_idis 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:
If you have different credentials for App Store Connect and the Apple Developer, you must set
team_idanditc_team_id.Go to Fastlane's Appfile documentation for details on writing this file for your App Store Connect account.
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.
Follow the setup guide to configure match in your app project's
iosdirectory. This creates thefastlane/Matchfilefile.
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_PASSWORDcontaining this password in your project.Commit and push all changes to your Git repository.
App Store Connect API Key
Follow Apple's documentation to Create API Keys for App Store Connect API to create a Team Key. An Individual Key won't work.
Store the Issuer ID as a text secret named
APPLE_API_KEY_ISSUER_IDin your project.Store the Key ID as a text secret named
APPLE_API_KEY_IDin your project.
The API key itself is a file, so it must be base64 encoded before it can be stored as a secret.
Save the API key to a file (such as
api-key.p8), and then encode it using your terminal. For example:Save the encoded string as a text secret named
APPLE_API_KEY_CONTENTin 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.
Add a lane to run an action that loads the Apple Store Connect API key information:
Add a lane to run the match action:
Add a lane to run the deliver action to upload the app to TestFlight:
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_NAMEandPACKAGE_NAMEwith the values from the init command.Replace
TEAM_IDwith your App Store Connect team ID.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_NAMEwith the value from the init command.Commit and push all changes to your Git repository.
Create Harness pipeline
In your Harness account, select a Harness project, then select the Continuous Integration module.
Use the Get Started wizard to connect your Git provider, activate your iOS app repository, and create an initial pipeline.
Add security scans stage
Add a Build stage to your pipeline named
Security.On the stage Infrastructure tab, select the Harness CI Cloud Linux platform.
Switch to the YAML editor using the switch at the top of the Pipeline Studio.
In the pipeline YAML editor, add a
Runstep namedNPM Install:
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.
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.
Install jest-junit.
Edit the file
jest.config.js.Run the tests again.
The tests generate a
junit.xmlfile that Harness can ingest.Optionally, you can optionally add
junit.xmlto your repository's.gitignorefile.There is no need to check this file into your repository, since it is automatically generated.
Commit and push all changes to your Git repository.
Build stage
Add a Build stage to your pipeline named
Build.On the stage Infrastructure tab, select the Harness CI Cloud macOS platform.
Switch to the YAML editor using the switch at the top of the Pipeline Studio.
In the pipeline YAML editor, add a
Runstep namedRun NPM Tests.Add a
Runstep namedInstall Build Dependencies.Add a
Runstep namedBuild.Replace
APPLE_ID_USERNAMEwith your Apple ID username.
Trigger pipeline
Save and run the pipeline.
Observe the build logs while the pipeline runs.
Here's an example of the Security Scans stage execution:

Security scans stage And this is an example of the Build stage execution:

Build stage When complete, Fastlane prints a success message:
To see your published build:
Login to
https://appstoreconnect.apple.com.Select Apps.
Select your app from the list.
Select the TestFlight tab.
Your app's build appears in the list.
Next steps
Learn about TestFlight, and install your app on your iOS devices.
Invite testers to try your app on their devices.
Learn how to submit your app for review.
Last updated
Was this helpful?