Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit c9f64d9

Browse files
authored
[CI] Create react-native-code-push CI (#1800)
1 parent fbebc93 commit c9f64d9

File tree

4 files changed

+85
-19
lines changed

4 files changed

+85
-19
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: React-native-code-push CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
jobs:
9+
test-android:
10+
name: Test Android app
11+
runs-on: macos-latest
12+
strategy:
13+
matrix:
14+
api-level: [27]
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
- name: Start adb server
19+
run: adb devices
20+
- name: Download system image "android-${{ matrix.api-level }}"
21+
run: $ANDROID_HOME/tools/bin/sdkmanager "system-images;android-${{ matrix.api-level }};google_apis;x86"
22+
- name: Create android emulator
23+
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"
24+
- name: Start android emulator
25+
run: $ANDROID_HOME/emulator/emulator -avd TestEmulator -noaudio -no-window -no-snapshot-save -no-boot-anim -memory 6144 &
26+
- run: sleep 120
27+
- run: adb shell settings put global window_animation_scale 0.0
28+
- run: adb shell settings put global transition_animation_scale 0.0
29+
- run: adb shell settings put global animator_duration_scale 0.0
30+
- name: Package Installation
31+
run: npm install
32+
- name: Install react-native-cli
33+
run: npm install react-native-cli
34+
- name: test:android
35+
run: npm run test:android
36+
37+
test-iOS:
38+
name: Test iOS app
39+
runs-on: macos-latest
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v2
43+
- name: Install dependecies
44+
run: npm install
45+
- name: Install react-native-cli
46+
run: npm install react-native-cli
47+
- name: Run tests
48+
run: npm run test:ios

code-push-plugin-testing-framework/script/platform.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ var AndroidEmulatorManager = (function () {
231231
* Ends a running application given its app id.
232232
*/
233233
AndroidEmulatorManager.prototype.endRunningApplication = function (appId) {
234-
return testUtil_1.TestUtil.getProcessOutput("adb shell am force-stop " + appId).then(function () { return null; });
234+
return testUtil_1.TestUtil.getProcessOutput("adb shell am force-stop " + appId).then(function () { return Q.delay(10000); });
235235
};
236236
/**
237237
* Restarts an already installed application by app id.
@@ -240,8 +240,8 @@ var AndroidEmulatorManager = (function () {
240240
var _this = this;
241241
return this.endRunningApplication(appId)
242242
.then(function () {
243-
// Wait for a second before restarting.
244-
return Q.delay(1000);
243+
// Wait for a 10 seconds before restarting.
244+
return Q.delay(10000);
245245
})
246246
.then(function () {
247247
return _this.launchInstalledApplication(appId);

code-push-plugin-testing-framework/script/serverUtil.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,25 @@ exports.createUpdateResponse = createUpdateResponse;
129129
function expectTestMessages(expectedMessages) {
130130
var deferred = Q.defer();
131131
var messageIndex = 0;
132+
var lastRequestBody = null;
132133
exports.testMessageCallback = function (requestBody) {
133134
try {
134135
console.log("Message index: " + messageIndex);
135-
if (typeof expectedMessages[messageIndex] === "string") {
136-
assert.equal(requestBody.message, expectedMessages[messageIndex]);
137-
}
138-
else {
139-
assert(areEqual(requestBody, expectedMessages[messageIndex]));
140-
}
141-
/* end of message array */
142-
if (++messageIndex === expectedMessages.length) {
143-
deferred.resolve(undefined);
136+
// We should ignore duplicated requests. It is only CI issue.
137+
if (lastRequestBody === null || !areEqual(requestBody, lastRequestBody)) {
138+
if (typeof expectedMessages[messageIndex] === "string") {
139+
assert.equal(requestBody.message, expectedMessages[messageIndex]);
140+
}
141+
else {
142+
assert(areEqual(requestBody, expectedMessages[messageIndex]));
143+
}
144+
145+
lastRequestBody = requestBody;
146+
147+
/* end of message array */
148+
if (++messageIndex === expectedMessages.length) {
149+
deferred.resolve(undefined);
150+
}
144151
}
145152
}
146153
catch (e) {

test/test.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,30 @@ class RNAndroid extends Platform.Android implements RNPlatform {
112112
return TestUtil.getProcessOutput("adb install -r " + this.getBinaryPath(projectDirectory), { cwd: androidDirectory }).then(() => { return null; });
113113
}
114114

115+
/**
116+
* Build function of the test application, the command depends on the OS
117+
*/
118+
buildFunction(androidDirectory: string): Q.Promise<void> {
119+
if (process.platform === "darwin") {
120+
return TestUtil.getProcessOutput(`./gradlew assembleRelease --daemon`, { noLogStdOut: true, cwd: androidDirectory })
121+
.then(() => { return null; });
122+
} else {
123+
return TestUtil.getProcessOutput(`gradlew assembleRelease --daemon`, { noLogStdOut: true, cwd: androidDirectory })
124+
.then(() => { return null; });
125+
}
126+
}
127+
115128
/**
116129
* Builds the binary of the project on this platform.
117130
*/
118131
buildApp(projectDirectory: string): Q.Promise<void> {
119132
// In order to run on Android without the package manager, we must create a release APK and then sign it with the debug certificate.
120133
const androidDirectory: string = path.join(projectDirectory, TestConfig.TestAppName, "android");
121-
const apkPath = this.getBinaryPath(projectDirectory);
122-
if (process.platform === "darwin") {
123-
return TestUtil.getProcessOutput(`./gradlew assembleRelease --daemon`, { cwd: androidDirectory })
124-
.then(() => { return null; });
125-
} else {
126-
return TestUtil.getProcessOutput(`gradlew assembleRelease --daemon`, { cwd: androidDirectory })
127-
.then(() => { return null; });
134+
// If the build fails for the first time, try rebuild app again
135+
try {
136+
return this.buildFunction(androidDirectory);
137+
} catch {
138+
return this.buildFunction(androidDirectory);
128139
}
129140
}
130141
}

0 commit comments

Comments
 (0)