Bundle, build and run iOS test app in separate steps in production + ccache enabled #1031
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Check | |
| env: | |
| CMAKE_VERSION: 4.1.2 | |
| # Version here should match the one in React Native template and packages/cmake-rn/src/cli.ts | |
| NDK_VERSION: 27.1.12297006 | |
| # Enabling the Gradle test on CI (disabled by default because it downloads a lot) | |
| ENABLE_GRADLE_TESTS: true | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| lint: | |
| name: Lint | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: lts/krypton | |
| - name: Setup cpp tools | |
| uses: aminya/setup-cpp@v1 | |
| with: | |
| clang-format: true | |
| - name: ccache | |
| uses: hendrikmuhs/[email protected] | |
| with: | |
| key: ${{ github.job }}-${{ runner.os }} | |
| # Set up JDK and Android SDK only because we need weak-node-api, to build ferric-example and to run the linting | |
| # TODO: Remove this once we have a way to run linting without building the native code | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: "17" | |
| distribution: "temurin" | |
| - name: Setup Android SDK | |
| uses: android-actions/setup-android@v3 | |
| with: | |
| packages: tools platform-tools ndk;${{ env.NDK_VERSION }} | |
| - run: rustup target add x86_64-linux-android | |
| - run: npm ci | |
| - run: npm run build | |
| # Bootstrap weak-node-api and ferric-example to get types | |
| # TODO: Solve this by adding an option to ferric to build only types or by committing the types into the repo as a fixture for an "init" command | |
| - run: npm run bootstrap --workspace weak-node-api | |
| - run: npm run bootstrap --workspace @react-native-node-api/ferric-example | |
| - run: npm run lint | |
| env: | |
| DEBUG: eslint:eslint | |
| - run: npm run prettier:check | |
| - run: npm run depcheck | |
| - run: npm run publint | |
| unit-tests: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| runner: | |
| - ubuntu-latest | |
| - windows-latest | |
| - macos-latest | |
| runs-on: ${{ matrix.runner }} | |
| name: Unit tests (${{ matrix.runner }}) | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: lts/krypton | |
| - name: Setup cpp tools | |
| uses: aminya/setup-cpp@v1 | |
| with: | |
| clang-format: true | |
| - name: ccache | |
| uses: hendrikmuhs/[email protected] | |
| with: | |
| key: ${{ github.job }}-${{ runner.os }} | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: "17" | |
| distribution: "temurin" | |
| - name: Setup Android SDK | |
| uses: android-actions/setup-android@v3 | |
| with: | |
| packages: tools platform-tools ndk;${{ env.NDK_VERSION }} | |
| - run: rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi i686-linux-android aarch64-apple-ios-sim | |
| - run: npm ci | |
| - run: npm run bootstrap | |
| - run: npm test | |
| weak-node-api-tests: | |
| if: github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'weak-node-api') | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| runner: | |
| - ubuntu-latest | |
| - windows-latest | |
| - macos-latest | |
| runs-on: ${{ matrix.runner }} | |
| name: Weak Node-API tests (${{ matrix.runner }}) | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: lts/krypton | |
| - name: Setup cpp tools | |
| uses: aminya/setup-cpp@v1 | |
| with: | |
| clang-format: true | |
| - name: ccache | |
| uses: hendrikmuhs/[email protected] | |
| with: | |
| key: ${{ github.job }}-${{ runner.os }} | |
| - run: npm ci | |
| - run: npm run build | |
| - name: Prepare weak-node-api | |
| run: npm run prebuild:prepare --workspace weak-node-api | |
| - name: Build and run weak-node-api C++ tests | |
| run: | | |
| cmake -S . -B build -DBUILD_TESTS=ON | |
| cmake --build build | |
| ctest --test-dir build --output-on-failure | |
| working-directory: packages/weak-node-api | |
| test-ios: | |
| if: github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Apple 🍎') | |
| name: Test app (iOS) | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: lts/krypton | |
| - name: Boot the simulator | |
| run: xcrun simctl boot 'iPhone 17' | |
| - name: Setup cpp tools | |
| uses: aminya/setup-cpp@v1 | |
| with: | |
| clang-format: true | |
| - name: ccache | |
| uses: hendrikmuhs/[email protected] | |
| with: | |
| key: ${{ github.job }}-${{ runner.os }} | |
| - run: rustup target add aarch64-apple-ios-sim | |
| - run: npm ci | |
| - run: npm run bootstrap | |
| env: | |
| CMAKE_RN_TRIPLETS: arm64;x86_64-apple-ios-sim | |
| FERRIC_TARGETS: aarch64-apple-ios-sim | |
| # Because the Xcode project injects its own CCACHE_CONFIGPATH, | |
| # the configuration set by the ccache action doesn't propagate. | |
| - name: Expose Ccache config to Xcode | |
| run: | | |
| echo "CCACHE_DIR=`ccache --get-config cache_dir`" >> $GITHUB_ENV | |
| echo "CCACHE_MAXSIZE=`ccache --get-config max_size`" >> $GITHUB_ENV | |
| echo "CCACHE_COMPILERCHECK=`ccache --get-config compiler_check`" >> $GITHUB_ENV | |
| - run: npm run pod-install | |
| working-directory: apps/test-app | |
| env: | |
| USE_CCACHE: 1 | |
| - name: Bundle test app | |
| run: npx react-native bundle --entry-file index.ts --platform ios --dev false --minify false --bundle-output dist/main.ios.jsbundle --assets-dest dist/res | |
| working-directory: apps/test-app | |
| - name: Build test app | |
| run: xcodebuild archive -workspace ReactTestApp.xcworkspace -configuration Release -scheme ReactTestApp -destination generic/platform="iOS" -archivePath ./build/test-app.xcarchive # | xcbeautify | |
| working-directory: apps/test-app/ios | |
| - uses: actions/upload-artifact@v6 | |
| with: | |
| name: test-app-build | |
| path: apps/test-app/ios/build/test-app.xcarchive | |
| - name: Run test app | |
| run: | | |
| # Install the app | |
| xcrun simctl install booted ./ios/build/test-app.xcarchive/Products/Applications/ReactTestApp.app | |
| # Run Mocha Remote wrapping the launch of the app | |
| npx mocha-remote --exit-on-error -- xcrun simctl launch --terminate-running-process --console-pty booted com.microsoft.ReactTestApp | |
| working-directory: apps/test-app | |
| env: | |
| MOCHA_REMOTE_CONTEXT: allTests | |
| test-macos: | |
| # Disabling this on main for now, as initializing the template takes a long time and | |
| # we don't have macOS-specific code yet | |
| if: contains(github.event.pull_request.labels.*.name, 'MacOS 💻') | |
| name: Test app (macOS) | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: lts/krypton | |
| - name: Setup cpp tools | |
| uses: aminya/setup-cpp@v1 | |
| with: | |
| clang-format: true | |
| - name: ccache | |
| uses: hendrikmuhs/[email protected] | |
| with: | |
| key: ${{ github.job }}-${{ runner.os }} | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: "17" | |
| distribution: "temurin" | |
| - name: Install compatible CMake version | |
| uses: jwlawson/actions-setup-cmake@v2 | |
| with: | |
| cmake-version: ${{ env.CMAKE_VERSION }} | |
| - run: rustup target add x86_64-apple-darwin | |
| - run: npm ci | |
| - run: npm run bootstrap | |
| env: | |
| CMAKE_RN_TRIPLETS: arm64;x86_64-apple-darwin | |
| FERRIC_TARGETS: aarch64-apple-darwin,x86_64-apple-darwin | |
| - run: npm run init-macos-test-app | |
| - run: pod install --project-directory=macos | |
| working-directory: apps/macos-test-app | |
| - name: Bundle test app | |
| run: npx react-native bundle --entry-file index.js --platform macos --dev false --minify false --bundle-output dist/main.macos.jsbundle --assets-dest dist/res | |
| working-directory: apps/macos-test-app | |
| - name: Build test app | |
| run: xcodebuild archive -workspace MacOSTestApp.xcworkspace -configuration Release -scheme MacOSTestApp-macOS -destination generic/platform="macOS" -archivePath ./build/macos-test-app.xcarchive | xcbeautify | |
| working-directory: apps/macos-test-app/macos | |
| - name: Run test app | |
| run: npx mocha-remote --exit-on-error -- macos/build/macos-test-app.xcarchive/Products/Applications/MacOSTestApp.app/Contents/MacOS/MacOSTestApp | |
| working-directory: apps/macos-test-app | |
| env: | |
| MOCHA_REMOTE_CONTEXT: allTests | |
| test-android: | |
| if: github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Android 🤖') | |
| name: Test app (Android) | |
| runs-on: ubuntu-self-hosted | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: lts/krypton | |
| - name: Setup cpp tools | |
| uses: aminya/setup-cpp@v1 | |
| with: | |
| clang-format: true | |
| - name: ccache | |
| uses: hendrikmuhs/[email protected] | |
| with: | |
| key: ${{ github.job }}-${{ runner.os }} | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: "17" | |
| distribution: "temurin" | |
| - name: Setup Android SDK | |
| uses: android-actions/setup-android@v3 | |
| with: | |
| packages: tools platform-tools ndk;${{ env.NDK_VERSION }} cmake;${{ env.CMAKE_VERSION }} | |
| - run: rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi i686-linux-android aarch64-apple-ios-sim | |
| - run: npm ci | |
| - run: npm run bootstrap | |
| env: | |
| CMAKE_RN_TRIPLETS: x86_64-linux-android | |
| FERRIC_TARGETS: x86_64-linux-android | |
| - name: Clone patched Hermes version | |
| shell: bash | |
| run: | | |
| REACT_NATIVE_OVERRIDE_HERMES_DIR=$(npx react-native-node-api vendor-hermes --silent) | |
| echo "REACT_NATIVE_OVERRIDE_HERMES_DIR=$REACT_NATIVE_OVERRIDE_HERMES_DIR" >> $GITHUB_ENV | |
| working-directory: apps/test-app | |
| # - name: Setup Android Emulator cache | |
| # uses: actions/cache@v4 | |
| # id: avd-cache | |
| # with: | |
| # path: | | |
| # ~/.android/avd/* | |
| # ~/.android/adb* | |
| # key: ${{ runner.os }}-avd-29 | |
| # See https://github.com/marketplace/actions/android-emulator-runner#running-hardware-accelerated-emulators-on-linux-runners | |
| - name: Enable KVM group perms | |
| run: | | |
| echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules | |
| sudo udevadm control --reload-rules | |
| sudo udevadm trigger --name-match=kvm | |
| - name: Build weak-node-api for all Android architectures | |
| run: npm run prebuild:build:android --workspace weak-node-api | |
| - name: Build ferric-example for all architectures | |
| run: npm run build -- --android | |
| working-directory: packages/ferric-example | |
| - name: Run tests (Android) | |
| timeout-minutes: 75 | |
| uses: reactivecircus/android-emulator-runner@v2 | |
| with: | |
| api-level: 29 | |
| force-avd-creation: false | |
| disable-animations: true | |
| arch: x86_64 | |
| ndk: ${{ env.NDK_VERSION }} | |
| cmake: 3.22.1 | |
| working-directory: apps/test-app | |
| script: | | |
| # Setup port forwarding to Mocha Remote | |
| adb reverse tcp:8090 tcp:8090 | |
| # Uninstall the app if already in the snapshot (unlikely but could result in a signature mismatch failure) | |
| adb uninstall com.microsoft.reacttestapp || true | |
| # Start logcat in background and save logs | |
| adb logcat > emulator-logcat.txt 2>&1 & | |
| LOGCAT_PID=$! | |
| # Build, install and run the app | |
| npm run test:android:allTests -- --mode Release | |
| # Wait a bit for the sub-process to terminate, before terminating the emulator | |
| sleep 5 | |
| # Stop logcat | |
| kill $LOGCAT_PID || true | |
| - name: Upload device logs | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: emulator-logcat | |
| path: apps/test-app/emulator-logcat.txt | |
| test-ferric-apple-triplets: | |
| if: github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Ferric 🦀') | |
| name: Test ferric Apple triplets | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: lts/krypton | |
| - name: Setup cpp tools | |
| uses: aminya/setup-cpp@v1 | |
| with: | |
| clang-format: true | |
| - name: ccache | |
| uses: hendrikmuhs/[email protected] | |
| with: | |
| key: ${{ github.job }}-${{ runner.os }} | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: "17" | |
| distribution: "temurin" | |
| - run: rustup target add x86_64-apple-darwin x86_64-apple-ios aarch64-apple-ios aarch64-apple-ios-sim | |
| - run: rustup toolchain install nightly --component rust-src | |
| - run: npm ci | |
| - run: npm run build | |
| - name: Build weak-node-api for all Apple architectures | |
| run: | | |
| npm run prebuild:prepare --workspace weak-node-api | |
| npm run prebuild:build:apple --workspace weak-node-api | |
| # Build Ferric example for all Apple architectures | |
| - run: npx ferric --apple | |
| working-directory: packages/ferric-example | |
| - name: Inspect the structure of the prebuilt binary | |
| run: lipo -info ferric_example.apple.node/*/libferric_example.framework/libferric_example > lipo-info.txt | |
| working-directory: packages/ferric-example | |
| - name: Upload lipo info | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: lipo-info | |
| path: packages/ferric-example/lipo-info.txt | |
| - name: Verify Apple triplet builds | |
| run: | | |
| # Create expected fixture content | |
| cat > expected-lipo-info.txt << 'EOF' | |
| Architectures in the fat file: ferric_example.apple.node/ios-arm64_x86_64-simulator/libferric_example.framework/libferric_example are: x86_64 arm64 | |
| Architectures in the fat file: ferric_example.apple.node/macos-arm64_x86_64/libferric_example.framework/libferric_example are: x86_64 arm64 | |
| Architectures in the fat file: ferric_example.apple.node/tvos-arm64_x86_64-simulator/libferric_example.framework/libferric_example are: x86_64 arm64 | |
| Non-fat file: ferric_example.apple.node/ios-arm64/libferric_example.framework/libferric_example is architecture: arm64 | |
| Non-fat file: ferric_example.apple.node/tvos-arm64/libferric_example.framework/libferric_example is architecture: arm64 | |
| Non-fat file: ferric_example.apple.node/xros-arm64-simulator/libferric_example.framework/libferric_example is architecture: arm64 | |
| Non-fat file: ferric_example.apple.node/xros-arm64/libferric_example.framework/libferric_example is architecture: arm64 | |
| EOF | |
| # Compare with expected fixture (will fail if files differ) | |
| diff expected-lipo-info.txt lipo-info.txt | |
| working-directory: packages/ferric-example |