Scaffolding React Native boilerplate with CodePush and smart CI
I'm preparing a minimal React Native example integrated with CodePush plus a GitHub Actions workflow that detects native dependency changes by comparing package.json across commits. The pipeline conditionally runs either a CodePush JS bundle release or a full native binary build based on that detection. This includes package.json, App.js with CodePush wrapper, a detection script, and the workflow YAML using App Center CLI and secrets.
Below is a minimal React Native/CodePush boilerplate and a GitHub Actions workflow that will:
- Wrap your app with CodePush for OTA updates.
- On every push to
main, inspect package.json to see if any native dependencies changed.
- If no native deps changed, release a CodePush JS bundle.
- If native deps changed, force a native binary build (placeholder commands included).
You can adapt paths/commands to your preferred CI/CD stack.
package.json (excerpt)
{
"name": "MyRNCodePushApp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "react-native start",
"android": "react-native run-android",
"ios": "react-native run-ios",
"codepush:release:android": "appcenter codepush release-react -a $APPCENTER_OWNER/$APPCENTER_APP_ANDROID -d Production -t \"*\" --output-dir ./build/android",
"codepush:release:ios": "appcenter codepush release-react -a $APPCENTER_OWNER/$APPCENTER_APP_IOS -d Production -t \"*\" --plist-file ios/MyRNCodePushApp/Info.plist --output-dir ./build/ios",
"detect:native": "node scripts/detect-native-changes.js"
},
"dependencies": {
"react": "18.x",
"react-native": "0.72.x",
"react-native-code-push": "^8.0.0"
}
}
Add whatever other dependencies you need. react-native-code-push is required.
App.js (wrap with CodePush)
import React from 'react';
import {SafeAreaView, Text} from 'react-native';
import CodePush from 'react-native-code-push';
// Configure how often to check for updates
const codePushOptions = {
checkFrequency: CodePush.CheckFrequency.ON_APP_START,
installMode: CodePush.InstallMode.ON_NEXT_RESTART,
mandatoryInstallMode: CodePush.InstallMode.IMMEDIATE
};
function App() {
return (
<SafeAreaView>
<Text>Hello from CodePush boilerplate!</Text>
</SafeAreaView>
);
}
// Wrap your root component
export default CodePush(codePushOptions)(App);
Ensure you’ve followed the react-native-code-push Android/iOS linking steps (or autolinking) and added the CodePush deployment keys in your native configs (Android strings.xml / iOS Info.plist).
scripts/detect-native-changes.js
This script compares the current package.json to the previous commit’s package.json and flags if any native dependencies have changed. You can adjust the heuristics to your needs.
#!/usr/bin/env node
const {execSync} = require('child_process');
const path = require('path');
const fs = require('fs');
const NATIVE_PATTERNS = [
/^react-native(-|$)/, // any react-native-* package
/^@react-native\//, // scoped RN packages
/^@expo\//, // expo-managed native libs
/^@shopify\//, // example of common native libs
/^@segment\//, // example of common native libs
/^@sentry\// // example of common native libs
];
// Load current and previous package.json
const currentPkgPath = path.join(__dirname, '..', 'package.json');
const currentPkg = JSON.parse(fs.readFileSync(currentPkgPath, 'utf-8'));
let prevPkg;
try {
const prevRaw = execSync('git show HEAD~1:package.json', {stdio: ['pipe', 'pipe', 'ignore']}).toString();
prevPkg = JSON.parse(prevRaw);
} catch (e) {
// No previous commit or package.json missing; force native rebuild
console.log('native_changed=true');
process.exit(0);
}
// Helper to gather deps
const collectDeps = pkg => ({...pkg.dependencies, ...pkg.devDependencies});
// Compare dependency sets
const currentDeps = collectDeps(currentPkg) || {};
const prevDeps = collectDeps(prevPkg) || {};
let nativeChanged = false;
const changes = [];
const allDeps = new Set([...Object.keys(currentDeps), ...Object.keys(prevDeps)]);
for (const dep of allDeps) {
const curVer = currentDeps[dep];
const prevVer = prevDeps[dep];
const isNative = NATIVE_PATTERNS.some(pattern => pattern.test(dep));
if (curVer !== prevVer && isNative) {
nativeChanged = true;
changes.push({dep, prevVer, curVer});
}
}
if (nativeChanged) {
console.log('Detected native dependency changes:', JSON.stringify(changes, null, 2));
// GitHub Actions output
console.log('native_changed=true');
} else {
console.log('native_changed=false');
}
The script writes native_changed=true|false to stdout so it can be captured as an output in GitHub Actions. Adjust NATIVE_PATTERNS or expand to include a manual allow/deny list as needed.
.github/workflows/release.yml
This GitHub Actions workflow triggers on pushes to main, detects native dep changes, and conditionally runs CodePush or a native build. It uses App Center CLI for CodePush.
name: Release
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install dependencies
run: npm install
- name: Detect native dependency changes
id: detect
run: |
npm run detect:native | tee detect.log
# Extract native_changed from script output
NATIVE_CHANGED=$(grep -oE "native_changed=(true|false)" detect.log | head -n1 | cut -d'=' -f2)
echo "native_changed=$NATIVE_CHANGED" >> $GITHUB_OUTPUT
- name: Show detection result
run: echo "Native dependencies changed? ${{ steps.detect.outputs.native_changed }}"
- name: Install App Center CLI
if: steps.detect.outputs.native_changed == 'false'
run: npm install -g appcenter-cli
- name: CodePush release (Android)
if: steps.detect.outputs.native_changed == 'false'
env:
APPCENTER_TOKEN: ${{ secrets.APPCENTER_TOKEN }}
APPCENTER_OWNER: ${{ secrets.APPCENTER_OWNER }}
APPCENTER_APP_ANDROID: ${{ secrets.APPCENTER_APP_ANDROID }}
run: |
appcenter login --token "$APPCENTER_TOKEN"
npm run codepush:release:android
- name: CodePush release (iOS)
if: steps.detect.outputs.native_changed == 'false'
env:
APPCENTER_TOKEN: ${{ secrets.APPCENTER_TOKEN }}
APPCENTER_OWNER: ${{ secrets.APPCENTER_OWNER }}
APPCENTER_APP_IOS: ${{ secrets.APPCENTER_APP_IOS }}
run: |
appcenter login --token "$APPCENTER_TOKEN"
npm run codepush:release:ios
- name: Native build & binary release
if: steps.detect.outputs.native_changed == 'true'
run: |
echo "Native dependencies changed. Running native build..."
# Insert your native build and store upload commands here
# Examples:
# cd android && ./gradlew assembleRelease
# cd ios && xcodebuild -workspace MyRNCodePushApp.xcworkspace -scheme MyRNCodePushApp -configuration Release -sdk iphoneos -derivedDataPath build
# fastlane ios deploy
# fastlane android deploy
Secrets you’ll need to set in GitHub:
• APPCENTER_TOKEN – App Center API token with CodePush permissions
• APPCENTER_OWNER – Org/user name in App Center
• APPCENTER_APP_ANDROID – owner/appName-Android for CodePush
• APPCENTER_APP_IOS – owner/appName-iOS for CodePush
If you prefer to split the pipeline into separate jobs (one to detect, one to CodePush, one to build native), you can move detection to its own job and pass the output as a dependency to the others.
Native setup notes
- Android: Add your
CODEPUSH_KEY in android/app/src/main/res/values/strings.xml, and in android/app/build.gradle add the CodePush config per the react-native-code-push docs.
- iOS: Add the deployment key in
Info.plist or via ReactNativeConfig, and include the CodePush package in AppDelegate (or rely on autolinking if supported by your RN version).
With this structure, pushes to main will automatically release a CodePush JS bundle unless native dependencies changed, in which case you’ll run the native build/upload steps. Adjust the detection logic and build steps as your project evolves.