Automating CodePush deploys with Fastlane

CodePush is a great service that allows you to update your React Native apps over the air without waiting on the user to update their app through the App Store or Google Play. CodePush is extremely configurable, and includes a CLI to configure and initialize deploys. Despite a simple command and some good defaults, there are lots of questions and parameters to remember, such as:

  • What track should I use (dev, staging, or production)?
  • What version of the app should this deploytarget (what could break by releasing this)?
  • Do I want to force-apply this update immediately and not wait until the next time the app resumes?

Why Automate?

A common thread exists between every software developer, regardless of experience. We’re all human, and humans make mistakes.

The best way to reduce the likelihood of a mistake is to automate as much as possible in your workflows and processes. In the React Native world, the best deploy-related tool we’ve found to do that is fastlane.

NOTE: If your impatient, and just want to see the full script we’re using, skip to the bottom of the page. For more detail on each piece, read on.

Create Codepush Lanes

We’ll start by creating our fastlane entry points, a lane called and a lane called .

The only job of those lanes is to pass an app name param to a private lane (think of these as private methods).

The Main Script

The main part of our script first checks to make sure there are no local git modifications, and wraps the built-in command with a nice confirmation message. This gives a user a chance to make sure everything is correct before continuing.

To keep things clean, we handle getting the correct CodePush environment and app version from other private lanes.

Select a Proper Codepush Environment

These private lanes handle fetching the available CodePush environments and prompting the user to select one. By default AppCenter will create a Staging and Production environment, but you can create as many as you’d like.

Select a Target App Version

This private lane will parse the current app version (it currently assumes iOS and Android are versioned in lockstep), and prompt the user for a target version.

Assuming the current app is version 1.3.0, selecting “All users” will apply the codepush update to every version. Selecting “most recent major” and “most recent minor” will target and respectively, and “Current” will target only. To make sure this is clear to the user, we show the version target in the select prompt.

That’s all folks!

Putting this all together, you now just have to run and , answer a few questions, and watch it 🚀!

Our script in action - Part 1
Our script in action — Part 2

Here’s the full script:

If you’d like help automating your React Native workflow, say hello! We’d love to hear from you.

More about:

Chris Ball

Chris is CTO at Echobind, a full-service agency specializing in custom web and mobile apps. When he’s not helping developers grow or creating amazing things for clients, you’re likely to find him playing music, cycling, or camping.