Skip to content

Bash Script Example

Mark Glagola edited this page Feb 21, 2018 · 4 revisions

The following is a sequence of bash commands that, when executed in sequence, will automate your expo iOS and Android standalone app builds and deployments.

You can run this script on your local machine, or ideally, translate these commands to your continuous-integration/continuous-deployment service. This script is written to be ran in the same directory as your expo project.

This is meant to be a guide, so customize it to fit your automation needs!

Prerequisites / Notes

  • This example assumes you have exp and fastlane installed and understand how to use them.
  • Be conscious of env variables along the way.
  • If you decide to use fastlane, the fastlane deliver command will only work on macOS.

Example

#! /usr/bin/env bash

#### Script Setup ####
# Exptool will exit with non-zero statuses when a certain command fails.
# It's useful to exit the bash script when a command exits with a non-zero status
# as the following commands must be run successfully in sequence for expected results.
set -e # exit entire script when command exits with non-zero status

# Install dependencies
npm install

# [Optional] Login to expo using username & password
# You may or may not need to do this depending on your setup.
# Note the $EXPO_USERNAME and $EXPO_PASSWORD env variables
# exp login -u $EXPO_USERNAME -p $EXPO_PASSWORD --non-interactive

#### Publish to Expo ####
# Publish `production` release 
exp publish --release-channel production --non-interactive

#### Building Android Standalone App ####
# Makes sure that there are no active standalone app builds in progress.
# Will exit with a non-zero status code if there is an active standalone app build already in progress.
exptool check:status

# Start building standalone android build using `production` release channel
exp build:android --release-channel production --non-interactive

# Wait for the build to finish, checking its status every 2 mins (timeout is 20 mins)
# Will exit 0 (success) once the build has successfully been built
# Android builds take a little longer in my experience, hence the longer interval and timeout.
exptool wait:build --interval 120 --timeout 1200
 
# Download the artifact to current directory as `app.apk`
exptool download:artifact

#### Submit and publish standalone Android app to the Google Play Store ####
# Use fastlane to upload your current standalone android build
# Customize this to fit your needs. Take note of env variables. 
# Check out https://docs.fastlane.tools for more info.
fastlane supply --track 'production' --json_key '<path/to/json_key.json>' --package_name "$(exptool android:package)" --apk "app.apk" --skip_upload_metadata --skip_upload_images --skip_upload_screenshots

#### Building iOS Standalone App ####
# Makes sure that there are no active standalone app builds in progress.
# Will exit with a non-zero status code if there is an active standalone app build already in progress.
exptool check:status

# Start building standalone android build using `production` release channel
exp build:ios --release-channel production --non-interactive

# Wait for the build to finish, checking its status periodically
# Will exit 0 (success) once the build has successfully been built
exptool wait:build # using default interval & timeout

# Download the artifact to current directory as `app.ipa`
exptool download:artifact

#### Submit standalone iOS app to iTunes Connect ####
# Make sure the following env variables are set
# export DELIVER_USERNAME=<your-itunes-connect-email>
# export DELIVER_PASSWORD=<your-itunes-connect-password>

# Use fastlane to upload your current standalone iOS build to itc
fastlane deliver --verbose --ipa "app.ipa" --skip_screenshots --skip_metadata

#### Misc ####
# [Optional] You may or may not need to do this depending on your setup.
# exp logout