Skip to content

api-sync

api-sync #13

Workflow file for this run

name: API Sync
on:
repository_dispatch:
types: [api-sync]
permissions:
contents: write
pull-requests: write
id-token: write
jobs:
sync:
name: Sync SDK with API changes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Fetch API sync data
run: |
mkdir -p /tmp/api-sync
git fetch origin api-sync-data
git show origin/api-sync-data:.api-sync/openapi.json > /tmp/api-sync/openapi.json
git show origin/api-sync-data:.api-sync/changed_paths.json > /tmp/api-sync/changed_paths.json
echo "Changed paths:"
cat /tmp/api-sync/changed_paths.json
- name: Check for existing api-sync PR
id: check-pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=$(gh pr list --head api-sync --json number --jq '.[0].number // empty')
if [ -n "$PR_NUMBER" ]; then
echo "existing_pr=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "Found existing api-sync PR: #$PR_NUMBER"
else
echo "existing_pr=" >> $GITHUB_OUTPUT
echo "No existing api-sync PR found"
fi
- name: Create or checkout api-sync branch
run: |
git fetch origin api-sync 2>/dev/null || true
if git rev-parse --verify origin/api-sync >/dev/null 2>&1; then
git checkout api-sync
git reset --hard origin/main
else
git checkout -b api-sync
fi
- name: Apply changes with Claude Code
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
claude_args: '--allowedTools "Bash(*),Read,Edit,Write,Glob,Grep"'
prompt: |
You are updating this SDK to match API changes. Read CLAUDE.md for codebase standards.
The changed API paths are listed in /tmp/api-sync/changed_paths.json — these indicate which resource(s) changed.
The full current OpenAPI spec is at /tmp/api-sync/openapi.json
Instructions:
1. Read CLAUDE.md thoroughly — it contains all patterns and conventions for this SDK.
2. Read the changed paths to identify which resource(s) were affected.
3. For each affected resource, find ALL related paths in the OpenAPI spec (e.g. if /sandbox changed, also include /sandbox/{id}). Implement every endpoint for the resource, not just the literally changed path.
4. Only process paths where x-sdk is true in the OpenAPI spec.
5. Apply the changes following CLAUDE.md patterns exactly.
6. If adding a new resource: create the resource file with ALL endpoints (list, get, create, update, delete, etc.), register in client, add exports.
7. If modifying types: update the type definitions to match new schemas.
8. If removing a resource: delete files, remove registrations.
9. Bump the version following CLAUDE.md versioning rules and semver.
10. As a final step, run the project's full lint and type check commands (check CLAUDE.md for the exact commands). If ANY errors exist in files you created or modified, fix them. Repeat until all checks pass cleanly. Do not finish until zero errors.
11. Do NOT create commits — just modify the files.
- name: Commit and push
id: commit
run: |
git remote set-url origin "https://x-access-token:${{ secrets.SDK_SYNC_PAT }}@github.com/${{ github.repository }}.git"
git checkout -- .github/workflows/ 2>/dev/null || true
git add -A
git reset HEAD .github/workflows/ 2>/dev/null || true
if git diff --staged --quiet; then
echo "No changes to commit"
echo "has_changes=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "has_changes=true" >> $GITHUB_OUTPUT
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "feat: sync SDK with API changes"
git push --force-with-lease origin api-sync
- name: Create or update PR
if: steps.commit.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.SDK_SYNC_PAT }}
run: |
EXISTING_PR="${{ steps.check-pr.outputs.existing_pr }}"
if [ -n "$EXISTING_PR" ]; then
echo "Updating existing PR #$EXISTING_PR"
gh pr comment "$EXISTING_PR" --body "Updated with latest API changes."
else
gh pr create \
--title "feat: sync SDK with API changes" \
--body "Automated SDK update from API changes." \
--base main \
--head api-sync \
--label api-sync
fi