Skip to content

Commit df0c3df

Browse files
committed
chore(typegen): add canary python types runtime
1 parent 2c41dd9 commit df0c3df

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Script to generate Python types for CI validation
5+
* This script uses the test database setup to generate Python types
6+
*/
7+
8+
import { build } from '../src/server/app.js'
9+
10+
const TEST_CONNECTION_STRING = 'postgresql://postgres:postgres@localhost:5432'
11+
12+
async function generatePythonTypes() {
13+
const app = build()
14+
15+
try {
16+
const response = await app.inject({
17+
method: 'GET',
18+
url: '/generators/python',
19+
headers: {
20+
pg: TEST_CONNECTION_STRING,
21+
},
22+
query: {
23+
access_control: 'public',
24+
},
25+
})
26+
27+
if (response.statusCode !== 200) {
28+
console.error(`Failed to generate types: ${response.statusCode}`)
29+
console.error(response.body)
30+
process.exit(1)
31+
}
32+
33+
// Write to stdout so it can be captured
34+
process.stdout.write(response.body)
35+
} catch (error) {
36+
console.error('Error generating Python types:', error)
37+
process.exit(1)
38+
} finally {
39+
await app.close()
40+
}
41+
}
42+
43+
generatePythonTypes()
44+

0 commit comments

Comments
 (0)