diff --git a/.github/README.md b/.github/README.md new file mode 100644 index 000000000..b38a2cfe9 --- /dev/null +++ b/.github/README.md @@ -0,0 +1,22 @@ +# LaunchDarkly Github Actions for JavaScript SDKs. + +This directory contains Github Actions for building, deploying, releasing +libraries in this monorepo. + +## Local testing using act + +You can use [act](https://nektosact.com/usage/index.html) to run github actions locally for testing. + +1. Install and run Docker. +2. Install act. + +```shell +brew install act +``` + +3. Run a workflow file. + +```shell +# To run the react-native build/test/e2e +act -W '.github/workflows/react-native.yml' -P macos-14=-self-hosted +``` diff --git a/.github/workflows/react-native.yml b/.github/workflows/react-native.yml index 4a3a3fc8a..6f5422c27 100644 --- a/.github/workflows/react-native.yml +++ b/.github/workflows/react-native.yml @@ -14,11 +14,71 @@ jobs: build-test-react-native: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 - id: shared name: Shared CI Steps uses: ./actions/ci with: workspace_name: '@launchdarkly/react-native-client-sdk' workspace_path: packages/sdk/react-native + detox-ios: + # macos-latest uses macos-12 and we need macos-14 to get xcode 15. + # https://github.com/actions/runner-images/blob/main/README.md + runs-on: macos-14 + permissions: + id-token: write + contents: read + defaults: + run: + working-directory: packages/sdk/react-native/example + steps: + - uses: actions/checkout@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 + - name: Install deps + run: yarn workspaces focus + - name: Build + run: yarn workspaces foreach -pR --topological-dev --from 'react-native-example' run build + - name: Install macOS dependencies + run: | + brew tap wix/brew + brew install applesimutils + env: + HOMEBREW_NO_AUTO_UPDATE: 1 + HOMEBREW_NO_INSTALL_CLEANUP: 1 + + - name: Cache Detox build + id: cache-detox-build + uses: actions/cache@v4 + with: + path: ios/build + key: ${{ runner.os }}-detox-build + restore-keys: | + ${{ runner.os }}-detox-build + + - name: Detox rebuild framework cache + run: yarn detox rebuild-framework-cache + + - uses: ./actions/release-secrets + name: 'Get mobile key' + with: + aws_assume_role: ${{ vars.AWS_ROLE_ARN }} + ssm_parameter_pairs: '/sdk/detox/mobile-key = MOBILE_KEY' + + - name: Set mobile key + run: echo "MOBILE_KEY=$MOBILE_KEY" > .env + + - name: Expo prebuild + # HACK: Deleting ios/.xcode.env.local is needed to solve an xcode build issue with rn 0.73 + # https://github.com/facebook/react-native/issues/42112#issuecomment-1884536225 + run: | + export NO_FLIPPER=1 + yarn expo-prebuild + rm -rf ./ios/.xcode.env.local + + - name: Detox build + run: yarn detox build --configuration ios.sim.release + + - name: Detox test + run: yarn detox test --configuration ios.sim.release --cleanup --headless --record-logs all --take-screenshots failing diff --git a/packages/sdk/react-native/example/build-run-detox.sh b/packages/sdk/react-native/example/build-run-detox.sh index 58bb1c5b3..9434057ce 100755 --- a/packages/sdk/react-native/example/build-run-detox.sh +++ b/packages/sdk/react-native/example/build-run-detox.sh @@ -1,8 +1,13 @@ #!/bin/bash +export NO_FLIPPER=1 + echo "===== Installing all dependencies" yarn +echo "===== Rebuild detox cache" +yarn detox rebuild-framework-cache + echo "===== Building native code" yarn expo-prebuild @@ -12,11 +17,5 @@ yarn expo-prebuild echo "===== Delete .xcode.env.local" rm -rf ./ios/.xcode.env.local -echo "===== Start metro in background" -yarn start & - echo "===== Run ios tests" yarn detox-ios - -echo "===== Exit" -kill -9 $(lsof -t -i:8081) diff --git a/packages/sdk/react-native/example/package.json b/packages/sdk/react-native/example/package.json index a0f1a2d17..d9f4a7dfe 100644 --- a/packages/sdk/react-native/example/package.json +++ b/packages/sdk/react-native/example/package.json @@ -15,8 +15,8 @@ "ios-log": "react-native log-ios", "web": "expo start --web --clear", "clean": "yarn expo-prebuild && yarn cache clean && rm -rf node_modules && rm -rf .expo", - "detox-build-ios": "detox build -c ios.sim.debug", - "detox-run-ios": "detox test -c ios.sim.debug", + "detox-build-ios": "detox build -c ios.sim.release", + "detox-run-ios": "detox test -c ios.sim.release --cleanup --headless", "detox-ios": "yarn detox-build-ios && yarn detox-run-ios", "test": "./build-run-detox.sh" }, @@ -41,5 +41,9 @@ "jest": "^29.7.0", "ts-jest": "^29.1.1", "typescript": "^5.2.2" + }, + "packageManager": "yarn@3.4.1", + "installConfig": { + "hoistingLimits": "workspaces" } } diff --git a/packages/sdk/react-native/example/src/welcome.tsx b/packages/sdk/react-native/example/src/welcome.tsx index 8bcc28e57..f5447f65d 100644 --- a/packages/sdk/react-native/example/src/welcome.tsx +++ b/packages/sdk/react-native/example/src/welcome.tsx @@ -1,5 +1,5 @@ import { useState } from 'react'; -import { StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native'; +import { ScrollView, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native'; import { ConnectionMode } from '@launchdarkly/js-client-sdk-common'; import { useBoolVariation, useLDClient } from '@launchdarkly/react-native-client-sdk'; @@ -20,13 +20,17 @@ export default function Welcome() { ldc.setConnectionMode(m); }; + const context = ldc.getContext() ?? 'No context identified.'; + return ( Welcome to LaunchDarkly {flagKey}: {`${flagValue}`} - context: {JSON.stringify(ldc.getContext(), null, 2)} + + Logging: {JSON.stringify(context, null, 2)} +