Skip to content

Commit

Permalink
Creating a GitHub action installing Realm JS with the latest versions (
Browse files Browse the repository at this point in the history
…realm#3444)

* Create latest-install-test-react-native.yml

* Moved test harness to seperate files

* Adding a trigger on push events

* Ignoring the install-test's app directory

* Incorporating feedback

* Using pinned versions of XCode

* Correcting path for the scripts

* Working around a RN CLI issue

* Installing with --force

This is to avoid peerDependencies failures.

* Update listen.js

* Trying out an older macos runner

* Update install-test-react-native.yml

* Renamed run script and pre-booting simulator

* Reverted change to use older MacOS nodes

* Pre-lunching simulator and relaunching app on CI

* Trying to retry

* Enabling ccache + seperated building and running

* Making xcodebuild more quiet

* Update run-ios.sh

* Adding ccache to PATH

* Update run-ios.sh

* Update run-ios.sh
  • Loading branch information
kraenhansen committed Nov 17, 2021
1 parent ba0a232 commit 8bc792c
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/install-test-react-native.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Install test (React Native)

on:
# Any change to these files
push:
paths:
- install-tests/react-native/**
- .github/workflows/install-test-react-native.yml
# Every day at 9:00 CET
schedule:
- cron: "0 8 * * *"
# You can also activate this workflow manually from the Actions tab
workflow_dispatch:
inputs:
react-native-version:
description: The version of React Native to install
required: true
default: next
realm-version:
description: The version of Realm to install
required: true
default: latest

defaults:
run:
working-directory: install-tests/react-native

jobs:
install:
name: Installing Realm → React Native (using Xcode v${{matrix.xcode}}, node v${{ matrix.node }}, npm v${{ matrix.npm }})
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
# See https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md#xcode
xcode:
# - 12.5
- 13.1
npm:
- 7
node:
- 14
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: Install npm v7
run: npm install -g npm@7
- name: ccache
uses: hendrikmuhs/ccache-action@v1
with:
key: install-test
- name: Prepend ccache executables to the PATH
run: echo PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" >> $GITHUB_ENV
- name: Install React Native & Realm
run: ./install.sh ${{ github.event.inputs.react-native-version }} ${{ github.event.inputs.realm-version }}
- name: Invoke the simulator (making subsequent "open -a Simulator" calls work)
run: open -a ${{ env.DEVELOPER_DIR }}/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator
- name: Run test (iOS)
run: ./run-ios.sh
# - name: Run test (Android)
# uses: reactivecircus/android-emulator-runner@v2
# with:
# api-level: 29
# target: google_apis
# script: ./run-android.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ crash.log
examples/ReactExample/ios/Pods/
examples/ReactExample/ios/ReactExample.xcworkspace/
tests/mongodb-realm
install-tests/react-native/app/

# Integration tests
integration-tests/environments/electron/dist/
Expand Down
6 changes: 6 additions & 0 deletions install-tests/react-native/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": [
"@react-native-community",
"../../.eslintrc"
]
}
57 changes: 57 additions & 0 deletions install-tests/react-native/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2021 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http:https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////

import { useEffect } from "react";
import Realm from "realm";

const CALLBACK_HOST = "http:https://localhost:3000";
const DELAY = 5000;
const schema = [{ name: "Person", properties: { name: "string" } }];
const App = () => {
useEffect(() => {
const realm = new Realm({ schema });
// Write persons into the database
if (realm.empty) {
realm.write(() => {
realm.create("Person", { name: "Alice" });
realm.create("Person", { name: "Bob" });
realm.create("Person", { name: "Charlie" });
});
}
// Read the persons out of the database again
const message =
"Persons are " +
realm
.objects("Person")
.map((p) => p.name)
.join(", ");
console.log(`Sending '${message}'`);
// Perform a request to signal a successful write & read
setTimeout(() => {
fetch(CALLBACK_HOST, {
method: "POST",
body: message,
}).catch(console.error);
}, DELAY);
// Close the Realm when component unmounts
return () => realm.close();
}, []);
return null;
};

export default App;
27 changes: 27 additions & 0 deletions install-tests/react-native/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

set -e

react_native_version="${1:-next}"
realm_version="${2:-latest}"

echo "Using React Native version = $react_native_version"
echo "Using Realm version = $realm_version"

APP_DIR="$PWD/`dirname $0`/app"

# Manually delete any previously created app
if [ -d "$APP_DIR" ]; then
echo "Found an existing app directory: Skipping React Native init"
else
# Create a new React Native app using the desired version
npx --yes react-native@$react_native_version init ReactNativeTestApp --version $react_native_version --directory $APP_DIR --npm
fi

cd $APP_DIR
# Install CLI tools and Realm (using --force to ignore potential peerDependencies failures)
npm install ios-simulator concurrently retry-cli pod-install realm@$realm_version --force
# Run pod-install again
npx pod-install
# Overwrite the App.js
cp ../App.js .
45 changes: 45 additions & 0 deletions install-tests/react-native/listen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2021 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http:https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////

const { createServer } = require("http");

const TIMEOUT = 5 * 60 * 1000; // 5 minutes (although it shouldn't really take more than a minute)
const PORT = 3000;
const EXPECTED_MESSAGE = "Persons are Alice, Bob, Charlie";

createServer((req, res) => {
console.log("Client connected");
req.on("data", (data) => {
const message = data.toString("utf-8");
res.statusCode = 200;
res.end();
console.log(`App sent "${message}"!`);
if (message === EXPECTED_MESSAGE) {
console.log("This was expected!");
process.exit(0);
} else {
console.log(`This was unexpected! (expected ${EXPECTED_MESSAGE})`);
process.exit(1);
}
});
}).listen(PORT);

setTimeout(() => {
console.log("It took too long for the app to send the message");
process.exit(1);
}, TIMEOUT);
4 changes: 4 additions & 0 deletions install-tests/react-native/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "empty-package-to-avoid-react-native-cli-confusions",
"see": "https://github.com/react-native-community/cli/issues/1493"
}
42 changes: 42 additions & 0 deletions install-tests/react-native/run-ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

set -e

APP_DIR="$PWD/`dirname $0`/app"
PROJECT_ROOT=$APP_DIR/../../..

# Manually delete any app previously created
if [ ! -d "$APP_DIR" ]; then
echo "Couldn't locate an app directory, did you run install.sh?"
exit 1
fi

# Determine the simulator's UDID
DEVICE_UDID=`npx ios-simulator -n 'iPhone 13'`
# Open the simulator
open -a Simulator --args -CurrentDeviceUDID $DEVICE_UDID
# Await the boot of the device
xcrun simctl bootstatus $DEVICE_UDID

cd $APP_DIR

# Build the app (ccache enabled)
RCT_NO_LAUNCH_PACKAGER=1 xcodebuild \
-workspace ios/ReactNativeTestApp.xcworkspace \
-configuration Debug \
-scheme ReactNativeTestApp \
-derivedDataPath ./build \
-destination id=$DEVICE_UDID \
CC="$PROJECT_ROOT/scripts/ccache-clang.sh" \
CXX="$PROJECT_ROOT/scripts/ccache-clang++.sh"

# Install the app onto the device
APP_BUNDLE_ID=org.reactjs.native.example.ReactNativeTestApp
APP_BUILD_PATH=./build/Build/Products/Debug-iphonesimulator/ReactNativeTestApp.app
xcrun simctl install $DEVICE_UDID $APP_BUILD_PATH

# Run the app: Starting the listening server, Metro bundler and delayed launch of the app.
npx concurrently --kill-others --success "first" --names "listen,metro,app" \
"node ../listen.js" \
"react-native start" \
"sleep 5; xcrun simctl launch --console-pty $DEVICE_UDID $APP_BUNDLE_ID"

0 comments on commit 8bc792c

Please sign in to comment.