Files
media-map/.gitea/workflows/test.yml
Danilo Reyes 4709a05ad4
Some checks failed
Test Suite / test (push) Failing after 16s
Refactor CI/CD workflow to utilize NixOS VM for testing
- Changed the CI workflow to run tests inside a NixOS virtual machine instead of directly on the runner.
- Updated the NixOS VM configuration to include necessary dependencies and services for testing.
- Added a script to handle test execution within the VM, including setup for Python and Node.js environments.
- Implemented SSH access to the VM for remote operations and streamlined the process of starting and stopping the VM during tests.
- Enhanced the workflow to build the VM and copy the codebase for testing, ensuring a more isolated and consistent testing environment.
2025-12-28 22:53:25 -06:00

92 lines
2.8 KiB
YAML

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 configuration using nixos-rebuild
# This creates a VM that can be run with QEMU
nixos-rebuild build-vm \
-I nixos-config=./nix/test-vm.nix \
-I nixpkgs=<nixpkgs> \
-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