Skip to content

api-sync

api-sync #8

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
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 diff payload to understand what changed (new paths, modified schemas, removed paths).
3. Only process paths where x-sdk is true in the OpenAPI spec.
4. Apply the changes following CLAUDE.md patterns exactly.
5. If adding a new resource: create the resource file, register in client, add exports.
6. If modifying types: update the type definitions to match new schemas.
7. If removing a resource: delete files, remove registrations.
8. Bump the version following CLAUDE.md versioning rules and semver.
9. Run lint and type checking. Fix any errors.
10. 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