Files
factorio-learning-environment/.github/workflows/factorio-test.yml
2025-08-20 09:49:52 +05:30

124 lines
3.8 KiB
YAML

name: Factorio Server Tests
on:
pull_request:
paths:
- 'fle/**'
- 'tests/actions/**'
- '.github/workflows/factorio-test.yml'
workflow_dispatch:
jobs:
test-factorio:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Verify scenario exists
run: |
# Check that the scenario directory exists
if [ ! -d "./fle/cluster/scenarios/default_lab_scenario" ]; then
echo "❌ Scenario directory not found at ./cluster/scenarios/default_lab_scenario"
exit 1
fi
echo "✓ Found scenario directory"
ls -la ./fle/cluster/scenarios/default_lab_scenario
- name: Start Factorio server
run: |
cd fle/cluster/local
bash run-envs.sh start -n 1
- name: Wait for server to start
run: |
echo "Waiting for Factorio server to initialize..."
sleep 15
echo "Waiting for RCON port 27000 to be ready..."
for i in {1..30}; do
if nc -z localhost 27000 2>/dev/null; then
echo "✓ RCON port 27000 is open!"
break
fi
echo "Waiting... ($i/30)"
sleep 2
done
if ! nc -z localhost 27000 2>/dev/null; then
echo "❌ RCON port 27000 never became available"
exit 1
fi
- name: Check server status
run: |
cd fle/cluster/local
docker compose -f docker-compose.yml ps
docker compose -f docker-compose.yml logs factorio_0
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
# Install the package with dev dependencies for testing
pip install -e ".[dev,agents,cluster,eval,all,mcp,env]"
- name: Debug container IPs and ports
run: |
echo "=== Docker containers ==="
docker ps -a
echo -e "\n=== Container port mappings ==="
docker ps --format "table {{.Names}}\t{{.Ports}}"
echo -e "\n=== Listening ports on host ==="
sudo netstat -tlnp | grep -E ':(270|34197)' || echo "No matching ports found"
- name: Test RCON connectivity
run: |
echo "=== Testing RCON connectivity ==="
# First, let's see what port the container is actually exposing
CONTAINER_ID=$(docker ps -q -f name=factorio_1)
if [ -n "$CONTAINER_ID" ]; then
echo "Found container ID: $CONTAINER_ID"
docker inspect $CONTAINER_ID | grep -A 10 "Ports"
fi
# Try common RCON ports
for port in 27000 27016 27017 27018 27019 27020; do
echo -n "Testing port $port: "
if nc -z -w 2 localhost $port 2>/dev/null; then
echo "✓ Open"
else
echo "✗ Closed"
fi
done
- name: Run Python tests with debugging
run: |
# Run tests with verbose output and show print statements
python -m pytest -v -s --tb=short tests/actions/
env:
FACTORIO_HOST: localhost
FACTORIO_RCON_PORT: 27000
PYTHONUNBUFFERED: 1
- name: Show test logs on failure
if: failure()
run: |
cd fle/cluster/local
echo "=== Factorio container logs ==="
docker compose -f docker-compose.yml logs factorio_0
echo -e "\n=== All container logs ==="
docker compose -f docker-compose-linux.yml logs
- name: Stop server
if: always()
run: |
cd fle/cluster/local
bash run-envs.sh stop