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 fab18ae
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 14 deletions.
10 changes: 5 additions & 5 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
129 changes: 129 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
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: Cache application pods
uses: actions/cache@v3
id: cache-app-pods
with:
path: ./Example/ios/Pods
key: pods-${{ hashFiles('Example/ios/Podfile.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'

- name: Install application pods if cache not present
run: cd ./Example/ios && pod repo update && pod install
if: steps.cache-app-pods.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
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 fab18ae

Please sign in to comment.