diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index f314b675..00000000 --- a/.dockerignore +++ /dev/null @@ -1,4 +0,0 @@ -README.md -.gitignore -docker-compose.yml -Dockerfile* \ No newline at end of file diff --git a/.drone.jsonnet b/.drone.jsonnet deleted file mode 100644 index 79e9bc8d..00000000 --- a/.drone.jsonnet +++ /dev/null @@ -1,32 +0,0 @@ - -[ - // Unit tests (PRs only) - { - kind: 'pipeline', - type: 'docker', - name: 'Session Android Integration tests', - platform: { os: 'linux', arch: 'amd64' }, - steps: [ - { - name: 'appium android tests', - image: "registry.oxen.rocks/appium-34-pixel6", - environment: { - 'APK_URL': 'https://oxen.rocks/AL-Session/session-android/dev/session-android-20240402T225341Z-d3c863574-universal.tar.xz', - 'APK_TO_TEST_PATH':'/session.apk', - 'NODE_CONFIG_ENV': 'ci', - }, - commands: [ - 'cp -r docker/etc/* /etc', - '/usr/bin/supervisord -c /etc/supervisord_test.conf', - 'chmod +x ./docker/*.sh', - './docker/start_emulators.sh', - './docker/dl.sh', - 'yarn install --immutable && yarn tsc && yarn test-no-retry ""' - - ], - - }, - ], -}, -] - diff --git a/.github/workflows/android-regression.yml b/.github/workflows/android-regression.yml new file mode 100644 index 00000000..727394bc --- /dev/null +++ b/.github/workflows/android-regression.yml @@ -0,0 +1,166 @@ +name: Run android regression tests +on: + workflow_dispatch: + inputs: + APK_URL: + description: 'APK.tar.gz url to test' + required: true + type: string + default: https://oxen.rocks/oxen-io/session-android/release/1.19.2/session-android-20240821T063349Z-20e1fbceb-universal.tar.xz + + APPIUM_REPO: + description: 'appium repo to checkout' + required: true + type: string + default: oxen-io/session-appium + + BRANCH_TO_CHECKOUT: + description: 'branch to checkout' + required: true + type: string + default: august + + SHARD_NUMBER: + description: 'shard number' + required: true + type: string + default: '1' + + SHARD_COUNT: + description: 'shard count' + required: true + type: string + default: '1' + + PRINT_FAILED_TEST_LOGS: + description: 'print failed test logs (1 to enable)' + required: true + type: string + default: '0' + + PRINT_ONGOING_TEST_LOGS: + description: 'print ongoing test logs (1 to enable)' + required: true + type: string + default: '0' + +# concurrency: +# group: ${{ github.workflow }} +# cancel-in-progress: true + +jobs: + android-regression: + runs-on: [self-hosted, linux, x64, qa-android] + env: + ANDROID_APP_PATH_PREFIX: "../extracted/session-android.apk" + APPIUM_ADB_FULL_PATH: "/opt/android/platform-tools/adb" + ANDROID_SDK_ROOT: "/opt/android" + PLAYWRIGHT_WORKERS_COUNT: 1 + PLAYWRIGHT_RETRIES_COUNT: 0 + PRINT_FAILED_TEST_LOGS: ${{ github.event.inputs.PRINT_FAILED_TEST_LOGS }} + PRINT_ONGOING_TEST_LOGS: ${{ github.event.inputs.PRINT_ONGOING_TEST_LOGS }} + IOS_APP_PATH_PREFIX: "just_not_empty" + IOS_FIRST_SIMULATOR: "just_not_empty" + IOS_SECOND_SIMULATOR: "just_not_empty" + IOS_THIRD_SIMULATOR: "just_not_empty" + IOS_FOURTH_SIMULATOR: "just_not_empty" + IOS_FIFTH_SIMULATOR: "just_not_empty" + IOS_SIXTH_SIMULATOR: "just_not_empty" + IOS_SEVENTH_SIMULATOR: "just_not_empty" + IOS_EIGHTH_SIMULATOR: "just_not_empty" + + + steps: + - uses: actions/checkout@v4 + - name: Runner Details + run: | + echo "BRANCH_TO_CHECKOUT ${{ github.event.inputs.BRANCH_TO_CHECKOUT }}" + echo "APPIUM_REPO ${{ github.event.inputs.APPIUM_REPO }}" + echo "APK_URL ${{ github.event.inputs.APK_URL }}" + echo "SHARD_NUMBER ${{ github.event.inputs.SHARD_NUMBER }}" + echo "SHARD_COUNT ${{ github.event.inputs.SHARD_COUNT }}" + + - name: Download APK + run: | + wget -q -O session-android.apk.tar.xz ${{ github.event.inputs.APK_URL }} + ls + pwd + + - name: Extract APK + run: | + tar xf session-android.apk.tar.xz + ls + pwd + + - name: Rename extracted folder + run: | + mv session-android-*universal extracted + ls extracted + mv extracted/*.apk extracted/session-android.apk + ls extracted + pwd + + + - uses: actions/checkout@v4 + with: + repository: ${{ github.event.inputs.APPIUM_REPO }} + ref: ${{ github.event.inputs.BRANCH_TO_CHECKOUT }} + path: 'forked-session-appium' + + - uses: actions/setup-node@v4 + with: + # node-version-file: 'forked-session-appium/.nvmrc' + node-version: 18.15.0 + + + - name: Install yarn + run: | + npm install -g yarn + corepack enable + yarn set version 4.1.1 + + - name: Install test dependencies + run: | + cd forked-session-appium + ls + git status + touch yarn.lock + yarn install --immutable + + - name: Build the Android tests + run: | + cd forked-session-appium + yarn tsc + + - name: Restart adb server + shell: bash + continue-on-error: true # just so we don't fail if adb wasn't alreadu running + run: | + source ./scripts/ci.sh + adb kill-server; + adb start-server; + + - name: Start 4 android emulators with snapshots + shell: bash + run: | + source ./scripts/ci.sh + start_with_snapshots + + - name: Run the Android tests + run: | + cd forked-session-appium + pwd + yarn test-android-shard ${{ github.event.inputs.SHARD_NUMBER }}​​/${{ github.event.inputs.SHARD_COUNT }}​​ + + - name: Killall running emulators + if: always() + continue-on-error: true # just so we don't fail + shell: bash + run: | + source ./scripts/ci.sh + killall_emulators + + + + + diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 073e83c4..00000000 --- a/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -FROM android-emulator-base - - - -#========================= -# Copying Scripts to root -#========================= - -RUN chmod a+x /session-appium/docker/*.sh -RUN ln -s /session-appium/docker/dl.sh /usr/bin/dl && ln -s /session-appium/docker/test.sh /usr/bin/ci_test && ln -s /session-appium/docker/dl_and_test.sh /usr/bin/dl_and_test - - - -WORKDIR /session-appium - -EXPOSE 8080 - -COPY avd /root/.android/avd - -ENTRYPOINT [ "/usr/bin/supervisord", "-c", "/etc/supervisord_test.conf", "-n" ] diff --git a/Dockerfile.base b/Dockerfile.base deleted file mode 100644 index f10b7f30..00000000 --- a/Dockerfile.base +++ /dev/null @@ -1,119 +0,0 @@ -# syntax=docker.io/docker/dockerfile:1.7-labs - -FROM openjdk:18-ea-11-jdk-slim-bullseye - -LABEL maintainer "Audric Ackermann" - -ENV DEBIAN_FRONTEND noninteractive - -WORKDIR / -#============================= -# Install Dependenices -#============================= -SHELL ["/bin/bash", "-c"] - -RUN apt-get update -RUN apt install -y ca-certificates curl git cpu-checker supervisor vim bash wget unzip xvfb x11vnc fluxbox xterm novnc net-tools htop libpulse-dev libnss3 libxcursor1 libasound2 libqt5gui5 libc++-dev libxcb-cursor0 htop tree tar gzip - - -#============================== -# Android SDK ARGS -#============================== -ARG ARCH="x86_64" -ARG TARGET="google_apis_playstore" -ARG API_LEVEL="34" -ARG BUILD_TOOLS="34.0.0" -ARG ANDROID_ARCH=${ANDROID_ARCH_DEFAULT} -ARG ANDROID_API_LEVEL="android-${API_LEVEL}" -ARG ANDROID_APIS="${TARGET};${ARCH}" -ARG EMULATOR_PACKAGE="system-images;${ANDROID_API_LEVEL};${ANDROID_APIS}" -ARG PLATFORM_VERSION="platforms;${ANDROID_API_LEVEL}" -ARG BUILD_TOOL="build-tools;${BUILD_TOOLS}" -ARG ANDROID_CMD="commandlinetools-linux-11076708_latest.zip" -ARG ANDROID_SDK_PACKAGES="${EMULATOR_PACKAGE} ${PLATFORM_VERSION} ${BUILD_TOOL} platform-tools" - -#============================== -# Set JAVA_HOME - SDK -#============================== -ENV ANDROID_SDK_ROOT=/opt/android -ENV PATH "$PATH:$ANDROID_SDK_ROOT/cmdline-tools/tools:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin:$ANDROID_SDK_ROOT/emulator:$ANDROID_SDK_ROOT/tools/bin:$ANDROID_SDK_ROOT/latform-tools:$ANDROID_SDK_ROOT/build-tools/${BUILD_TOOLS}:$ANDROID_SDK_ROOT/platform-tools/" -ENV DOCKER="true" - -#============================================ -# Install required Android CMD-line tools -#============================================ -RUN wget https://dl.google.com/android/repository/${ANDROID_CMD} -P /tmp && \ - unzip -d $ANDROID_SDK_ROOT /tmp/$ANDROID_CMD && \ - mkdir -p $ANDROID_SDK_ROOT/cmdline-tools/tools && cd $ANDROID_SDK_ROOT/cmdline-tools && mv NOTICE.txt source.properties bin lib tools/ && \ - cd $ANDROID_SDK_ROOT/cmdline-tools/tools && ls - -#============================================ -# Install required package using SDK manager -#============================================ -RUN yes Y | sdkmanager --licenses -RUN yes Y | sdkmanager --verbose --no_https ${ANDROID_SDK_PACKAGES} - -#============================================ -# Create required emulators -#============================================ -RUN adb devices # keep this one to make sure adb is initialized (and creates a dummy adbkey, then erase it) -RUN rm /root/.android/adbkey -COPY adbkey /root/.android/adbkey -COPY adbkey.pub /root/.android/adbkey.pub -RUN chmod 600 /root/.android/adbkey -RUN chmod 644 /root/.android/adbkey.pub -RUN adb devices - -ARG EMULATOR_NAME="emulator1" -ARG EMULATOR_DEVICE="pixel_6" # all emulators are created with the pixel 6 spec for now - -RUN yes | sdkmanager emulator -RUN echo "no" | avdmanager --verbose create avd --force --name "${EMULATOR_NAME}" --device "${EMULATOR_DEVICE}" --package "${EMULATOR_PACKAGE}" - -#========================== -# Install node & yarn berry -#========================== - -RUN curl -sL https://deb.nodesource.com/setup_18.x | bash && \ - apt-get -qqy install nodejs && npm install -g yarn && corepack enable && \ - yarn set version 4.1.1 - - -# Install websokify and noVNC -RUN curl -O https://bootstrap.pypa.io/get-pip.py && \ - python3 get-pip.py && \ - pip3 install --no-cache-dir \ - setuptools && \ - pip3 install -U https://github.com/novnc/websockify/archive/refs/tags/v0.11.0.tar.gz - -RUN wget -O x11vnc.zip https://github.com/x11vnc/noVNC/archive/refs/heads/x11vnc.zip && \ - unzip x11vnc.zip && mv noVNC-x11vnc /usr/local/noVNC/ && ls -la /usr/local/noVNC/utils && \ - (chmod a+x /usr/local/noVNC/utils/launch.sh || \ - (chmod a+x /usr/local/noVNC/utils/novnc_proxy && \ - ln -s -f /usr/local/noVNC/utils/novnc_proxy /usr/local/noVNC/utils/launch.sh)) && \ - rm -rf /tmp/* /var/tmp/* - - -ENV HOME=/root \ - DEBIAN_FRONTEND=noninteractive \ - LANG=en_US.UTF-8 \ - LANGUAGE=en_US.UTF-8 \ - LC_ALL=C.UTF-8 \ - DISPLAY=:0.0 \ - DISPLAY_WIDTH=1920 \ - DISPLAY_HEIGHT=900 \ - RUN_XTERM=yes \ - RUN_FLUXBOX=yes - - -#========================== -# copy the appium current folder -#========================== - -COPY --exclude="node_modules" --exclude="avd" --exclude=".git" --exclude="etc" --exclude="config/local*" ./ /session-appium - - -COPY docker/etc /etc - - -EXPOSE 8080 \ No newline at end of file diff --git a/docker/README.md b/docker/README.md deleted file mode 100644 index 7e34362b..00000000 --- a/docker/README.md +++ /dev/null @@ -1,56 +0,0 @@ -### Build the base image without the adb in it - -**This has to be done once on each computers you use this docker, and if you ever change the Dockerfile.base settings related to the avd.** - -Comment this line in the Dockerfile: -`COPY avd /root/.android/avd` - -then run build both docker images (base and test one) so you can manually build a snapshot for your avds. (step 1) -```sh -clear; sudo docker build -t android-emulator-base -f Dockerfile.base . && sudo docker build -t android-emulator -f Dockerfile . && sudo docker run --privileged -it --device /dev/kvm -p 8080:8080 android-emulator -``` - -Once that's done, open a browser to http://localhost:8080/vnc.html, you should see the novnc connect button. -Connect, and in the terminal opened, enter this (copy/paste doesn't work for now) -``` -./docker/start_emu_for_state.sh -``` - -Let the emulator start, and give it a few more minutes so the snapshot is as complete as possible. -Then, close manually the emulator, it should display the "saving state" dialog. -Once the state is saved, do on a host terminal from the root of the `appium` folder: -``` -sudo rm -rf avd; sudo docker cp $(sudo docker ps -q):/root/.android/avd/ ./avd # sudo docker ps -q returns the running container hash directly -``` - - -Once that's done, stop the current docker container (ctrl-c should be enough). - -Then, uncomment the line -``` -COPY avd /root/.android/avd -``` - -in the Dockerfile, and rebuild the 2 images -``` -clear; sudo docker build -t android-emulator-base -f Dockerfile.base . && sudo docker build -t android-emulator -f Dockerfile . # (step 1) -``` -Once that's done, you can start the docker with the apk to test with - -``` -sudo docker run --privileged -it --device /dev/kvm -e APK_URL='' -e NODE_CONFIG_ENV="ci" -e APK_TO_TEST_PATH="/session.apk" -p 8080:8080 android-emulator # (step 2) -``` - -Then, reconnect via vnc http://localhost:8080/vnc.html, and run in the terminal -``` -./docker/start_4_emus.sh & -``` -The 4 emulators should start hopefully not too slowly. - -You can then trigger the dl of the APK (from the APK_TO_TEST_PATH env variable above) and the integration tests by running the command -`dl_and_test` - - -### Daily use - -No need to rebuild the avds every time you use the docker image/start integration tests, but you will have to rebuild both docker images after a `git pull` the session-appium repository (i.e. updating the integration tests themselves). That step should be very fast though, as everything should be cached by docker. I usually just have one big command to rebuild the changes and restart the container. \ No newline at end of file diff --git a/docker/dl.sh b/docker/dl.sh deleted file mode 100644 index 6ca1f2c2..00000000 --- a/docker/dl.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -ex - -echo "APK_URL: $APK_URL" -apk_url=${APK_URL} -apk_saved_on=${APK_TO_TEST_PATH} - -cd / -wget -O /session.apk.tar.xz $apk_url -tar xvf /session.apk.tar.xz -mv /session*/*.apk /session.apk -cd - diff --git a/docker/dl_and_test.sh b/docker/dl_and_test.sh deleted file mode 100644 index ab5c1683..00000000 --- a/docker/dl_and_test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -ex - -/session-appium/docker/dl.sh && /session-appium/docker/test.sh \ No newline at end of file diff --git a/docker/etc/supervisor/conf.d/fluxbox.conf b/docker/etc/supervisor/conf.d/fluxbox.conf deleted file mode 100644 index b301a332..00000000 --- a/docker/etc/supervisor/conf.d/fluxbox.conf +++ /dev/null @@ -1,3 +0,0 @@ -[program:fluxbox] -command=fluxbox -autorestart=true \ No newline at end of file diff --git a/docker/etc/supervisor/conf.d/websockify.conf b/docker/etc/supervisor/conf.d/websockify.conf deleted file mode 100644 index fbbd0301..00000000 --- a/docker/etc/supervisor/conf.d/websockify.conf +++ /dev/null @@ -1,3 +0,0 @@ -[program:websockify] -command=websockify --web /usr/share/novnc 8080 localhost:5900 -autorestart=true \ No newline at end of file diff --git a/docker/etc/supervisor/conf.d/x11vnc.conf b/docker/etc/supervisor/conf.d/x11vnc.conf deleted file mode 100644 index 4b045796..00000000 --- a/docker/etc/supervisor/conf.d/x11vnc.conf +++ /dev/null @@ -1,3 +0,0 @@ -[program:x11vnc] -command=x11vnc -forever -shared -autorestart=true \ No newline at end of file diff --git a/docker/etc/supervisor/conf.d/xfvb.conf b/docker/etc/supervisor/conf.d/xfvb.conf deleted file mode 100644 index 08d35fcb..00000000 --- a/docker/etc/supervisor/conf.d/xfvb.conf +++ /dev/null @@ -1,3 +0,0 @@ -[program:xvfb] -command=Xvfb :0 -screen 0 "%(ENV_DISPLAY_WIDTH)s"x"%(ENV_DISPLAY_HEIGHT)s"x24 -listen tcp -ac -autorestart=true \ No newline at end of file diff --git a/docker/etc/supervisor/conf.d/xterm.conf b/docker/etc/supervisor/conf.d/xterm.conf deleted file mode 100644 index 9cd92be0..00000000 --- a/docker/etc/supervisor/conf.d/xterm.conf +++ /dev/null @@ -1,3 +0,0 @@ -[program:xterm] -command=xterm -autorestart=true \ No newline at end of file diff --git a/docker/etc/supervisord_test.conf b/docker/etc/supervisord_test.conf deleted file mode 100644 index e400e38a..00000000 --- a/docker/etc/supervisord_test.conf +++ /dev/null @@ -1,8 +0,0 @@ -[supervisord] -nodaemon = false -user = root -loglevel = info - - -[include] -files = /etc/supervisor/conf.d/fluxbox.conf /etc/supervisor/conf.d/websockify.conf /etc/supervisor/conf.d/x11vnc.conf /etc/supervisor/conf.d/xfvb.conf /etc/supervisor/conf.d/xterm.conf \ No newline at end of file diff --git a/docker/start_4_emus.sh b/docker/start_4_emus.sh deleted file mode 100644 index 1674a58b..00000000 --- a/docker/start_4_emus.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -ex - -DIR="$(cd "$(dirname "$0")" && pwd)" - -start_emu=$DIR/start_emu.sh - -adb devices - -export EMULATOR_NAME="emulator1" # they all share the same avd, but started with the -read-only flag to make it work -DEVICE_NAME="emulator-5554" nice ionice $start_emu & -DEVICE_NAME="emulator-5556" nice ionice $start_emu & -DEVICE_NAME="emulator-5558" nice ionice $start_emu & -DEVICE_NAME="emulator-5560" nice ionice $start_emu & - -wait # wait for the 4 emulators above to be started diff --git a/docker/start_appium.sh b/docker/start_appium.sh deleted file mode 100644 index 89606656..00000000 --- a/docker/start_appium.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -BL='\033[0;34m' -G='\033[0;32m' -RED='\033[0;31m' -YE='\033[1;33m' -NC='\033[0m' # No Color - -function start_appium () { - if [ "$APPIUM_PORT" == "" ] || [ "$APPIUM_PORT" == null ]; - then - printf "${G}==> ${YE}No port provided, instance will run on 4723 ${G}<==${NC}""\n" - sleep 0.5 - appium - else - printf "${G}==> ${BL}Instance will run on ${YE}${APPIUM_PORT} ${G}<==${NC}""\n" - sleep 0.5 - appium -p $APPIUM_PORT - fi -}; - -start_appium \ No newline at end of file diff --git a/docker/start_emu.sh b/docker/start_emu.sh deleted file mode 100644 index a7f8ae4e..00000000 --- a/docker/start_emu.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -set -ex - -BL='\033[0;34m' -G='\033[0;32m' -RED='\033[0;31m' -YE='\033[1;33m' -NC='\033[0m' # No Color - -emulator_name=${EMULATOR_NAME} -device_name=${DEVICE_NAME} - -function start_emulator() { - emulator -avd "${emulator_name}" -read-only -gpu off - printf "${G}==> ${BL}Emulator has ${YE}${EMULATOR_NAME} ${BL}started in headed mode! ${G}<==${NC}""\n" -} - -function disable_animation() { - adb -s ${device_name} shell "settings put global window_animation_scale 0.0" - adb -s ${device_name} shell "settings put global transition_animation_scale 0.0" - adb -s ${device_name} shell "settings put global animator_duration_scale 0.0" -} - -start_emulator -sleep 1 -disable_animation \ No newline at end of file diff --git a/docker/start_emu_for_state.sh b/docker/start_emu_for_state.sh deleted file mode 100644 index 67e0fb27..00000000 --- a/docker/start_emu_for_state.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -set -x - -emulator_name="emulator1" - -function start_emulator_for_state() { - rm -rf /root/.android/avd/emulator1.avd/snapshots/ # delete any saved snapshots - nohup emulator -avd "${emulator_name}" -gpu off -no-snapshot-load & # no -read only flag here - printf "==> Emulator ${emulator_name} has started IN HEADED mode! \n" -} - -start_emulator_for_state diff --git a/docker/start_emulators.sh b/docker/start_emulators.sh deleted file mode 100644 index 628f5383..00000000 --- a/docker/start_emulators.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -set -ex - -DIR="$(cd "$(dirname "$0")" && pwd)" - -start_emu=$DIR/start_emu.sh - -adb devices - -function wait_emulator_to_be_ready() { - to_wait_for="${1}" - start_time=$(date +%s) - timeout=200 - sleep_interval=1 - printf "==> Waiting booted emulator ... \n" - - while [ "`adb -s ${to_wait_for} shell getprop sys.boot_completed | tr -d '\r' `" != "1" ] ; do - adb devices - current_time=$(date +%s) - elapsed_time=$((current_time - start_time)) - if [ $elapsed_time -gt $timeout ]; then - printf "==> Timeout after ${timeout} seconds elapsed .. \n" - break - fi - printf "==> Emulator not reported as booted yet ... sleeping ${sleep_interval} before retry\n" - sleep $sleep_interval; - done - - if [ "`adb -s ${to_wait_for} shell getprop sys.boot_completed | tr -d '\r' `" == "1" ] ; then - printf "==> Emulator is booted! \n" - fi -} - -export EMULATOR_NAME="emulator1" # they all share the same avd, but started with the -read-only flag to make it work -DEVICE_NAME="emulator-5554" $start_emu & -sleep 1 -DEVICE_NAME="emulator-5556" $start_emu & -sleep 1 -DEVICE_NAME="emulator-5558" $start_emu & -sleep 1 -DEVICE_NAME="emulator-5560" $start_emu & -sleep 1 - -sleep 30; -adb devices;sleep 30; -adb devices;sleep 30; -adb devices;sleep 30; -adb devices;sleep 30; -adb devices;sleep 30; -adb devices;sleep 30; -adb devices; -# wait_emulator_to_be_ready "emulator-5554" -# wait_emulator_to_be_ready "emulator-5556" -# wait_emulator_to_be_ready "emulator-5558" -# wait_emulator_to_be_ready "emulator-5560" - -# wait # hang in here while the emulators are running diff --git a/docker/start_vnc.sh b/docker/start_vnc.sh deleted file mode 100644 index 33d581d8..00000000 --- a/docker/start_vnc.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/bash - -readonly G_LOG_I='[INFO]' -readonly G_LOG_W='[WARN]' -readonly G_LOG_E='[ERROR]' -BL='\033[0;34m' -G='\033[0;32m' -NC='\033[0m' # No Color - -main() { - launch_xvfb - launch_window_manager - run_vnc_server - printf "${G}==> ${BL}Welcome to android-emulator VNC by amrsa ${G}<==${NC}""\n" -} - -launch_xvfb() { - # Set defaults if the user did not specify envs. - export DISPLAY=${XVFB_DISPLAY:-:1} - local screen=${XVFB_SCREEN:-0} - local resolution=${XVFB_RESOLUTION:-1280x1024x24} - local timeout=${XVFB_TIMEOUT:-5} - - # Start and wait for either Xvfb to be fully up or we hit the timeout. - Xvfb ${DISPLAY} -screen ${screen} ${resolution} & - local loopCount=0 - until xdpyinfo -display ${DISPLAY} > /dev/null 2>&1 - do - loopCount=$((loopCount+1)) - sleep 1 - if [ ${loopCount} -gt ${timeout} ] - then - echo "${G_LOG_E} xvfb failed to start." - exit 1 - fi - done -} - -launch_window_manager() { - local timeout=${XVFB_TIMEOUT:-5} - - # Start and wait for either fluxbox to be fully up or we hit the timeout. - fluxbox & - local loopCount=0 - until wmctrl -m > /dev/null 2>&1 - do - loopCount=$((loopCount+1)) - sleep 1 - if [ ${loopCount} -gt ${timeout} ] - then - echo "${G_LOG_E} fluxbox failed to start." - exit 1 - fi - done -} - -run_vnc_server() { - local passwordArgument='-nopw' - - if [ -n "${VNC_PASSWORD}" ] - then - local passwordFilePath="${HOME}/x11vnc.pass" - if ! x11vnc -storepasswd "${VNC_PASSWORD}" "${passwordFilePath}" - then - echo "${G_LOG_E} Failed to store x11vnc password." - exit 1 - fi - passwordArgument=-"-rfbauth ${passwordFilePath}" - echo "${G_LOG_I} The VNC server will ask for a password." - else - echo "${G_LOG_W} The VNC server will NOT ask for a password." - fi - - x11vnc -ncache_cr -display ${DISPLAY} -forever ${passwordArgument} & - wait $! -} - - -control_c() { - echo "" - exit -} - -trap control_c SIGINT SIGTERM SIGHUP - -main - -exit \ No newline at end of file diff --git a/docker/test.sh b/docker/test.sh deleted file mode 100644 index d295b4a9..00000000 --- a/docker/test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -ex - -cd /session-appium && yarn install --immutable && yarn tsc && yarn test-no-retry "" \ No newline at end of file diff --git a/scripts/ci.sh b/scripts/ci.sh new file mode 100644 index 00000000..64296738 --- /dev/null +++ b/scripts/ci.sh @@ -0,0 +1,101 @@ +#!/bin/bash + + +ARCH="x86_64" +TARGET="google_apis_playstore" +API_LEVEL="34" +BUILD_TOOLS="34.0.0" +ANDROID_ARCH=${ANDROID_ARCH_DEFAULT} +ANDROID_API_LEVEL="android-${API_LEVEL}" +ANDROID_APIS="${TARGET};${ARCH}" +EMULATOR_PACKAGE="system-images;${ANDROID_API_LEVEL};${ANDROID_APIS}" +PLATFORM_VERSION="platforms;${ANDROID_API_LEVEL}" +BUILD_TOOL="build-tools;${BUILD_TOOLS}" +ANDROID_CMD="commandlinetools-linux-11076708_latest.zip" +export ANDROID_SDK_PACKAGES="${EMULATOR_PACKAGE} ${PLATFORM_VERSION} ${BUILD_TOOL} platform-tools" +export ANDROID_SDK_ROOT=/opt/android + +export PATH="$PATH:$ANDROID_SDK_ROOT/cmdline-tools/tools:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin:$ANDROID_SDK_ROOT/emulator:$ANDROID_SDK_ROOT/tools/bin:$ANDROID_SDK_ROOT/latform-tools:$ANDROID_SDK_ROOT/build-tools/${BUILD_TOOLS}:$ANDROID_SDK_ROOT/platform-tools/" +export EMULATOR_DEVICE="pixel_6" # all emulators are created with the pixel 6 spec for now + + +# this should only be done when we bump the API version or add a worker to the CI that needs emulators to be setup +# Once you've run this, you must also start_for_snapshots() and force_save_snapshots() (see details below) +function create_emulators() { + sudo apt update + sudo apt install -y ca-certificates curl git vim bash wget unzip tree htop gzip default-jre libnss3 libxcursor1 libqt5gui5 libc++-dev libxcb-cursor0 htop tree tar gzip gh nload + + sudo rm -rf $ANDROID_SDK_ROOT + + sudo mkdir -p $ANDROID_SDK_ROOT + sudo chown $USER:$USER $ANDROID_SDK_ROOT + + wget https://dl.google.com/android/repository/${ANDROID_CMD} -P /tmp && \ + unzip -d $ANDROID_SDK_ROOT /tmp/$ANDROID_CMD && \ + mkdir -p $ANDROID_SDK_ROOT/cmdline-tools/tools && cd $ANDROID_SDK_ROOT/cmdline-tools && mv NOTICE.txt source.properties bin lib tools/ && \ + cd $ANDROID_SDK_ROOT/cmdline-tools/tools && ls + + yes Y | sdkmanager --licenses + yes Y | sdkmanager --verbose --no_https ${ANDROID_SDK_PACKAGES} + + + adb devices + + + yes | sdkmanager emulator + + # make sure to start-adb at least once so it generates a key before we create the avd + + adb start-server + + for i in {1..4} + do + echo "no" | avdmanager --verbose create avd --force --name "emulator$i" --device "${EMULATOR_DEVICE}" --package "${EMULATOR_PACKAGE}" + # Path to the AVD's config.ini file + CONFIG_FILE="$HOME/.android/avd/emulator$i.avd/config.ini" + + # Set the RAM size to 6GB (6144MB) + sed -i 's/^hw\.ramSize=.*/hw.ramSize=6144/' "$CONFIG_FILE" + + done + + cd +} + + + + +function start_for_snapshots() { + for i in {1..4} + do + DISPLAY=:0 emulator @emulator$i -gpu host -accel on -no-snapshot-load & + sleep 20 + done +} + +# let the emulators start and be ready (check cpu usage) before calling this. +# We want to take a snapshot woth emulators state as "done" as we can +function force_save_snapshots() { + values=("5554" "5556" "5558" "5560" "5562" "5564" "5566" "5568") + for val in "${values[@]}" + do + adb -s emulator-$val emu avd snapshot save plop.snapshot + done +} + +function killall_emulators() { + killall qemu-system-x86_64; +} + + +function start_with_snapshots() { + for i in {1..4} + do + EMU_CONFIG_FILE="$HOME/.android/avd/emulator$i.avd/emulator-user.ini" + # set the position fo each emulator to be next to the previous one + sed -i "s/^window.x.*/window.x=$(( 100 + (i-1) * 400))/" "$EMU_CONFIG_FILE" + + DISPLAY=:0 emulator @emulator$i -gpu host -accel on -no-snapshot-save -snapshot plop.snapshot -force-snapshot-load & + sleep 5 + done +} \ No newline at end of file