name: Test Suite on: push: branches: [ main, master, develop ] pull_request: branches: [ main, master, develop ] jobs: test: runs-on: nixos steps: - name: Checkout code uses: actions/checkout@v3 - name: Build NixOS VM run: | # Build the VM purely via the flake input nixpkgs (no host channels / no path) nix build .#nixosConfigurations.test-vm.config.system.build.vm -o vm-result - name: Start VM run: | # Find the VM run script (name may vary) VM_SCRIPT=$(find vm-result/bin -name "run-*-vm" -type f | head -1) if [ -z "$VM_SCRIPT" ]; then echo "VM script not found in vm-result/bin" ls -la vm-result/bin/ exit 1 fi echo "Starting VM with script: $VM_SCRIPT" # Start VM in background # The VM will expose SSH on port 2222 $VM_SCRIPT > vm.log 2>&1 & VM_PID=$! echo "VM_PID=$VM_PID" >> $GITHUB_ENV # Wait for VM to boot and SSH to be available echo "Waiting for VM to boot..." for i in {1..120}; do if ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=2 \ -p 2222 root@127.0.0.1 "echo 'VM is ready'" 2>/dev/null; then echo "VM is ready!" break fi if [ $i -eq 120 ]; then echo "VM failed to start after 4 minutes" echo "VM log:" tail -100 vm.log exit 1 fi sleep 2 done - name: Copy code to VM run: | # Copy the entire repository to the VM SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222" ssh $SSH_OPTS root@127.0.0.1 "mkdir -p /tmp/moviemap" # Use tar to copy files (more reliable than rsync in CI) tar --exclude='.git' \ --exclude='node_modules' \ --exclude='__pycache__' \ --exclude='*.pyc' \ --exclude='.pytest_cache' \ --exclude='dist' \ --exclude='vm-result' \ -czf - . | ssh $SSH_OPTS root@127.0.0.1 "cd /tmp/moviemap && tar -xzf -" - name: Run all tests in VM run: | # Execute the test script inside the VM SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222" ssh $SSH_OPTS root@127.0.0.1 "bash /tmp/moviemap/scripts/run-tests-in-vm.sh" - name: Stop VM if: always() run: | if [ ! -z "$VM_PID" ]; then kill $VM_PID || true wait $VM_PID 2>/dev/null || true fi # Also try to kill any remaining QEMU processes pkill -f "moviemap-test-vm" || true