Skip to content

Commit bbabd3b

Browse files
committed
Use GitHub Actions CI
1 parent 57a2aa0 commit bbabd3b

File tree

4 files changed

+214
-85
lines changed

4 files changed

+214
-85
lines changed

.circleci/config.yml

Lines changed: 0 additions & 85 deletions
This file was deleted.

.github/workflows/build_and_test.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Build jsc-android and test
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
container: reactnativecommunity/react-native-android:2019-9-4
9+
10+
steps:
11+
- uses: actions/checkout@v1
12+
13+
- name: Install packages
14+
run: |
15+
apt-get update
16+
apt-get install coreutils realpath curl git subversion python3.5 python3.5-dev ruby gperf -y
17+
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
18+
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash
19+
echo 'export NVM_DIR="$HOME/.nvm"' >> "${HOME}/.bashrc"
20+
echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> "${HOME}/.bashrc"
21+
source "${HOME}/.bashrc"
22+
nvm install 10
23+
nvm use 10
24+
nvm alias default 10
25+
shell: bash
26+
27+
- name: Install Android packages
28+
run: |
29+
sdkmanager \
30+
"lldb;3.0" \
31+
"cmake;3.10.2.4988404"
32+
shell: bash
33+
- name: Build
34+
run: |
35+
yarn clean
36+
yarn download
37+
yarn start
38+
shell: bash
39+
40+
- name: Archive
41+
run: |
42+
mkdir -p archive
43+
mv dist archive/
44+
mv dist.unstripped archive/
45+
shell: bash
46+
47+
- uses: actions/upload-artifact@master
48+
with:
49+
name: archive
50+
path: archive
51+
52+
53+
test:
54+
needs: build
55+
runs-on: macOS-latest
56+
57+
steps:
58+
- uses: actions/checkout@v1
59+
60+
- uses: actions/download-artifact@master
61+
with:
62+
name: archive
63+
path: archive
64+
65+
- name: Launch AVD
66+
run: |
67+
source scripts/android-setup.sh
68+
export PATH="${ANDROID_HOME}/emulator:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools:${PATH}"
69+
export AVD_PACKAGES="system-images;android-${ANDROID_SDK_TARGET_API_LEVEL};google_apis;${AVD_ABI}"
70+
sdkmanager "${AVD_PACKAGES}"
71+
createAVD
72+
launchAVD &
73+
shell: bash
74+
75+
- name: Wait AVD
76+
run: |
77+
export PATH="${ANDROID_HOME}/emulator:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools:${PATH}"
78+
source scripts/android-setup.sh
79+
set +e +o pipefail
80+
waitForAVD
81+
shell: bash
82+
83+
- name: Run test
84+
run: |
85+
mv archive/dist .
86+
cd test
87+
yarn
88+
cd android && ./gradlew assembleDebug assembleAndroidTest connectedAndroidTest
89+
shell: bash

scripts/.tests.env

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# These should match the recommended versions listed in
2+
# https://facebook.github.io/react-native/docs/getting-started.html
3+
4+
5+
## ANDROID ##
6+
# Android SDK Build Tools revision
7+
export ANDROID_SDK_BUILD_TOOLS_REVISION=28.0.3
8+
# Android API Level we build with
9+
export ANDROID_SDK_BUILD_API_LEVEL="28"
10+
# Google APIs for Android level
11+
export ANDROID_GOOGLE_API_LEVEL="23"
12+
# Minimum Android API Level we target
13+
export ANDROID_SDK_TARGET_API_LEVEL="19"
14+
# Android Virtual Device name
15+
export AVD_NAME="testAVD"
16+
# ABI to use in Android Virtual Device
17+
export AVD_ABI=x86
18+
19+
## IOS ##
20+
export IOS_TARGET_OS="12.4"
21+
export IOS_DEVICE="iPhone 6s"
22+
export TVOS_DEVICE="Apple TV"
23+
24+
## CI OVERRIDES ##
25+
# Values to override when running in CI
26+
# $CI is set by Circle CI
27+
if [ $CI ]; then
28+
# Use ARM on Circle CI
29+
export AVD_ABI=armeabi-v7a
30+
fi

scripts/android-setup.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
# Copyright (c) Facebook, Inc. and its affiliates.
3+
#
4+
# This source code is licensed under the MIT license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# inspired by https://github.com/Originate/guide/blob/master/android/guide/Continuous%20Integration.md
8+
9+
# shellcheck disable=SC1091
10+
source "scripts/.tests.env"
11+
12+
function getAndroidPackages {
13+
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/tools.bin:$PATH"
14+
15+
DEPS="$ANDROID_HOME/installed-dependencies"
16+
17+
# Package names can be obtained using `sdkmanager --list`
18+
if [ ! -e "$DEPS" ] || [ ! "$CI" ]; then
19+
echo "Installing Android API level $ANDROID_SDK_TARGET_API_LEVEL, Google APIs, $AVD_ABI system image..."
20+
sdkmanager "system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;$AVD_ABI"
21+
echo "Installing build SDK for Android API level $ANDROID_SDK_BUILD_API_LEVEL..."
22+
sdkmanager "platforms;android-$ANDROID_SDK_BUILD_API_LEVEL"
23+
echo "Installing target SDK for Android API level $ANDROID_SDK_TARGET_API_LEVEL..."
24+
sdkmanager "platforms;android-$ANDROID_SDK_TARGET_API_LEVEL"
25+
echo "Installing SDK build tools, revision $ANDROID_SDK_BUILD_TOOLS_REVISION..."
26+
sdkmanager "build-tools;$ANDROID_SDK_BUILD_TOOLS_REVISION"
27+
# These moved to "system-images;android-$ANDROID_SDK_BUILD_API_LEVEL;google_apis;x86" starting with API level 25, but there is no ARM version.
28+
echo "Installing Google APIs $ANDROID_GOOGLE_API_LEVEL..."
29+
sdkmanager "add-ons;addon-google_apis-google-$ANDROID_GOOGLE_API_LEVEL"
30+
echo "Installing Android Support Repository"
31+
sdkmanager "extras;android;m2repository"
32+
$CI && touch "$DEPS"
33+
fi
34+
}
35+
36+
function getAndroidNDK {
37+
NDK_HOME="/opt/ndk"
38+
DEPS="$NDK_HOME/installed-dependencies"
39+
40+
if [ ! -e $DEPS ]; then
41+
cd $NDK_HOME || exit
42+
echo "Downloading NDK..."
43+
curl -o ndk.zip https://dl.google.com/android/repository/android-ndk-r19c-linux-x86_64.zip
44+
unzip -o -q ndk.zip
45+
echo "Installed Android NDK at $NDK_HOME"
46+
touch $DEPS
47+
rm ndk.zip
48+
fi
49+
}
50+
51+
function createAVD {
52+
AVD_PACKAGES="system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;$AVD_ABI"
53+
echo "Creating AVD with packages $AVD_PACKAGES"
54+
echo no | avdmanager create avd --name "$AVD_NAME" --force --package "$AVD_PACKAGES" --tag google_apis --abi "$AVD_ABI"
55+
}
56+
57+
function launchAVD {
58+
# The AVD name here should match the one created in createAVD
59+
if [ "$CI" ]
60+
then
61+
"$ANDROID_HOME/emulator/emulator" -avd "$AVD_NAME" -no-audio -no-window
62+
else
63+
"$ANDROID_HOME/emulator/emulator" -avd "$AVD_NAME"
64+
fi
65+
}
66+
67+
function waitForAVD {
68+
echo "Waiting for Android Virtual Device to finish booting..."
69+
local bootanim=""
70+
export PATH=$(dirname $(dirname $(command -v android)))/platform-tools:$PATH
71+
until [[ "$bootanim" =~ "stopped" ]]; do
72+
sleep 5
73+
bootanim=$(adb -e shell getprop init.svc.bootanim 2>&1)
74+
echo "boot animation status=$bootanim"
75+
done
76+
echo "Android Virtual Device is ready."
77+
}
78+
79+
function retry3 {
80+
local n=1
81+
local max=3
82+
local delay=1
83+
while true; do
84+
"$@" && break || {
85+
if [[ $n -lt $max ]]; then
86+
((n++))
87+
echo "Command failed. Attempt $n/$max:"
88+
sleep $delay;
89+
else
90+
echo "The command has failed after $n attempts." >&2
91+
return 1
92+
fi
93+
}
94+
done
95+
}

0 commit comments

Comments
 (0)