A CI/CD pipeline helps you build, test, and deliver your React Native app automatically. It saves time and reduces mistakes.
CI/CD pipeline setup in 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.apkThis example shows a simple GitHub Actions workflow for React Native.
Each step runs commands to build and test your app automatically.
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm install
- run: npm teston:
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm install
- run: npm testjobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm install
- run: npm run android-build
- run: npm run ios-buildThis 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.
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 assembleReleaseMake 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.
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.
Practice
Solution
Step 1: Understand CI/CD pipeline purpose
A CI/CD pipeline automates repetitive tasks like building and testing to save time and reduce errors.Step 2: Identify correct purpose for React Native
For React Native apps, CI/CD pipelines help automate building, testing, and deploying to catch errors early and deliver updates faster.Final Answer:
To automate building, testing, and deploying the app -> Option AQuick Check:
CI/CD = Automate build & deploy [OK]
- Thinking CI/CD is for manual testing
- Confusing CI/CD with coding speed
- Believing CI/CD increases app size
Solution
Step 1: Identify supported runners in GitHub Actions
GitHub Actions supports runners like ubuntu-latest, macos-latest, and windows-latest, but not outdated or invalid ones.Step 2: Choose the valid runner for React Native CI/CD
Using 'runs-on: ubuntu-latest' is common and valid for React Native workflows; others like windows-98 or android-5 are invalid or unsupported.Final Answer:
runs-on: ubuntu-latest -> Option AQuick Check:
Valid runner = ubuntu-latest [OK]
- Using outdated OS versions
- Specifying unsupported runners
- Confusing runner names with device names
npm run test step if tests fail?
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run testSolution
Step 1: Understand default behavior of GitHub Actions on command failure
If a command like 'npm run test' fails (returns non-zero exit code), GitHub Actions stops the job and marks it as failed by default.Step 2: Apply this to the given snippet
Since no special flags or error handling are used, test failures will stop the workflow and mark the job as failed.Final Answer:
The workflow stops and marks the job as failed -> Option BQuick Check:
Failed test = job fails [OK]
- Assuming workflow continues after test failure
- Thinking tests auto-retry without config
- Believing failed steps are skipped silently
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build app
run: npm run build
What is the most likely reason the build step is skipped?Solution
Step 1: Check required sections in GitHub Actions workflow
Every workflow file needs an 'on' section to specify when it runs (e.g., on push or pull request). Without it, the workflow never triggers.Step 2: Analyze given workflow
The workflow lacks the 'on' trigger, so GitHub Actions never starts the job and steps, causing the build step to be skipped.Final Answer:
The workflow file is missing the 'on' trigger section -> Option DQuick Check:
Missing 'on' = workflow never runs [OK]
- Thinking job names are restricted
- Assuming outdated actions block steps
- Believing npm build is invalid for React Native
Solution
Step 1: Identify trigger and branch conditions
The pipeline should trigger on pushes to the main branch only, so 'on: push: branches: - main' is correct.Step 2: Ensure tests run before deploy and deploy depends on test success
Job 'deploy' depends on 'test' job with 'needs: test' and runs only if tests succeed using 'if: success()'.Step 3: Verify steps in each job
'test' job installs dependencies and runs tests; 'deploy' job runs deployment commands after tests pass.Final Answer:
The workflow that runs tests on main branch push and deploys only if tests pass -> Option CQuick Check:
Test before deploy on main branch =on: push: branches: - main jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - run: npm install - run: npm run test deploy: needs: test runs-on: ubuntu-latest if: success() steps: - run: echo "Deploying app..."[OK]
- Deploying without waiting for tests
- Triggering on wrong branches
- Missing job dependencies
Ready to prove it?
Pass the test and this pattern moves unknown
