Skip to content

Commit

Permalink
chore: updated build tests to run on pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
avishayil committed Dec 23, 2023
1 parent 1b8a989 commit e7345c4
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 20 deletions.
13 changes: 5 additions & 8 deletions .github/workflows/main.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Main tests

on:
push:
branches:
- '**'
push:
branches:
- master

jobs:

Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
run: yarn lint

test:
runs-on: macos-latest
runs-on: ubuntu-latest
needs: setup
timeout-minutes: 5
steps:
Expand All @@ -103,7 +103,7 @@ jobs:
run: yarn test

build-android:
runs-on: macos-latest
runs-on: ubuntu-latest
needs: [setup]
timeout-minutes: 10
steps:
Expand Down Expand Up @@ -153,9 +153,6 @@ jobs:
with:
path: ./Example/ios/Pods
key: pods-${{ hashFiles('Example/ios/Podfile.lock') }}

- name: Select Xcode
run: sudo xcode-select -switch /Applications/Xcode_13.2.1.app

- name: Xcode Version
run: /usr/bin/xcodebuild -version
Expand Down
118 changes: 118 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Main tests

on:
pull_request:
branches:
- master

jobs:

setup:
name: Setup code and environment needed for building, linting and tests
runs-on: macos-latest
timeout-minutes: 15
steps:
- name: Check out Git repository
uses: actions/checkout@v3

- name: Set up Node environment
uses: actions/setup-node@v3
with:
node-version: 16

- name: Cache Java
uses: actions/setup-java@v3
with:
java-version: "11"
distribution: "adopt"
cache: "gradle"

# Workaround for https://github.com/actions/setup-java/issues/65
- name: Backup JAVA_HOME
id: java-home
run: echo "::set-output name=path::$JAVA_HOME"

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: Cache module node modules
uses: actions/cache@v3
id: cache-node-modules
with:
path: node_modules
key: yarn-${{ hashFiles('yarn.lock') }}

- name: Cache Example application node modules
uses: actions/cache@v3
id: cache-app-node-modules
with:
path: ./Example/node_modules
key: yarn-${{ hashFiles('Example/yarn.lock') }}

- name: Install node modules if cache not present
run: yarn install --immutable
if: steps.cache-node-modules.outputs.cache-hit != 'true'

- name: Install application node modules if cache not present
run: cd ./Example && yarn install --immutable
if: steps.cache-app-node-modules.outputs.cache-hit != 'true'

lint:
runs-on: ubuntu-latest
needs: setup
timeout-minutes: 5
steps:
- name: Check out Git repository
uses: actions/checkout@v3

- name: Restore node modules from cache
uses: actions/cache@v3
with:
path: node_modules
key: yarn-${{ hashFiles('yarn.lock') }}

- name: Lint
run: yarn lint

test:
runs-on: ubuntu-latest
needs: setup
timeout-minutes: 5
steps:
- name: Check out Git repository
uses: actions/checkout@v3

- name: Restore node modules from cache
uses: actions/cache@v3
with:
path: node_modules
key: yarn-${{ hashFiles('yarn.lock') }}

- name: Run tests
run: yarn test

build-android:
runs-on: ubuntu-latest
needs: [setup]
timeout-minutes: 10
steps:
- name: Check out Git repository
uses: actions/checkout@v3

- name: Restore node modules from cache
uses: actions/cache@v3
with:
path: node_modules
key: yarn-${{ hashFiles('yarn.lock') }}

- name: Restore application node modules from cache
uses: actions/cache@v3
with:
path: ./Example/node_modules
key: yarn-${{ hashFiles('Example/yarn.lock') }}

- name: Build example application
run: |
export JAVA_HOME=${{ steps.java-home.outputs.JAVA_HOME }}
cd ./Example/android
./gradlew assembleDebug
6 changes: 3 additions & 3 deletions Example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ PODS:
- React-jsinspector (0.72.4)
- React-logger (0.72.4):
- glog
- react-native-restart (0.0.27):
- react-native-restart (0.0.28):
- React-Core
- React-NativeModulesApple (0.72.4):
- hermes-engine
Expand Down Expand Up @@ -692,7 +692,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: c7f826e40fa9cab5d37cab6130b1af237332b594
React-jsinspector: aaed4cf551c4a1c98092436518c2d267b13a673f
React-logger: da1ebe05ae06eb6db4b162202faeafac4b435e77
react-native-restart: 7595693413fe3ca15893702f2c8306c62a708162
react-native-restart: 4494134396cf409d59756275240717c5512197aa
React-NativeModulesApple: edb5ace14f73f4969df6e7b1f3e41bef0012740f
React-perflogger: 496a1a3dc6737f964107cb3ddae7f9e265ddda58
React-RCTActionSheet: 02904b932b50e680f4e26e7a686b33ebf7ef3c00
Expand All @@ -716,4 +716,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: c0a554845235370ca817f4812ef52dbc3a36d89b

COCOAPODS: 1.11.3
COCOAPODS: 1.14.2
23 changes: 19 additions & 4 deletions android/src/main/java/com/reactnativerestart/RestartModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.jakewharton.processphoenix.ProcessPhoenix;
import com.facebook.react.bridge.Promise;


public class RestartModule extends ReactContextBaseJavaModule {

private static final String REACT_APPLICATION_CLASS_NAME = "com.facebook.react.ReactApplication";
private static final String REACT_NATIVE_HOST_CLASS_NAME = "com.facebook.react.ReactNativeHost";
private static String restartReason = null;

private LifecycleEventListener mLifecycleEventListener = null;

Expand Down Expand Up @@ -95,14 +98,26 @@ private void clearLifecycleEventListener() {
}

@ReactMethod
public void Restart() {
ProcessPhoenix.triggerRebirth(getReactApplicationContext());
public void Restart(String reason) {
restartReason = reason;
loadBundle();
}

@ReactMethod
public void restart() {
ProcessPhoenix.triggerRebirth(getReactApplicationContext());
public void restart(String reason) {
restartReason = reason;
loadBundle();
}

@ReactMethod
public void getReason(Promise promise) {
try {
promise.resolve(restartReason);
} catch(Exception e) {
promise.reject("Create Event Error", e);
}
}


@Override
public String getName() {
Expand Down
7 changes: 5 additions & 2 deletions ios/Restart.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
@implementation Restart

RCT_EXPORT_MODULE(RNRestart)
NSString *restartReason = nil;

- (void)loadBundle
{
RCTTriggerReloadCommandListeners(@"react-native-restart: Restart");
}

RCT_EXPORT_METHOD(Restart) {
RCT_EXPORT_METHOD(Restart: (NSString *)reason) {
restartReason = reason;
if ([NSThread isMainThread]) {
[self loadBundle];
} else {
Expand All @@ -20,7 +22,8 @@ - (void)loadBundle
return;
}

RCT_EXPORT_METHOD(restart) {
RCT_EXPORT_METHOD(restart: (NSString *)reason) {
restartReason = reason;
if ([NSThread isMainThread]) {
[self loadBundle];
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-restart",
"version": "0.0.27",
"version": "0.0.28",
"description": "Sometimes you want to reload your app bundle during app runtime. This package will allow you to do it.",
"main": "lib/commonjs/index.js",
"module": "lib/module/index.js",
Expand Down
18 changes: 16 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { NativeModules } from "react-native";

const { RNRestart } = NativeModules;
const { RNRestart: rnRestart } = NativeModules;

type RestartType = {
/**
* @deprecated use `restart` instead
*/
Restart(): void;
restart(): void;
getReason(): Promise<string>;
};

export default RNRestart as RestartType;
const Restart = (reason?: string) => {
if (!reason) {
rnRestart.Restart(null);
} else {
rnRestart.Restart(reason);
}
};
const RNRestart: RestartType = {
...rnRestart,
restart: Restart,
Restart,
};

export default RNRestart;

0 comments on commit e7345c4

Please sign in to comment.