Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/sdk-codegen-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: SDK Codegen Check

# Lightweight check that runs on every PR to ensure types are in sync
# The full sdk-codegen.yml workflow handles generation and auto-commit

on:
pull_request:
paths:
- 'django-backend/soroscan/ingest/schema.py'
- 'sdk/typescript/src/generated/**'
- 'sdk/python/soroscan/generated/**'

jobs:
check-types-in-sync:
name: Check Generated Types Are In Sync
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Check if generated files exist
id: check_files
run: |
if [ ! -d "sdk/typescript/src/generated" ] || [ ! -d "sdk/python/soroscan/generated" ]; then
echo "exists=false" >> $GITHUB_OUTPUT
echo "⚠️ Generated type directories don't exist"
else
echo "exists=true" >> $GITHUB_OUTPUT
echo "✅ Generated type directories exist"
fi

- name: Warn if types missing
if: steps.check_files.outputs.exists == 'false'
run: |
echo "::warning::Generated SDK types are missing. Run 'cd sdk/codegen && npm run generate' to create them."
echo ""
echo "This is expected for new repositories. The full sdk-codegen workflow will generate them."

- name: Check for manual edits to generated files
if: steps.check_files.outputs.exists == 'true'
run: |
# Check if generated files have the auto-generated warning
if grep -r "DO NOT EDIT MANUALLY" sdk/typescript/src/generated/ sdk/python/soroscan/generated/ > /dev/null 2>&1; then
echo "✅ Generated files have proper warnings"
else
echo "::warning::Some generated files may be missing auto-generated warnings"
fi

- name: Provide instructions
if: failure()
run: |
echo "::error::Generated types check failed!"
echo ""
echo "To fix this:"
echo "1. cd sdk/codegen"
echo "2. npm install"
echo "3. npm run generate"
echo "4. git add sdk/typescript/src/generated/ sdk/python/soroscan/generated/"
echo "5. git commit -m 'chore: regenerate SDK types'"
echo ""
echo "See sdk/CODEGEN_GUIDE.md for more details."
168 changes: 168 additions & 0 deletions .github/workflows/sdk-codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: SDK Code Generation

on:
push:
branches: [main, develop]
paths:
- 'django-backend/soroscan/ingest/schema.py'
- 'sdk/codegen/**'
pull_request:
paths:
- 'django-backend/soroscan/ingest/schema.py'
- 'sdk/codegen/**'
workflow_dispatch:

jobs:
generate-types:
name: Generate SDK Types
runs-on: ubuntu-latest

services:
postgres:
image: postgres:15
env:
POSTGRES_DB: soroscan_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

redis:
image: redis:7-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'

- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 8

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install Python dependencies
working-directory: django-backend
run: |
pip install -r requirements.txt

- name: Run Django migrations
working-directory: django-backend
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/soroscan_test
REDIS_URL: redis://localhost:6379/0
SECRET_KEY: test-secret-key-for-ci
DEBUG: 'True'
run: |
python manage.py migrate --noinput

- name: Start Django server
working-directory: django-backend
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/soroscan_test
REDIS_URL: redis://localhost:6379/0
SECRET_KEY: test-secret-key-for-ci
DEBUG: 'True'
run: |
python manage.py runserver 8000 &
echo $! > django.pid
# Wait for server to be ready
timeout 30 bash -c 'until curl -f http://localhost:8000/health/ 2>/dev/null; do sleep 1; done'

- name: Install codegen dependencies
working-directory: sdk/codegen
run: pnpm install

- name: Generate SDK types
working-directory: sdk/codegen
env:
GRAPHQL_ENDPOINT: http://localhost:8000/graphql/
run: pnpm run generate

- name: Check for changes
id: check_changes
run: |
if git diff --quiet sdk/typescript/src/generated/ sdk/python/soroscan/generated/; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi

- name: Show diff
if: steps.check_changes.outputs.changed == 'true'
run: |
echo "::group::Generated type changes"
git diff sdk/typescript/src/generated/ sdk/python/soroscan/generated/
echo "::endgroup::"

- name: Verify TypeScript SDK
working-directory: sdk/typescript
run: |
pnpm install
pnpm run build
pnpm test

- name: Verify Python SDK
working-directory: sdk/python
run: |
pip install -e .
pip install pytest pytest-cov
pytest

- name: Fail if types are out of sync (PR only)
if: github.event_name == 'pull_request' && steps.check_changes.outputs.changed == 'true'
run: |
echo "❌ Generated types are out of sync with schema!"
echo "Please run 'cd sdk/codegen && pnpm run generate' and commit the changes."
exit 1

- name: Commit and push changes (main/develop only)
if: github.event_name == 'push' && steps.check_changes.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add sdk/typescript/src/generated/ sdk/python/soroscan/generated/
git commit -m "chore: regenerate SDK types from schema [skip ci]"
git push

- name: Stop Django server
if: always()
working-directory: django-backend
run: |
if [ -f django.pid ]; then
kill $(cat django.pid) || true
rm django.pid
fi

- name: Upload generated types as artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: generated-types
path: |
sdk/typescript/src/generated/
sdk/python/soroscan/generated/
retention-days: 7
Loading
Loading