0
0
React Nativemobile~5 mins

CI/CD pipeline setup in React Native

Choose your learning style9 modes available
Introduction

A CI/CD pipeline helps you build, test, and deliver your React Native app automatically. It saves time and reduces mistakes.

When you want to automatically test your app after every code change.
When you want to build your app and create installable files without manual steps.
When you want to deliver app updates faster to testers or users.
When you want to catch errors early before releasing your app.
When you want to keep your app code quality high and consistent.
Syntax
React Native
name: Build_and_Deploy
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'
      - name: Install dependencies
        run: npm install
      - name: Run tests
        run: npm test
      - name: Build Android app
        run: cd android && ./gradlew assembleRelease
      - name: Upload artifact
        uses: actions/upload-artifact@v3
        with:
          name: app-build
          path: android/app/build/outputs/apk/release/app-release.apk

This example shows a simple GitHub Actions workflow for React Native.

Each step runs commands to build and test your app automatically.

Examples
This example runs tests on every push to the repository.
React Native
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: npm install
      - run: npm test
This example runs tests when someone creates a pull request.
React Native
on:
  pull_request:
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: npm install
      - run: npm test
This example builds both Android and iOS versions of the app.
React Native
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: npm install
      - run: npm run android-build
      - run: npm run ios-build
Sample App

This GitHub Actions workflow runs on every push to the main branch. It checks out the code, sets up Node.js, installs dependencies, runs tests, and builds the Android app.

React Native
name: ReactNative_CI_CD
on:
  push:
    branches:
      - main
jobs:
  build_and_test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'
      - name: Install dependencies
        run: npm install
      - name: Run tests
        run: npm test
      - name: Build Android app
        run: cd android && ./gradlew assembleRelease
OutputSuccess
Important Notes

Make sure your React Native project has test scripts defined in package.json.

Building iOS apps requires a macOS runner or a cloud service that supports macOS.

You can add steps to deploy your app to stores or testers after building.

Summary

CI/CD pipelines automate building, testing, and delivering your React Native app.

Use pipelines to catch errors early and save time.

GitHub Actions is one easy way to set up CI/CD for React Native projects.