Skip to content

Commit

Permalink
[CI] Create react-native-code-push CI (microsoft#1800)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreidubov authored Mar 3, 2020
1 parent fbebc93 commit c9f64d9
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 19 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/react-native-code-push-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: React-native-code-push CI

on:
pull_request:
branches:
- master

jobs:
test-android:
name: Test Android app
runs-on: macos-latest
strategy:
matrix:
api-level: [27]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Start adb server
run: adb devices
- name: Download system image "android-${{ matrix.api-level }}"
run: $ANDROID_HOME/tools/bin/sdkmanager "system-images;android-${{ matrix.api-level }};google_apis;x86"
- name: Create android emulator
run: $ANDROID_HOME/tools/bin/avdmanager create avd --force --name TestEmulator --abi google_apis/x86 --package 'system-images;android-${{ matrix.api-level }};google_apis;x86' --device "Nexus 6P"
- name: Start android emulator
run: $ANDROID_HOME/emulator/emulator -avd TestEmulator -noaudio -no-window -no-snapshot-save -no-boot-anim -memory 6144 &
- run: sleep 120
- run: adb shell settings put global window_animation_scale 0.0
- run: adb shell settings put global transition_animation_scale 0.0
- run: adb shell settings put global animator_duration_scale 0.0
- name: Package Installation
run: npm install
- name: Install react-native-cli
run: npm install react-native-cli
- name: test:android
run: npm run test:android

test-iOS:
name: Test iOS app
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependecies
run: npm install
- name: Install react-native-cli
run: npm install react-native-cli
- name: Run tests
run: npm run test:ios
6 changes: 3 additions & 3 deletions code-push-plugin-testing-framework/script/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ var AndroidEmulatorManager = (function () {
* Ends a running application given its app id.
*/
AndroidEmulatorManager.prototype.endRunningApplication = function (appId) {
return testUtil_1.TestUtil.getProcessOutput("adb shell am force-stop " + appId).then(function () { return null; });
return testUtil_1.TestUtil.getProcessOutput("adb shell am force-stop " + appId).then(function () { return Q.delay(10000); });
};
/**
* Restarts an already installed application by app id.
Expand All @@ -240,8 +240,8 @@ var AndroidEmulatorManager = (function () {
var _this = this;
return this.endRunningApplication(appId)
.then(function () {
// Wait for a second before restarting.
return Q.delay(1000);
// Wait for a 10 seconds before restarting.
return Q.delay(10000);
})
.then(function () {
return _this.launchInstalledApplication(appId);
Expand Down
25 changes: 16 additions & 9 deletions code-push-plugin-testing-framework/script/serverUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,25 @@ exports.createUpdateResponse = createUpdateResponse;
function expectTestMessages(expectedMessages) {
var deferred = Q.defer();
var messageIndex = 0;
var lastRequestBody = null;
exports.testMessageCallback = function (requestBody) {
try {
console.log("Message index: " + messageIndex);
if (typeof expectedMessages[messageIndex] === "string") {
assert.equal(requestBody.message, expectedMessages[messageIndex]);
}
else {
assert(areEqual(requestBody, expectedMessages[messageIndex]));
}
/* end of message array */
if (++messageIndex === expectedMessages.length) {
deferred.resolve(undefined);
// We should ignore duplicated requests. It is only CI issue.
if (lastRequestBody === null || !areEqual(requestBody, lastRequestBody)) {
if (typeof expectedMessages[messageIndex] === "string") {
assert.equal(requestBody.message, expectedMessages[messageIndex]);
}
else {
assert(areEqual(requestBody, expectedMessages[messageIndex]));
}

lastRequestBody = requestBody;

/* end of message array */
if (++messageIndex === expectedMessages.length) {
deferred.resolve(undefined);
}
}
}
catch (e) {
Expand Down
25 changes: 18 additions & 7 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,30 @@ class RNAndroid extends Platform.Android implements RNPlatform {
return TestUtil.getProcessOutput("adb install -r " + this.getBinaryPath(projectDirectory), { cwd: androidDirectory }).then(() => { return null; });
}

/**
* Build function of the test application, the command depends on the OS
*/
buildFunction(androidDirectory: string): Q.Promise<void> {
if (process.platform === "darwin") {
return TestUtil.getProcessOutput(`./gradlew assembleRelease --daemon`, { noLogStdOut: true, cwd: androidDirectory })
.then(() => { return null; });
} else {
return TestUtil.getProcessOutput(`gradlew assembleRelease --daemon`, { noLogStdOut: true, cwd: androidDirectory })
.then(() => { return null; });
}
}

/**
* Builds the binary of the project on this platform.
*/
buildApp(projectDirectory: string): Q.Promise<void> {
// In order to run on Android without the package manager, we must create a release APK and then sign it with the debug certificate.
const androidDirectory: string = path.join(projectDirectory, TestConfig.TestAppName, "android");
const apkPath = this.getBinaryPath(projectDirectory);
if (process.platform === "darwin") {
return TestUtil.getProcessOutput(`./gradlew assembleRelease --daemon`, { cwd: androidDirectory })
.then(() => { return null; });
} else {
return TestUtil.getProcessOutput(`gradlew assembleRelease --daemon`, { cwd: androidDirectory })
.then(() => { return null; });
// If the build fails for the first time, try rebuild app again
try {
return this.buildFunction(androidDirectory);
} catch {
return this.buildFunction(androidDirectory);
}
}
}
Expand Down

0 comments on commit c9f64d9

Please sign in to comment.