ci: Move VM preparation to separate scripts

This commit is contained in:
Davide Depau committed 2026-04-30 00:16:43 +02:00
1 parent 443c0fb04c
commit 3d79e05c4f
5 files changed
+130 -39

No files matched your search

+16 -39
View File
@@ -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
+3
View File
@@ -98,6 +98,9 @@ proguard/
# Android Studio Navigation editor temp files
.navigation/
# Appium VM files
.appium-vm/
# Android Studio captures folder
captures/
+63
View File
@@ -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
+46
View File
@@ -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
@@ -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