@detools/travis-scripts

What
This module helps us (I hope it'll help you too) to manage builds and tests for applications written for React-Native.
Why
We've built a lot of 3rd-party modules for React-Native.
We have internal rules for every project that we are doing:
- All of them should have example apps with linked modules
- All of them should have E2E-tests written with Appium
- E2E-tests should run against example apps
To follow these rules we've copied build scripts from module to module.
This project helps us to follow DRY principle.
How to use
- First of all, you need to create your 3rd-party module.
- After that, install
@detools/travis-scripts
as devDependency:
npm i @detools/travis-scripts -D
- This module will create two files:
.travis.yml
.detoolsrc.js
Let's take a closer look:
.travis.yml
matrix:
include:
- os: osx
language: objective-c
osx_image: xcode9.4
env:
- OS: 'ios'
- os: linux
language: android
jdk: oraclejdk8
sudo: required
android:
components:
- platform-tools
- tools
- build-tools-27.0.3
- android-21
- android-27
- sys-img-armeabi-v7a-android-21
- extra-android-m2repository
- extra-google-m2repository
- extra-google-google_play_services
env:
- OS: 'android'
script:
- rm -rf ~/.nvm
- git clone https://github.com/creationix/nvm.git ~/.nvm
- (cd ~/.nvm; git checkout `git describe --abbrev=0 --tags`)
- source ~/.nvm/nvm.sh
- nvm install --lts
- npm run ci
.travis.yml — is a config for Travis CI. It contains a matrix with jobs for iOS and Android.
sys-img-armeabi-v7a-android-21
is an Emulator image with Android SDK 21 on board.
- This is an ARM image because we can't use x86 Emulators.
- Another parts of Android components just contains required parts to build an Android App.
- We define an according
OS
variable (one more value to tests these scripts locally is both
).
- Also, we detect if your operating system is not a macOS — we won't to run an iOS tasks.
OS=both
is a default behaviour.
- Script does install and run a
ci
— the only command to build and test example apps
.detoolsrc.js
export default {
test: {
ios: 'npm run test:ios',
android: 'npm run test:android',
},
}
.detoolsrc.js — is a config for @detools/travis-scripts
.
It contains optional and required fields that needs to be managed by project maintainer.
Let see them all:
export default {
requiredVariables: [],
beforeCreateProjects: [],
filesToCopy: [
'.appiumhelperrc',
'package.json',
'android/build.gradle',
'android/gradle/wrapper/gradle-wrapper.properties',
'android/app/src/main/AndroidManifest.xml',
`ios/${PROJECT}/AppDelegate.m`,
`ios/${PROJECT}/Info.plist`,
'src',
'scripts',
'__tests__',
'rn-cli.config.js',
'App.js',
'ios/Podfile',
],
usePods: false,
useAppium: true,
afterInstall: [],
additionalVariablesToBuild: {
ios: [],
android: [],
podspec: [],
},
build: {
ios: '',
android: '',
podspec: '',
},
additionalVariablesToTest: {
ios: [],
android: [],
podspec: [],
},
test: {
ios: 'npm run test:ios',
android: 'npm run test:android',
},
runTestsCount: 1,
failFast: true,
virtualDevice: {
ios: 'iPhone 6',
android: 'detools-android-5.1.1-22',
},
androidEmulatorNeedsWritableStorage: false,
}
Where it has been used
Roadmap
- Add bin scripts
- Create a npx command to bootstrap new modules with example apps and tests from CLI
- Add podspec generator
- Use passed fields to config
additionalVariablesToBuild
, build
, additionalVariablesToTest
Xcode 10
There is an error with RN 0.57 on Xcode 10 — https://github.com/facebook/react-native/issues/19573.
I have added -UseModernBuildSystem=NO
flag to be ready for Xcode 10 for now.
When RN Team will fix build on Xcode 10 — I will remove it.
License
MIT License
Copyright (c) 2018 Anton Kuznetsov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.