Skip to content

More fake utilities to force AI generation of code #23

More fake utilities to force AI generation of code

More fake utilities to force AI generation of code #23

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, 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'
permissions:
contents: write
pull-requests: write
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: Create PR for AI updates
run: |
# Check if TypeScript files were actually modified
if [[ -n $(git status --porcelain typescript/src/) ]]; then
# Create a new branch for the AI changes
BRANCH_NAME="ai-sync-$(date +%Y%m%d-%H%M%S)"
git checkout -b "$BRANCH_NAME"
# Configure git
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action AI"
# Add and commit changes
git add typescript/src/ ai_updates.json python_changes.md 2>/dev/null || true
git commit -m "πŸ€– AI auto-sync: Update TypeScript implementation
Python changes detected:
- ${{ needs.check-python-changes.outputs.files_changed }} files changed
- ${{ needs.check-python-changes.outputs.lines_changed }} lines modified
Generated TypeScript updates to maintain API compatibility.
πŸ€– Generated with Claude AI"
# Push the new branch
git push origin "$BRANCH_NAME"
# Create pull request using gh CLI
gh pr create \
--title "πŸ€– AI Auto-sync: TypeScript Updates (${{ needs.check-python-changes.outputs.files_changed }} files, ${{ needs.check-python-changes.outputs.lines_changed }} lines)" \
--body "$(cat <<'EOF'
## πŸ€– Automated TypeScript Sync
This PR contains AI-generated TypeScript implementation updates based on recent Python model changes.
### Python Changes Summary
- **Files changed:** ${{ needs.check-python-changes.outputs.files_changed }}
- **Lines modified:** ${{ needs.check-python-changes.outputs.lines_changed }}
### AI Analysis
See attached `ai_updates.json` and `python_changes.md` for detailed analysis.
### Review Instructions
1. Verify TypeScript changes align with Python model updates
2. Test the generated TypeScript client functionality
3. Check for any breaking changes in the API
4. Ensure all tests pass before merging
πŸ€– Generated with [Claude AI](https://claude.ai/code) auto-sync workflow
EOF
)" \
--head "$BRANCH_NAME" \
--base develop
echo "βœ… Created PR for AI-generated TypeScript updates"
else
echo "ℹ️ No TypeScript files were modified by AI generation"
# Still commit analysis files to current branch for record keeping
if [[ -f ai_updates.json ]] || [[ -f python_changes.md ]]; then
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action AI"
git add ai_updates.json python_changes.md 2>/dev/null || true
if git commit -m "πŸ€– AI analysis completed (no TypeScript changes needed)" 2>/dev/null; then
git push origin develop
echo "βœ… Analysis files committed to develop branch"
else
echo "ℹ️ No changes to commit"
fi
else
echo "ℹ️ No analysis files generated"
fi
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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