From 3d79e05c4fef5080923e62641e6c829eb1cfb5bb Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Thu, 30 Apr 2026 00:16:43 +0200 Subject: [PATCH] ci: Move VM preparation to separate scripts --- .github/workflows/build-test-debug.yml | 55 +++++----------- .gitignore | 3 + appium-tests/scripts/prepare-vm.sh | 63 +++++++++++++++++++ appium-tests/scripts/run-vm.sh | 46 ++++++++++++++ ...{ci-qemu-prepare.sh => wait-vm-startup.sh} | 2 + 5 files changed, 130 insertions(+), 39 deletions(-) create mode 100755 appium-tests/scripts/prepare-vm.sh create mode 100755 appium-tests/scripts/run-vm.sh rename appium-tests/scripts/{ci-qemu-prepare.sh => wait-vm-startup.sh} (91%) diff --git a/.github/workflows/build-test-debug.yml b/.github/workflows/build-test-debug.yml index d28039c..0ebf3fe 100644 --- a/.github/workflows/build-test-debug.yml +++ b/.github/workflows/build-test-debug.yml @@ -8,8 +8,10 @@ on: workflow_dispatch: env: + # If changed, also update the variables in appium-tests/scripts/prepare-vm.sh BLISSOS_FILE: 'Bliss-v16.9.7-x86_64-OFFICIAL-foss-20241011.iso' BLISSOS_URL: 'https://deac-riga.dl.sourceforge.net/project/blissos-x86/Official/BlissOS16/FOSS/Generic/' + VM_DIR: ~/.cache/appium-vm jobs: build: @@ -183,57 +185,32 @@ jobs: with: key: ${{ env.BLISSOS_FILE }} restore-keys: ${{ env.BLISSOS_FILE }} - path: ~/.cache/blissos + path: ${{ env.VM_DIR }} - - name: Download BlissOS image - id: download-bliss + - name: Prepare BlissOS VM + id: prepare-vm run: | - mkdir -p ~/.cache/blissos - cd ~/.cache/blissos - curl -L -o bliss.sha256 "${{ env.BLISSOS_URL }}/${{ env.BLISSOS_FILE }}.sha256" - - if [[ ! -f "${{ env.BLISSOS_FILE }}" ]] || ! sha256sum -c bliss.sha256; then - echo "Downloading ${BLISSOS_FILE}..." - curl -L -o "${{ env.BLISSOS_FILE }}" "${{ env.BLISSOS_URL }}/${{ env.BLISSOS_FILE }}" - echo "cached=0" >> "$GITHUB_OUTPUT" - else - echo "Using cached ${BLISSOS_FILE}" - echo "cached=1" >> "$GITHUB_OUTPUT" - fi + ./appium-tests/scripts/prepare-vm.sh + # Save cache space by removing the ISO, we only need the extracted contents for QEMU + rm -f "${{ env.VM_DIR }}/${{ env.BLISSOS_FILE }}" - name: Store BlissOS to cache uses: actions/cache/save@v4 - if: steps.download-bliss.outputs.cached == 0 + if: steps.prepare-vm.outputs.cached == 0 with: key: ${{ env.BLISSOS_FILE }} - path: ~/.cache/blissos - - - name: Mount BlissOS image - run: | - ISO_PATH="$(realpath ~/.cache/blissos/${{ env.BLISSOS_FILE }})" - echo "Mounting ${ISO_PATH}..." - - sudo losetup -fP "$ISO_PATH" - LOOP_DEV="$(sudo losetup -j "$ISO_PATH" | cut -d: -f1)" - echo "Attached loop device: $LOOP_DEV" - echo "LOOP_DEV=$LOOP_DEV" >> $GITHUB_ENV - - mkdir -p /tmp/blissos - sudo mount -o loop,ro "${LOOP_DEV}p1" /tmp/blissos - echo "Mounted ${ISO_PATH} to /tmp/blissos" + path: ${{ env.VM_DIR }} - name: Create virtual USB drive image - run: | - qemu-img create -f qcow2 /tmp/usb-storage.qcow2 2G - mkdir -p vm-outputs + run: mkdir -p vm-outputs - name: Run QEMU id: run-qemu uses: etchdroid/qemu-kvm-action@v1 with: video-record: true - kernel: /tmp/blissos/kernel - initrd: /tmp/blissos/initrd.img + kernel: ${{ env.VM_DIR }}/kernel + initrd: ${{ env.VM_DIR }}/initrd.img cmdline: 'root=/dev/ram0 androidboot.selinux=permissive console=ttyS0 FFMPEG_CODEC=1 FFMPEG_PREFER_C2=1' video-output: vm-outputs/recording.mkv flags: | @@ -250,7 +227,7 @@ jobs: -display sdl,gl=on -drive - index=0,if=virtio,id=system,file=/tmp/blissos/system.efs,format=raw,readonly=on + index=0,if=virtio,id=system,file=${{ env.VM_DIR }}/system.efs,format=raw,readonly=on -usb -device usb-tablet,bus=usb-bus.0 @@ -259,7 +236,7 @@ jobs: -device ich9-usb-uhci1,id=uhci -drive - if=none,id=usbstick,file=/tmp/usb-storage.qcow2,format=qcow2 + if=none,id=usbstick,file=${{ env.VM_DIR }}/usb-storage.qcow2,format=qcow2 -device usb-storage,id=usbstick,bus=xhci.0,drive=usbstick,removable=on -qmp @@ -271,7 +248,7 @@ jobs: cd appium-tests export LOGCAT_DIR="$PWD/../vm-outputs/logcat/" mkdir -p "$LOGCAT_DIR" - ./scripts/ci-qemu-prepare.sh + ./scripts/wait-vm-startup.sh adb install -r ../apk/*.apk adb logcat -d > "$LOGCAT_DIR/0_before.log" 2>&1 uv run pytest -sv --tb=native --junit-xml=../junit.xml diff --git a/.gitignore b/.gitignore index 046666b..c4b4b54 100644 --- a/.gitignore +++ b/.gitignore @@ -98,6 +98,9 @@ proguard/ # Android Studio Navigation editor temp files .navigation/ +# Appium VM files +.appium-vm/ + # Android Studio captures folder captures/ diff --git a/appium-tests/scripts/prepare-vm.sh b/appium-tests/scripts/prepare-vm.sh new file mode 100755 index 0000000..2216244 --- /dev/null +++ b/appium-tests/scripts/prepare-vm.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" + +BLISSOS_FILE="${BLISSOS_FILE:-Bliss-v16.9.7-x86_64-OFFICIAL-foss-20241011.iso}" +BLISSOS_URL="${BLISSOS_URL:-https://deac-riga.dl.sourceforge.net/project/blissos-x86/Official/BlissOS16/FOSS/Generic/}" +VM_DIR="${VM_DIR:-$PROJECT_ROOT/.appium-vm}" + +# Check for required tools +EXIT=0 +for tool in curl 7z qemu-img sha256sum; do + if ! command -v "$tool" &> /dev/null; then + echo "Error: $tool is not installed." + EXIT=1 + fi +done +[[ "$EXIT" == 1 ]] && exit 1 + +mkdir -p "$VM_DIR" + +if [[ -f "$VM_DIR/kernel" && -f "$VM_DIR/initrd.img" && -f "$VM_DIR/system.efs" ]]; then + echo "Kernel, initrd, and system.efs already extracted to '$VM_DIR'. Skipping download and extraction." + exit 0 +fi + +# Download BlissOS ISO +ISO_PATH="$VM_DIR/$BLISSOS_FILE" +SHA_PATH="$ISO_PATH.sha256" + +if [[ ! -f "$SHA_PATH" ]]; then + echo "Downloading SHA256 checksum..." + curl -L -o "$SHA_PATH" "$BLISSOS_URL/$BLISSOS_FILE.sha256" +fi + +if [[ ! -f "$ISO_PATH" ]] || ! (cd "$VM_DIR" && sha256sum -c "$(basename "$SHA_PATH")"); then + echo "Downloading BlissOS ISO (this may take a while)..." + curl -L -o "$ISO_PATH" "$BLISSOS_URL/$BLISSOS_FILE" + (cd "$VM_DIR" && sha256sum -c "$(basename "$SHA_PATH")") +else + echo "BlissOS ISO is already present and valid." +fi + +# Extract files from ISO +echo "Extracting files from ISO..." +# 7z e (extract) -y (yes to all) -o (output dir) +7z e -y -o"$VM_DIR" "$ISO_PATH" kernel initrd.img system.efs + +# Create virtual USB drive image +USB_IMAGE="$VM_DIR/usb-storage.qcow2" +if [[ ! -f "$USB_IMAGE" ]]; then + echo "Creating virtual USB drive image..." + qemu-img create -f qcow2 "$USB_IMAGE" 2G +else + echo "Virtual USB drive image already exists." +fi + +echo "VM preparation complete. Files are in $VM_DIR" +# For CI to know where files are +if [[ -n "${GITHUB_OUTPUT:-}" ]]; then + echo "vm_dir=$VM_DIR" >> "$GITHUB_OUTPUT" +fi diff --git a/appium-tests/scripts/run-vm.sh b/appium-tests/scripts/run-vm.sh new file mode 100755 index 0000000..8e2db75 --- /dev/null +++ b/appium-tests/scripts/run-vm.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Go to project root from appium-tests/scripts +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +VM_DIR="$PROJECT_ROOT/.appium-vm" + +USB_IMAGE="$VM_DIR/usb-storage.qcow2" +SYSTEM_EFS="$VM_DIR/system.efs" +KERNEL="$VM_DIR/kernel" +INITRD="$VM_DIR/initrd.img" + +# Check if files exist +for file in "$USB_IMAGE" "$SYSTEM_EFS" "$KERNEL" "$INITRD"; do + if [[ ! -f "$file" ]]; then + echo "Error: $file not found. Please run appium-tests/scripts/prepare-vm.sh first." + exit 1 + fi +done + +echo "Starting Bliss OS VM..." +echo "ADB will be available on localhost:5556" + +qemu-system-x86_64 \ + -enable-kvm \ + -cpu host \ + -smp 2 \ + -m 4096 \ + -kernel "$KERNEL" \ + -initrd "$INITRD" \ + -append 'root=/dev/ram0 androidboot.selinux=permissive console=ttyS0 FFMPEG_CODEC=1 FFMPEG_PREFER_C2=1' \ + -netdev user,id=network,hostfwd=tcp::5556-:5555 \ + -device virtio-net-pci,netdev=network \ + -device virtio-vga-gl \ + -display gtk,gl=on \ + -serial stdio \ + -drive index=0,if=virtio,id=system,file="$SYSTEM_EFS",format=raw,readonly=on \ + -usb \ + -device usb-tablet,bus=usb-bus.0 \ + -device nec-usb-xhci,id=xhci \ + -device ich9-usb-uhci1,id=uhci \ + -drive if=none,id=usbstick,file="$USB_IMAGE",format=qcow2 \ + -device usb-storage,id=usbstick,bus=xhci.0,drive=usbstick,removable=on \ + -qmp unix:/tmp/qmp.sock,server=on,wait=off \ + -monitor unix:/tmp/qemu-monitor.sock,server=on,wait=off diff --git a/appium-tests/scripts/ci-qemu-prepare.sh b/appium-tests/scripts/wait-vm-startup.sh similarity index 91% rename from appium-tests/scripts/ci-qemu-prepare.sh rename to appium-tests/scripts/wait-vm-startup.sh index d9ed33c..eb298d1 100755 --- a/appium-tests/scripts/ci-qemu-prepare.sh +++ b/appium-tests/scripts/wait-vm-startup.sh @@ -31,4 +31,6 @@ fi # Fix launcher and go home "${adb[@]}" shell pm set-home-activity com.android.launcher3 "${adb[@]}" shell input keyevent KEYCODE_HOME + +# Enable pointer location to see what the appium tests are doing "${adb[@]}" shell settings put system pointer_location 1