Skip to content

TypeScript library Generation #17

TypeScript library Generation

TypeScript library Generation #17

Workflow file for this run

name: CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
jobs:
test-python:
runs-on: ubuntu-latest
name: Test Python Library
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "latest"
- name: Set up Python
run: uv python install 3.11
- name: Install Python dependencies
run: |
cd python
uv sync
- name: Lint Python code
run: |
cd python
uv run ruff check --output-format=github
uv run ruff format --check
- name: Test Python library
run: |
cd python
uv run pytest -v
generate-and-test-schema:
runs-on: ubuntu-latest
name: Test Schema Generation
needs: test-python
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "latest"
- name: Set up Python
run: uv python install 3.11
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install Python dependencies
run: |
cd python
uv sync
- name: Install TypeScript dependencies
run: |
cd typescript
npm ci
- name: Generate OpenAPI schema from Python models
run: |
cd python
uv run python ../scripts/generate_openapi.py
- name: Test schema generation
run: |
cd python
uv run pytest tests/test_schema_generation.py -v
- name: Generate TypeScript types from schema
run: |
cd typescript
npm run generate-types
- name: Test TypeScript generation
run: |
cd typescript
npm run test -- schema-generation.test.ts
- name: Upload schema artifacts
uses: actions/upload-artifact@v4
with:
name: generated-schema
path: |
schema/openapi.yaml
schema/openapi.json
typescript/src/generated/types.ts
retention-days: 7
test-typescript:
runs-on: ubuntu-latest
name: Test TypeScript Library
needs: generate-and-test-schema
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install uv (for schema generation)
uses: astral-sh/setup-uv@v3
with:
version: "latest"
- name: Set up Python (for schema generation)
run: uv python install 3.11
- name: Install Python dependencies (for schema generation)
run: |
cd python
uv sync
- name: Install TypeScript dependencies
run: |
cd typescript
npm ci
- name: Generate schema and types (needed for tests)
run: npm run sync
- name: Lint TypeScript code
run: |
cd typescript
npm run lint
- name: Type check TypeScript code
run: |
cd typescript
npm run type-check
- name: Test TypeScript library
run: |
cd typescript
npm test
- name: Build TypeScript library
run: |
cd typescript
npm run build
check-python-changes:
runs-on: ubuntu-latest
name: Check Python Changes Significance
outputs:
python_changed: ${{ steps.check_changes.outputs.python_changed }}
changes_significant: ${{ steps.check_changes.outputs.changes_significant }}
files_changed: ${{ steps.check_changes.outputs.files_changed }}
lines_changed: ${{ steps.check_changes.outputs.lines_changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2 # Need previous commit for comparison
- name: Check Python changes
id: check_changes
env:
FILES_THRESHOLD: ${{ secrets.AI_FILES_THRESHOLD || '3' }}
LINES_THRESHOLD: ${{ secrets.AI_LINES_THRESHOLD || '50' }}
run: |
# Check if any Python files changed
python_files=$(git diff --name-only HEAD~1 HEAD -- 'python/' | wc -l)
if [[ $python_files -eq 0 ]]; then
echo "python_changed=false" >> $GITHUB_OUTPUT
echo "changes_significant=false" >> $GITHUB_OUTPUT
echo "files_changed=0" >> $GITHUB_OUTPUT
echo "lines_changed=0" >> $GITHUB_OUTPUT
echo "πŸ“‹ No Python files changed"
exit 0
fi
echo "python_changed=true" >> $GITHUB_OUTPUT
# Count files and lines changed in entire python/ directory
files_changed=$(git diff --name-only HEAD~1 HEAD -- 'python/' | wc -l)
# Get total lines changed (insertions + deletions)
diff_stat=$(git diff --stat HEAD~1 HEAD -- 'python/' | tail -1)
lines_changed=0
if [[ $diff_stat =~ ([0-9]+)\ insertion ]]; then
insertions=${BASH_REMATCH[1]}
lines_changed=$((lines_changed + insertions))
fi
if [[ $diff_stat =~ ([0-9]+)\ deletion ]]; then
deletions=${BASH_REMATCH[1]}
lines_changed=$((lines_changed + deletions))
fi
echo "files_changed=$files_changed" >> $GITHUB_OUTPUT
echo "lines_changed=$lines_changed" >> $GITHUB_OUTPUT
# Determine if changes are significant using configurable thresholds
if [[ $files_changed -ge $FILES_THRESHOLD ]] || [[ $lines_changed -ge $LINES_THRESHOLD ]]; then
echo "changes_significant=true" >> $GITHUB_OUTPUT
echo "βœ… Changes are SIGNIFICANT: $files_changed files, $lines_changed lines (threshold: $FILES_THRESHOLD files OR $LINES_THRESHOLD lines)"
else
echo "changes_significant=false" >> $GITHUB_OUTPUT
echo "⚠️ Changes are minor: $files_changed files, $lines_changed lines (threshold: $FILES_THRESHOLD files OR $LINES_THRESHOLD lines)"
fi
echo "πŸ“Š Python change summary:" >> $GITHUB_STEP_SUMMARY
echo "- Files changed: $files_changed" >> $GITHUB_STEP_SUMMARY
echo "- Lines changed: $lines_changed" >> $GITHUB_STEP_SUMMARY
echo "- Thresholds: $FILES_THRESHOLD files OR $LINES_THRESHOLD lines" >> $GITHUB_STEP_SUMMARY
echo "- Significant for AI generation: $([ $files_changed -ge $FILES_THRESHOLD ] || [ $lines_changed -ge $LINES_THRESHOLD ] && echo 'YES' || echo 'NO')" >> $GITHUB_STEP_SUMMARY
- name: Save change detection results for AI workflow
run: |
mkdir -p change-detection-results
echo "python_changed=${{ steps.check_changes.outputs.python_changed }}" > change-detection-results/results.txt
echo "changes_significant=${{ steps.check_changes.outputs.changes_significant }}" >> change-detection-results/results.txt
echo "files_changed=${{ steps.check_changes.outputs.files_changed }}" >> change-detection-results/results.txt
echo "lines_changed=${{ steps.check_changes.outputs.lines_changed }}" >> change-detection-results/results.txt
- name: Upload change detection results
uses: actions/upload-artifact@v4
with:
name: change-detection-results
path: change-detection-results/results.txt
retention-days: 1
ai-sync-typescript:
runs-on: ubuntu-latest
name: AI Sync TypeScript (if significant changes)
needs: [check-python-changes, generate-and-test-schema]
if: needs.check-python-changes.outputs.changes_significant == 'true'
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 2
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: AI Generate TypeScript Updates
env:
CLAUDE_API_KEY: ${{ secrets.CLAUDE_AUTO_SYNC_KEY }}
AI_SYNC_ENABLED: ${{ secrets.AI_SYNC_ENABLED || 'true' }}
run: |
if [[ "$AI_SYNC_ENABLED" != "true" ]]; then
echo "🚫 AI sync disabled via AI_SYNC_ENABLED secret"
exit 0
fi
if [[ -z "$CLAUDE_API_KEY" ]]; then
echo "❌ CLAUDE_AUTO_SYNC_KEY not found - skipping AI generation"
echo "πŸ’‘ Add Claude API key as CLAUDE_AUTO_SYNC_KEY secret to enable"
exit 0
fi
echo "πŸ€– Running AI TypeScript generation..."
pip install httpx
python scripts/ai_generate_typescript.py
- name: Commit AI updates
run: |
if [[ -n $(git status --porcelain) ]]; then
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action AI"
git add typescript/src/
git commit -m "πŸ€– AI auto-sync: Update TypeScript implementation
Generated by Claude AI based on Python model changes.

Check failure on line 287 in .github/workflows/ci.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/ci.yml

Invalid workflow file

You have an error in your yaml syntax on line 287
Files changed: ${{ needs.check-python-changes.outputs.files_changed }}
Lines changed: ${{ needs.check-python-changes.outputs.lines_changed }}"
echo "βœ… AI updates committed"
else
echo "ℹ️ No TypeScript changes generated"
fi
test-typescript:
runs-on: ubuntu-latest
name: Test TypeScript Library
needs: [test-python, generate-and-test-schema, ai-sync-typescript]
if: always() && (needs.test-python.result == 'success' && needs.generate-and-test-schema.result == 'success')
steps:
- uses: actions/checkout@v4
integration-test:
runs-on: ubuntu-latest
name: Integration Tests
needs: [test-python, generate-and-test-schema, test-typescript, check-python-changes]
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "latest"
- name: Set up Python
run: uv python install 3.11
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install all dependencies
run: |
npm run install:python
npm run install:typescript
- name: Run full validation pipeline
run: npm run validate
- name: Build both libraries
run: npm run build
- name: Run all tests
run: npm test