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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
162 changes: 162 additions & 0 deletions .github/workflows/auto-update-sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
name: Auto-Update SDK

on:
schedule:
# Run daily at 2am UTC
- cron: '0 2 * * *'
workflow_dispatch: # Allow manual triggering

permissions:
contents: write
pull-requests: write

jobs:
check-schema:
name: Check for Schema Changes
runs-on: ubuntu-latest
outputs:
has-changes: ${{ steps.check.outputs.has-changes }}
breaking: ${{ steps.check.outputs.breaking }}
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
with:
version: 8

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Generate coverage report
id: coverage
run: |
pnpm run codegen:coverage || echo "coverage-failed=true" >> $GITHUB_OUTPUT
continue-on-error: true

- name: Check for changes
id: check
run: |
if [ -f .sdk/coverage.json ]; then
NEW_OPS=$(jq -r '.newOperations' .sdk/coverage.json)
MODIFIED_OPS=$(jq -r '.modifiedOperations' .sdk/coverage.json)
REMOVED_OPS=$(jq -r '.removedOperations' .sdk/coverage.json)
BREAKING=$(jq -r '.breaking' .sdk/coverage.json)

TOTAL_CHANGES=$((NEW_OPS + MODIFIED_OPS + REMOVED_OPS))

if [ $TOTAL_CHANGES -gt 0 ]; then
echo "has-changes=true" >> $GITHUB_OUTPUT
echo "breaking=$BREAKING" >> $GITHUB_OUTPUT
echo "::notice::Found $TOTAL_CHANGES changes in GraphQL schema"
else
echo "has-changes=false" >> $GITHUB_OUTPUT
echo "::notice::No changes detected in GraphQL schema"
fi
else
echo "has-changes=false" >> $GITHUB_OUTPUT
echo "::warning::No coverage report generated"
fi

- name: Upload coverage report
if: steps.check.outputs.has-changes == 'true'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: .sdk/

update-sdk:
name: Update SDK
needs: check-schema
if: needs.check-schema.outputs.has-changes == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
with:
version: 8

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report
path: .sdk/

- name: Generate SDK
run: pnpm run codegen

- name: Run typecheck
run: pnpm run typecheck

- name: Run tests
run: pnpm run test --run

- name: Format code
run: pnpm run format:fix

- name: Read coverage report
id: coverage
run: |
if [ -f .sdk/COVERAGE.md ]; then
# Escape newlines and special characters for GitHub Actions
REPORT=$(cat .sdk/COVERAGE.md)
echo "report<<EOF" >> $GITHUB_OUTPUT
echo "$REPORT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: auto-update SDK from GraphQL schema changes'
title: 'πŸ€– Auto-update SDK - Schema Changes Detected'
body: |
This PR was automatically generated by the SDK auto-update workflow.

## Schema Changes

${{ steps.coverage.outputs.report }}

---

### Checklist
- [ ] Review the changes carefully
- [ ] Verify tests are passing
- [ ] Update CHANGELOG.md if needed
- [ ] Check for any breaking changes

**Note**: This PR was generated on ${{ github.run_id }}
branch: auto-update/sdk-${{ github.run_number }}
delete-branch: true
labels: |
auto-update
${{ needs.check-schema.outputs.breaking == 'true' && 'breaking-change' || 'enhancement' }}

- name: Comment on PR if breaking
if: needs.check-schema.outputs.breaking == 'true'
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '⚠️ **Breaking changes detected!** Please review this PR carefully before merging.'
})

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ package-lock.json
docs

# cache
.eslintcache
.eslintcache

# SDK generation cache and reports (generated files are committed)
.sdk/
Loading