-
Notifications
You must be signed in to change notification settings - Fork 1
110 lines (98 loc) · 4.47 KB
/
api-sync.yml
File metadata and controls
110 lines (98 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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/changelog.md > /tmp/api-sync/changelog.md
echo "=== Changelog ==="
cat /tmp/api-sync/changelog.md
- 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: '--model claude-sonnet-4-20250514 --allowedTools "Bash(*),Read,Edit,Write,Glob,Grep"'
prompt: |
You are updating this SDK to match API changes. Read CLAUDE.md for this SDK's conventions.
The changelog is at /tmp/api-sync/changelog.md — it contains ALL the information you need.
Do NOT read openapi.json. The changelog is self-contained.
INSTRUCTIONS:
1. Read CLAUDE.md thoroughly for this SDK's patterns and conventions.
2. Read /tmp/api-sync/changelog.md — it lists every enum type with every value, every field to add, and every change to make.
3. Implement ALL changes. Go through the changelog section by section:
- Section 1 (Enum Types): For each enum listed, check if the SDK has it. If missing, create it. If it exists, add any missing values. The changelog lists ALL values — add the ones that don't exist yet.
- Section 2 (Receiver Fields): Add each listed field to the receiver input/output types.
- Section 3 (Version): Minor bump.
4. Do not skip ANY enum or field. Every item in the changelog must be addressed.
5. Follow CLAUDE.md patterns exactly for naming, typing, and file organization.
6. MINOR version bump only.
7. Run lint and type check commands (see CLAUDE.md). Fix any errors until clean.
8. 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