Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Poc speculos mobile bot (#1824)
Browse files Browse the repository at this point in the history
* IOS Bot on CI

* change workflow

* change algorand-ios branch to trigger on ci

* remove android on the onpush

* lint

* update ios workflow with cache

* change bot prefer-offline

Co-authored-by: Henri Ly <[email protected]>
  • Loading branch information
gre and henri-ly authored May 4, 2022
1 parent b2c0287 commit ba1587b
Show file tree
Hide file tree
Showing 96 changed files with 18,329 additions and 110 deletions.
155 changes: 155 additions & 0 deletions .github/workflows/bot-algorand-android-2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
name: Bot android 'algorand on POC-BOT-RN' v2
on:
workflow_dispatch:

jobs:
android:
name: Android
runs-on: macos-11
timeout-minutes: 70
env:
EMULATOR_COMMAND: "-avd emu -avd emu -no-audio -no-snapshot -no-window"
EMULATOR_EXECUTABLE: qemu-system-x86_64-headless
steps:
- uses: styfle/[email protected]
with:
all_but_latest: true

- uses: actions/checkout@v2
with:
fetch-depth: 50

# Set up tool versions
- uses: actions/setup-node@v2
with:
node-version: 14.x

- name: Use specific Java version for sdkmanager to work
uses: joschi/setup-jdk@v1
with:
java-version: 'openjdk8'
architecture: 'x64'
env:
# https://github.com/actions/toolkit/issues/641#issuecomment-728963957
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'

# Set path variables needed for caches
- name: Set workflow variables
id: workflow-variables
run: |
echo "::set-output name=metro-cache::$HOME/.metro"
echo "::set-output name=yarn-cache-dir::$(yarn cache dir)"
echo "::set-output name=tempdir::$TMPDIR"
- name: env
working-directory: bot-react-native
run: |
echo GITHUB_SHA=${GITHUB_SHA} >> .ci.env
echo GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} >> .ci.env
echo GITHUB_RUN_ID=${{ github.run_id }} >> .ci.env
echo GITHUB_WORKFLOW=${{ github.workflow }} >> .ci.env
echo SLACK_API_TOKEN=${{ secrets.SLACK_API_TOKEN }} >> .ci.env
echo SLACK_CHANNEL=live-bot-mobile >> .ci.env
echo BOT_FILTER_FAMILY=algorand >> .ci.env
- uses: actions/cache@v2
name: Yarn Cache
id: yarn-cache
with:
path: ${{ steps.workflow-variables.outputs.yarn-cache-dir }}
key: ${{ runner.os }}-yarn-v1-${{ hashFiles('**/package.json') }}
restore-keys: ${{ runner.os }}-yarn-v1

- name: Install dependencies of BOT
working-directory: bot-react-native
run: yarn --frozen-lockfile --network-timeout 100000 --network-concurrency 1 --no-audit --prefer-offline

- uses: actions/cache@v2
name: Gradle Cache
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-v1-${{ hashFiles('**/*.gradle*') }}
restore-keys: ${{ runner.os }}-gradle-v1

- name: Build Android App
working-directory: bot-react-native
run: |
yarn detox build e2e --configuration android
- name: Metro Bundler Cache
uses: actions/cache@v2
with:
path: ${{ steps.workflow-variables.outputs.metro-cache }}
key: ${{ runner.os }}-metro-v1-${{ github.run_id }}
restore-keys: ${{ runner.os }}-metro-v1

- name: Download Emulator Image
# This can fail on network request, wrap with retry
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
retry_wait_seconds: 60
max_attempts: 3
command: echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "system-images;android-30;google_apis;x86_64"

- name: Create Emulator
run: echo "no" | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd --force --name emu --device "Nexus 5X" -k 'system-images;android-30;google_apis;x86_64' -g google_apis

# These Emulator start steps are the current best practice to do retries on multi-line commands with persistent (nohup) processes
- name: Start Android Emulator
id: emu1
timeout-minutes: 5
continue-on-error: true
run: |
echo "Starting emulator"
nohup $ANDROID_HOME/emulator/emulator $EMULATOR_COMMAND &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done'
- name: Start Android Emulator Retry 1
id: emu2
if: steps.emu1.outcome=='failure'
timeout-minutes: 5
continue-on-error: true
run: |
echo "Starting emulator, second attempt"
$ANDROID_HOME/platform-tools/adb devices
sudo killall -9 $EMULATOR_EXECUTABLE || true
sleep 2
nohup $ANDROID_HOME/emulator/emulator $EMULATOR_COMMAND &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done'
- name: Start Android Emulator Retry 2
id: emu3
if: steps.emu2.outcome=='failure'
timeout-minutes: 5
continue-on-error: true
run: |
echo "Starting emulator, third attempt"
$ANDROID_HOME/platform-tools/adb devices
sudo killall -9 $EMULATOR_EXECUTABLE || true
sleep 2
nohup $ANDROID_HOME/emulator/emulator $EMULATOR_COMMAND &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done'
- name: Emulator Status
if: always()
run: |
if ${{ steps.emu1.outcome=='success' || steps.emu2.outcome=='success' || steps.emu3.outcome=='success' }}; then
echo "Emulator Started"
else
exit 1
fi
- name: Detox Test
# Detox uses Espresso to choreograph steps in reaction to UI events, so we need to send a stream of taps.
timeout-minutes: 40
working-directory: bot-react-native
run: |
$ANDROID_HOME/platform-tools/adb devices
$ANDROID_HOME/platform-tools/adb shell settings put global window_animation_scale 0.0
$ANDROID_HOME/platform-tools/adb shell settings put global transition_animation_scale 0.0
$ANDROID_HOME/platform-tools/adb shell settings put global animator_duration_scale 0.0
nohup sh -c "until false; do $ANDROID_HOME/platform-tools/adb shell input tap 100 800; sleep 0.2; done" &
yarn detox test e2e --configuration android --debug-synchronization 200
shell: bash
121 changes: 121 additions & 0 deletions .github/workflows/bot-algorand-android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Bot android 'algorand on POC-BOT-RN'
on:
workflow_dispatch:

jobs:
run-bot:
runs-on: macos-latest
steps:
- name: Use specific Java version for sdkmanager to work
uses: joschi/setup-jdk@v1
with:
java-version: 'openjdk8'
architecture: 'x64'
env:
# https://github.com/actions/toolkit/issues/641#issuecomment-728963957
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
# Set path variables needed for caches
- name: Set workflow variables
id: workflow-variables
run: |
echo "::set-output name=metro-cache::$HOME/.metro"
echo "::set-output name=yarn-cache-dir::$(yarn cache dir)"
echo "::set-output name=tempdir::$TMPDIR"
- uses: actions/cache@v2
name: Gradle Cache
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-v1-${{ hashFiles('**/*.gradle*') }}
restore-keys: ${{ runner.os }}-gradle-v1

- name: Download Android Emulator Image
run: |
echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "system-images;android-30;google_apis;x86_64"
echo "no" | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd --force --name emu --device "Nexus 5X" -k 'system-images;android-30;google_apis;x86_64' -g google_apis
$ANDROID_HOME/emulator/emulator -list-avds
- name: Start Android Emulator
id: emu1
timeout-minutes: 5
continue-on-error: true
run: |
echo "Starting emulator"
nohup $ANDROID_HOME/emulator/emulator -avd emu -no-audio -no-snapshot -no-window &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82'
$ANDROID_HOME/platform-tools/adb devices
echo "Emulator started"
- name: Metro Bundler Cache
uses: actions/cache@v2
with:
path: ${{ steps.workflow-variables.outputs.metro-cache }}
key: ${{ runner.os }}-metro-v1-${{ github.run_id }}
restore-keys: ${{ runner.os }}-metro-v1

- uses: actions/checkout@v2
- uses: actions/setup-node@master
with:
node-version: 14.x
- name: install yarn
run: npm i -g yarn
- name: kill apt-get
run: sudo killall -w apt-get apt || echo OK


- name: env
working-directory: bot-react-native
run: |
echo GITHUB_SHA=${GITHUB_SHA} >> .ci.env
echo GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} >> .ci.env
echo GITHUB_RUN_ID=${{ github.run_id }} >> .ci.env
echo GITHUB_WORKFLOW=${{ github.workflow }} >> .ci.env
echo SLACK_API_TOKEN=${{ secrets.SLACK_API_TOKEN }} >> .ci.env
echo SLACK_CHANNEL=live-bot-mobile >> .ci.env
echo BOT_FILTER_FAMILY=algorand >> .ci.env
- uses: actions/cache@v2
name: Yarn Cache
id: yarn-cache
with:
path: ${{ steps.workflow-variables.outputs.yarn-cache-dir }}
key: ${{ runner.os }}-yarn-v1-${{ hashFiles('**/bot-react-native/package.json') }}
restore-keys: ${{ runner.os }}-yarn-v1
- name: Install dependencies
run: |
yarn global add yalc
yarn --frozen-lockfile --network-timeout 100000 --network-concurrency 1 --no-audit --prefer-offline
yarn ci-setup-cli
- name: LOGGER
env:
BOT_LOG_PROXY_FILE: ../botreport/logs.txt
run: |
mkdir botreport
cd cli
node ./bin/index botLogProxy -p 8331 &
- name: Install dependencies of BOT
working-directory: bot-react-native
run: yarn --frozen-lockfile --network-timeout 100000 --network-concurrency 1 --no-audit --prefer-offline

- name: build bot
working-directory: bot-react-native
run: yarn detox build e2e --configuration android

- name: Detox Test
# Detox uses Espresso to choreograph steps in reaction to UI events, so we need to send a stream of taps.
working-directory: bot-react-native
timeout-minutes: 40
run: |
$ANDROID_HOME/platform-tools/adb devices
$ANDROID_HOME/platform-tools/adb shell settings put global window_animation_scale 0.0
$ANDROID_HOME/platform-tools/adb shell settings put global transition_animation_scale 0.0
$ANDROID_HOME/platform-tools/adb shell settings put global animator_duration_scale 0.0
yarn detox test e2e --configuration android --cleanup --debug-synchronization 500 --detectOpenHandles --runInBand
shell: bash

- name: upload logs
if: failure() || success()
uses: actions/upload-artifact@v1
with:
name: botreport
path: botreport/
112 changes: 112 additions & 0 deletions .github/workflows/bot-algorand-ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Bot IOS
on:
schedule:
- cron: "0 8-16/2 * * 1-5"
push:
branches:
- poc-speculos-mobile-bot
- support/bot-rn-speculos

jobs:
run-bot:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@master
with:
node-version: 14.x

- name: install yarn
run: npm i -g yarn
- name: kill apt-get
run: sudo killall -w apt-get apt || echo OK

- name: env
working-directory: bot-react-native
run: |
echo GITHUB_SHA=${GITHUB_SHA} >> .ci.env
echo GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} >> .ci.env
echo GITHUB_RUN_ID=${{ github.run_id }} >> .ci.env
echo GITHUB_WORKFLOW=${{ github.workflow }} >> .ci.env
echo SLACK_API_TOKEN=${{ secrets.SLACK_API_TOKEN }} >> .ci.env
echo SLACK_CHANNEL=live-bot-mobile >> .ci.env
- name: Set workflow variables
id: workflow-variables
run: |
echo "::set-output name=metro-cache::$HOME/.metro"
echo "::set-output name=yarn-cache-dir::$(yarn cache dir)"
echo "::set-output name=tempdir::$TMPDIR"
- uses: actions/cache@v2
name: Yarn Cache
id: yarn-cache
with:
path: ${{ steps.workflow-variables.outputs.yarn-cache-dir }}
key: ${{ runner.os }}-yarn-v1-${{ hashFiles('**/package.json') }}
restore-keys: ${{ runner.os }}-yarn-v1
- uses: actions/cache@v2
name: Detox Framework Cache
id: detox-cache
with:
path: ~/Library/Detox/ios
key: ${{ runner.os }}-detox-framework-cache-${{ steps.workflow-variables.outputs.xcode-version }}

# Detox is compiled during yarn install, using Xcode, set up cache first
- uses: hendrikmuhs/ccache-action@v1
name: Xcode Compile Cache
with:
key: ${{ runner.os }}-v2 # makes a unique key w/related restore key internally
max-size: 750M
- name: Cache Pods
uses: actions/cache@v2
id: podcache
with:
path: bot-react-native/ios/Pods
key: ${{ runner.os }}-pods-v2-${{ hashFiles('**/Podfile.lock') }}
restore-keys: ${{ runner.os }}-pods-v2


- name: Install dependencies
run: |
yarn global add yalc
yarn --frozen-lockfile --network-timeout 100000 --network-concurrency 1
yarn ci-setup-cli
- name: LOGGER
env:
BOT_LOG_PROXY_FILE: ../botreport/logs.txt
run: |
mkdir botreport
cd cli
node ./bin/index botLogProxy -p 8331 &
- name: Install dependencies of BOT
run: yarn ci-setup-rn
- name: Rebuild detox
working-directory: bot-react-native
if: steps.cache.outputs.cache-hit == 'true'
run: yarn detox clean-framework-cache && yarn detox build-framework-cache
timeout-minutes: 120

- name: Update Pods
working-directory: bot-react-native
run: |
gem update cocoapods xcodeproj
cd ios && pod install && cd ..
- run: brew tap wix/brew
- run: brew install applesimutils

- name: build bot
working-directory: bot-react-native
run: yarn detox build e2e --configuration ios
- name: run test bot
working-directory: bot-react-native
run: yarn detox test e2e --configuration ios --cleanup

- name: upload logs
if: failure() || success()
uses: actions/upload-artifact@v1
with:
name: botreport
path: botreport/
6 changes: 6 additions & 0 deletions bot-react-native/.buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

[android]
target = Google Inc.:Google APIs:23

[maven_repositories]
central = https://repo1.maven.org/maven2
Loading

1 comment on commit ba1587b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution.
To be able to merge in develop branch, you need to:

  • pass the CI
  • have a dev review
  • have a QA review

Please sign in to comment.