Created
August 2, 2019 15:32
-
-
Save FLGMwt/7162a0543c2011fba093c3eb44ccc05b to your computer and use it in GitHub Desktop.
Cavy e2e + expo + CirlceCI + genymotion cloud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 2.1 | |
executors: | |
expo_turtle_android_executor: | |
docker: | |
- image: my/private/registry/expo-turtle-android:turrrrrtle | |
working_directory: /home/circleci/expo-project | |
environment: | |
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"' | |
android_executor: | |
docker: | |
- image: circleci/android:api-29-node | |
jobs: | |
build_job: | |
executor: expo_turtle_android_executor | |
steps: | |
- checkout | |
- run: yarn install | |
- run: turtle build:android --output release.apk --keystore-path my-upload-key.keystore --keystore-alias my-key-alias --type apk --release-channel cavy-channel | |
- store_artifacts: | |
path: release.apk | |
test_job: | |
executor: android_executor | |
steps: | |
- add_ssh_keys: | |
fingerprints: | |
- "ca:14:54:2a:d4:95:fb:7b:d8:81:c1:d3:28:25:30:9c" | |
- checkout | |
- run: mkdir -p ~/.ssh | |
- run: ssh-keyscan x.x.x.x >> ~/.ssh/known_hosts # x.x.x.x => public IP of genymotion EC2 instance | |
- run: ssh -i genymotion-test.pem -f -NL 5555:localhost:5555 [email protected] => public IP of genymotion EC2 instance | |
- run: adb install -r release.apk | |
- run: yarn install | |
- run: node ./run-server.js | |
workflows: | |
version: 2 | |
# build: | |
# jobs: | |
# - build_job | |
test: | |
jobs: | |
- test_job |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { execFileSync, spawnSync } = require('child_process'); | |
const spawn = require('cross-spawn'); | |
const express = require('express'); | |
const server = express(); | |
const chalk = require('chalk'); | |
server.use(express.json()); | |
function runAdbCommands() { | |
try { | |
// Run ADB reverse tcp:8082 tcp:8082 to allow reporting of test results | |
// from React Native. Borrowed from react-native-cli. | |
const adbPath = getAdbPath(); | |
const adbArgs = ['reverse', 'tcp:8082', 'tcp:8082']; | |
console.log(`cavy: Running ${adbPath} ${adbArgs.join(' ')}`); | |
execFileSync(adbPath, adbArgs, { stdio: 'inherit' }); | |
// // Ensures the app is not open | |
// execFileSync(adbPath, 'shell am force-stop host.exp.exponent'.split(' '), { | |
// stdio: 'inherit', | |
// }); | |
// Ensures the app is not open | |
execFileSync( | |
adbPath, | |
'shell am force-stop com.verticalmade.cavytest'.split(' '), | |
{ | |
stdio: 'inherit', | |
} | |
); | |
execFileSync( | |
adbPath, | |
'shell am start -n com.verticalmade.cavytest/host.exp.exponent.MainActivity'.split( | |
' ' | |
), | |
{ | |
stdio: 'inherit', | |
} | |
); | |
} catch (e) { | |
console.error(`Could not run adb command: ${e.message}.`); | |
process.exit(1); | |
} | |
} | |
// Borrowed from react-native-cli. | |
function getAdbPath() { | |
return process.env.ANDROID_HOME | |
? process.env.ANDROID_HOME + '/platform-tools/adb' | |
: 'adb'; | |
} | |
var isWin = process.platform === 'win32'; | |
const targetPlatform = 'android'; | |
if (targetPlatform === 'android') { | |
runAdbCommands(); | |
} | |
function countString(count, str) { | |
let string = count == 1 ? str : str + 's'; | |
return `${count} ${string}`; | |
} | |
server.post('/report', (req, res) => { | |
const results = req.body['results']; | |
const errorCount = req.body['errorCount']; | |
const duration = req.body['duration']; | |
results.forEach((result, index) => { | |
message = `${index + 1}) ${result['message']}`; | |
if (result['passed']) { | |
console.log(chalk.green(message)); | |
} else { | |
console.log(chalk.red(message)); | |
} | |
}); | |
console.log(`Finished in ${duration} seconds`); | |
const endMsg = `${countString(results.length, 'example')}, ${countString( | |
errorCount, | |
'failure' | |
)}\n`; | |
if (!errorCount) { | |
console.log(endMsg); | |
res.send('ok'); | |
} else { | |
console.log(endMsg); | |
res.send('failed'); | |
} | |
process.exit(errorCount ? 1 : 0); | |
}); | |
server.get('/', (req, res) => { | |
console.log('got root request'); | |
res.send('cavy-cli running'); | |
}); | |
server.listen(8082, () => { | |
console.log(`cavy: Listening on port 8082 for test results...`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
License of the above: MIT