TypeScript library Generation #22
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, ai-sync-typescript] | |
| if: always() && needs.generate-and-test-schema.result == 'success' | |
| 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 - ${{ needs.check-python-changes.outputs.files_changed }} files, ${{ needs.check-python-changes.outputs.lines_changed }} lines changed" | |
| echo "β AI updates committed" | |
| else | |
| echo "βΉοΈ No TypeScript changes generated" | |
| fi | |
| 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 |