🚀 Supercharge Your React Native Deployment with Fastlane
We are in the process of crafting a pipeline for both native applications, which will invoke the fastFile function to initiate a build. You can configure your fastFile for iOS using the provided link, and for Android with its respective link.
IOS Pipeline
Imagine you’re about to deploy an iOS application. Triggering a pipeline in this scenario requires two inputs and a manual intervention. This is crucial because building for iOS incurs significant costs, making it essential to manage the process carefully.
name: IOS Continuous Deployment - Stagging
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to deploy'
required: true
default: 'stage'
BUILD_NUMBER:
description: 'Enter Build Number '
required: true
VERSION_NAME:
description: 'Enter Version Number'
required: true
To deploy, specify the branch, build number, and version name. Alternatively, you can write a script to fetch this data directly from the App Store.
The prerequisite environments are presumably
env:
CI: true
GHP_TOKEN: ${{ secrets.GHP_TOKEN }}
APP_CONNECT_AUTH : ${{ secrets.APP_CONNECT_AUTH }}
MATCH_PASSWORD: "mobile development"
The prerequisite dependencies required for iOS builds include:
- xcodebuild
- NodeJS
- Fastlane
- CocoaPods
jobs:
build:
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch }}
- name: Check Xcode version
run: xcodebuild -version
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18.19.1'
- name: Install Fastlane
run: gem install fastlane
- name: Install CocoaPods
run: brew install cocoapods
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
Now lets write the app dependency installation process and start app getting started process.
- name: Create .env file
run: |
echo "${{ secrets.ENVS }}" > .env
- name: Install npm dependencies
run: npm ci
- name: Install Pods
run: pod install
working-directory: ./ios
- name: Add AuthKey.json
run: echo "${{ secrets.APP_CONNECT_AUTH }}" > key.p8
- name: Run Fastlane beta
run: fastlane beta --verbose
env:
API_KEY_PATH: ${{ format('{0}/key.p8', github.workspace) }}
BUILD_NUMBER: ${{ github.event.inputs.BUILD_NUMBER }}
VERSION_NAME: ${{ github.event.inputs.VERSION_NAME }}
working-directory: ./ios
From the code snippets provided, it’s evident that I prefer to store my environmental variables in a single GitHub secret. If you know of a better method to retrieve and load environmental variables, feel free to implement that process. This approach is somewhat subjective.
Additionally, for Fastlane authentication, a .p8 file is required, which can be obtained from Users And Access -> Integrations -> App Connect keys. In the subsequent steps of the Fastlane beta process, as illustrated, I convert the key obtained from secrets into a file named key.p8. This file’s absolute path is then used in the Fastlane process.
The remaining steps are quite straightforward. I hope this has been useful in your journey of creating a CD pipeline for React Native (IOS).
Android IOS :
Now lets talk about writing a CD for android that will trigger yoru fastlane build, setting up fastlane build is on this article. Moving on, lets talk writing the pipleline for it. Lets start with the prerequsites.
- NodeJS
- FastLane
- JDK
Lets write a pipleline that runs on ubuntu-latest And download these dependencies.
name: Android Continuous Deployment - Stage
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to deploy'
required: true
default: 'stage'
env:
CI: true
ANDROID_JSON_DATA: ${{ secrets.ANDROID_JSON_DATA }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch }}
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18.19.1' # Specify the Node.js version you need
- name: Install Fastlane
run: sudo gem install fastlane -NV
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
Let’s discuss the basic requirement, which is environmental variables. You can easily retrieve your environmental variables from GitHub secrets and load them into the environment.
- name: Create .env file
run: |
echo “${{ secrets.ENVS }}” > .env
- name: Load .env file
run: |
export $(xargs < .env)
Next, we might need a keystore, which is a requirement. Since they are usually encrypted, my plan is to convert the keystore into base64.
base64 -i path/to/keystore -o key.txt
You can then upload this base64-encoded file into Secrets with ease. During the pipeline execution, you need to retrieve it and save it in the Android folder.
- name: Write Keystore
run: echo “${{ secrets.KEYSTORE }}” | base64 — decode > ./android/app/app.keystore
You might have some variables that your keystore requires, so you would perform that step like this:
- name: Set up Gradle properties
run: |
echo “APP_UPLOAD_STORE_FILE=${{ secrets.APP_UPLOAD_STORE_FILE }}” >> ./gradle.properties
working-directory: ./android
With that completed, let’s address the inputs we did for iOS. To update the build_number and version_name, we would proceed as follows:
- name: Set GEM_HOME and install plugins
run: |
echo ‘GEM_HOME=$HOME/.gem’ >> $GITHUB_ENV
gem install fastlane-plugin-android_versioning — user-install
gem install fastlane-plugin-increment_version_code — user-install
working-directory: ./android
And finally, just execute the steps like this:
- name: Run Fastlane beta
run: fastlane beta — verbose
working-directory: ./android
To learn how to write a Fastlane beta function, it is quite straightforward. Simply read more on the topic.