Skip to content

Build & Deploy

Build & Deploy #51

Workflow file for this run

# 🔗 Links:
# Source file: https://github.com/rootstrap/react-native-template/blob/master/.github/workflows/eas-build.yml
# EAS Build docs: https://docs.expo.dev/eas-update/github-actions/
# ✍️ Description:
# This workflow is used to trigger a build on EAS.
# Can be triggered manually from the actions tab.
# This action accepts those inputs:
# `environment`, which is used to generate a build for a specific environment (development, staging, QA, production). We use staging by default.
# `android`, true by default, set to true if you don't want to trigger build for Android.
# `ios`, false by default, set to true if you want to trigger build for IOS.
# Before triggering the build, we run a pre-build script to generate the necessary native folders based on the APP_ENV.
# Based on the ANDROID and IOS inputs, we trigger the build for the corresponding platform with the corresponding flags.
# 🚨 GITHUB SECRETS REQUIRED:
# - EXPO_TOKEN: Expo token to authenticate with EAS to sync version numbers and submit the build.
# You can get it from https://expo.dev/settings/access-tokens
# - NEW_VERSION_NUMBER_PAT: A fine-grained Personal Access Token.
# This token is used to commit and push to protected branches.
# You can generate one from here: https://github.com/settings/tokens?type=beta
# Set the token name to something meaningful, e.g. "New version number PAT for <Project name>".
# Set the Repository access to "Only select repositories" and select this repository.
# Set the following Repo permissions:
# - Contents: Read & write (to commit and push)
# Make sure to add it to the repo secrets with the name NEW_VERSION_NUMBER_PAT:
# - Go to Repository Settings > Secrets and variables > Actions > New repository secret
# - Name: NEW_VERSION_NUMBER_PAT
# - Value: The Personal Access Token you created
name: 'EAS Build (Android & IOS) (EAS)'
on:
workflow_dispatch:
inputs:
environment:
type: choice
description: 'Environment'
required: true
default: 'staging'
options:
- development
- staging
- qa
- production
new-version:
type: string
description: 'New version (e.g. 1.0.0)'
android:
type: boolean
description: 'Build for Android'
required: true
default: true
ios:
type: boolean
description: 'Build for iOS'
required: true
default: true
jobs:
validate-new-version:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
if: inputs.new-version
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Node.js
if: inputs.new-version
uses: actions/setup-node@v4
with:
node-version: 20
- name: Validate new version
if: inputs.new-version
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
NEW_VERSION="${{ inputs.new-version }}"
echo "Current version: $CURRENT_VERSION"
echo "New version: $NEW_VERSION"
npx semver -r ">=$CURRENT_VERSION" "$NEW_VERSION" > /dev/null || (echo "❌ New version must be greater than or equal to current version ($CURRENT_VERSION)" && exit 1)
echo "✅ New version is valid"
build:
needs: validate-new-version
runs-on: ${{ matrix.os }}
permissions:
contents: write
environment: app-${{ inputs.environment }}
strategy:
fail-fast: false
matrix:
platform: [ios, android]
include:
- platform: ios
os: macos-latest
- platform: android
os: ubuntu-latest
steps:
- name: Check if all required secrets exist
run: |
if [ -z "${{ secrets.EXPO_TOKEN }}" ]; then
echo "You must provide an EXPO_TOKEN secret linked to this project's Expo account in this repo's secrets. Learn more: https://docs.expo.dev/eas-update/github-actions"
exit 1
fi
if [ -z "${{ secrets.NEW_VERSION_NUMBER_PAT }}" ]; then
echo "echo "NEW_VERSION_NUMBER_PAT secret not found. Please create a fine-grained Personal Access Token following the instructions in the workflow file.""
exit 1
fi
- name: 📦 Setup Expo and EAS
uses: expo/expo-github-action@v8
with:
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}
- name: 📦 Checkout project repo
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.NEW_VERSION_NUMBER_PAT }}
- name: 📦 Setup Node + PNPM + install deps
uses: ./.github/actions/setup-node-pnpm-install
- name: Create environment file
run: echo "${{ secrets.ENVIRONMENT_FILE }}" > .env.${{ inputs.environment }}
- name: Update version in package.json
if: inputs.new-version
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
if [ "$CURRENT_VERSION" == "${{inputs.new-version}}" ]; then
echo "Current version is already ${{ inputs.new-version }}, no need to update"
exit 0
fi
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
pnpm version ${{ inputs.new-version }} -m "chore: set app version to ${{ inputs.new-version }}"
- name: Setup latest version of Xcode
uses: maxim-lobanov/setup-xcode@v1
if: matrix.platform == 'ios'
with:
xcode-version: latest
- name: ⚙️ Run Prebuild
run: pnpm prebuild:${{ inputs.environment }}
- name: 📱 Run Build for ${{ matrix.platform }}
run: pnpm build:${{ inputs.environment }}:${{ matrix.platform }} --non-interactive --no-wait --message "Build ${{ inputs.environment }} for ${{ matrix.platform }}" --local
- name: 📦 Push changes to repository
if: inputs.new-version
run: |
git push || echo "Skipping push: version was already updated."
- name: Upload ${{ matrix.platform }} Build
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform }}-build-${{ inputs.environment }}
path: |
*.apk
*.aab
*.ipa