|
| 1 | +name: Validate Python Type Generation |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master, main] |
| 6 | + paths: |
| 7 | + - 'src/server/templates/python.ts' |
| 8 | + - 'src/lib/**' |
| 9 | + - 'test/**' |
| 10 | + pull_request: |
| 11 | + branches: [master, main] |
| 12 | + paths: |
| 13 | + - 'src/server/templates/python.ts' |
| 14 | + - 'src/lib/**' |
| 15 | + - 'test/**' |
| 16 | + |
| 17 | +jobs: |
| 18 | + validate-python-types: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout code |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Set up Node.js |
| 26 | + uses: actions/setup-node@v4 |
| 27 | + with: |
| 28 | + node-version: '20' |
| 29 | + cache: 'npm' |
| 30 | + |
| 31 | + - name: Install dependencies |
| 32 | + run: npm ci |
| 33 | + |
| 34 | + - name: Build project |
| 35 | + run: npm run build |
| 36 | + |
| 37 | + - name: Set up Python |
| 38 | + uses: actions/setup-python@v5 |
| 39 | + with: |
| 40 | + python-version: '3.11' |
| 41 | + cache: 'pip' |
| 42 | + |
| 43 | + - name: Install Python dependencies |
| 44 | + run: | |
| 45 | + pip install pydantic typing-extensions |
| 46 | +
|
| 47 | + - name: Start test database |
| 48 | + working-directory: test/db |
| 49 | + run: | |
| 50 | + docker compose up -d --wait |
| 51 | +
|
| 52 | + - name: Wait for database to be ready |
| 53 | + run: | |
| 54 | + # Install PostgreSQL client for health check |
| 55 | + sudo apt-get update && sudo apt-get install -y postgresql-client |
| 56 | + until pg_isready -h localhost -p 5432 -U postgres; do |
| 57 | + echo "Waiting for database..." |
| 58 | + sleep 1 |
| 59 | + done |
| 60 | + echo "Database is ready!" |
| 61 | +
|
| 62 | + - name: Generate Python types |
| 63 | + id: generate-types |
| 64 | + run: | |
| 65 | + node --loader ts-node/esm scripts/generate-python-types-test.ts > generated_types.py |
| 66 | + echo "Generated Python types (first 30 lines):" |
| 67 | + head -30 generated_types.py |
| 68 | +
|
| 69 | + - name: Validate Python types syntax |
| 70 | + run: | |
| 71 | + python -m py_compile generated_types.py |
| 72 | + echo "✓ Python syntax is valid" |
| 73 | +
|
| 74 | + - name: Validate Python types imports |
| 75 | + run: | |
| 76 | + python << 'EOF' |
| 77 | + import sys |
| 78 | + import importlib.util |
| 79 | +
|
| 80 | + try: |
| 81 | + # Load the module from file |
| 82 | + spec = importlib.util.spec_from_file_location("generated_types", "generated_types.py") |
| 83 | + if spec is None or spec.loader is None: |
| 84 | + print("✗ Failed to create module spec") |
| 85 | + sys.exit(1) |
| 86 | + |
| 87 | + module = importlib.util.module_from_spec(spec) |
| 88 | + spec.loader.exec_module(module) |
| 89 | + |
| 90 | + print("✓ All imports are valid") |
| 91 | + print("✓ Generated types can be imported successfully") |
| 92 | + print(f"✓ Module loaded: {module.__name__}") |
| 93 | + except ImportError as e: |
| 94 | + print(f"✗ Import error: {e}") |
| 95 | + import traceback |
| 96 | + traceback.print_exc() |
| 97 | + sys.exit(1) |
| 98 | + except SyntaxError as e: |
| 99 | + print(f"✗ Syntax error: {e}") |
| 100 | + import traceback |
| 101 | + traceback.print_exc() |
| 102 | + sys.exit(1) |
| 103 | + except Exception as e: |
| 104 | + print(f"✗ Unexpected error: {e}") |
| 105 | + import traceback |
| 106 | + traceback.print_exc() |
| 107 | + sys.exit(1) |
| 108 | + EOF |
| 109 | +
|
| 110 | + - name: Cleanup |
| 111 | + if: always() |
| 112 | + working-directory: test/db |
| 113 | + run: docker compose down |
0 commit comments