-
Notifications
You must be signed in to change notification settings - Fork 61
427 lines (340 loc) · 16.3 KB
/
api-reference-sync.yml
File metadata and controls
427 lines (340 loc) · 16.3 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
name: API Reference Sync
on:
pull_request:
types: [closed]
permissions:
actions: read
contents: write
pull-requests: write
issues: write
id-token: write
concurrency:
group: api-reference-sync-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
jobs:
# ─── Job 0: Build API JSON at HEAD~1 and HEAD, diff them ─────────────
analyze:
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
runs-on: ubuntu-latest
outputs:
has_diff: ${{ steps.classify.outputs.has_diff }}
has_new: ${{ steps.classify.outputs.has_new }}
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v5
with:
node-version-file: '.nvmrc'
cache: pnpm
- name: Collect PR metadata
id: meta
env:
PR_TITLE: ${{ github.event.pull_request.title || 'manual run' }}
run: |
mkdir -p /tmp/api-sync
jq -n \
--arg number "${{ github.event.pull_request.number || '' }}" \
--arg url "${{ github.event.pull_request.html_url || '' }}" \
--arg author "${{ github.event.pull_request.user.login || '' }}" \
--arg title "$PR_TITLE" \
'{number: $number, url: $url, author: $author, title: $title}' \
> /tmp/api-sync/pr-meta.json
cat /tmp/api-sync/pr-meta.json
- name: Build API JSON at HEAD
run: |
pnpm install --frozen-lockfile
pnpm -C site api-docs
mkdir -p /tmp/api-sync/after-components /tmp/api-sync/after-utils
cp -r site/src/content/generated-component-reference/* /tmp/api-sync/after-components/ 2>/dev/null || true
cp -r site/src/content/generated-util-reference/* /tmp/api-sync/after-utils/ 2>/dev/null || true
- name: Build API JSON at HEAD~1
run: |
git checkout HEAD~1
# If install or build fails (e.g. api-docs-builder itself changed),
# treat everything as new by leaving before dirs empty
mkdir -p /tmp/api-sync/before-components /tmp/api-sync/before-utils
if pnpm install --frozen-lockfile && pnpm -C site api-docs; then
cp -r site/src/content/generated-component-reference/* /tmp/api-sync/before-components/ 2>/dev/null || true
cp -r site/src/content/generated-util-reference/* /tmp/api-sync/before-utils/ 2>/dev/null || true
else
echo "::warning::HEAD~1 build failed — treating all components/utils as new"
fi
git checkout -
- name: Classify changes
id: classify
run: |
# Unified diff of both JSON directories
diff -ruN /tmp/api-sync/before-components /tmp/api-sync/after-components > /tmp/api-sync/diff.patch || true
diff -ruN /tmp/api-sync/before-utils /tmp/api-sync/after-utils >> /tmp/api-sync/diff.patch || true
# New: files in after but not in before
comm -23 \
<(ls /tmp/api-sync/after-components/ 2>/dev/null | sort) \
<(ls /tmp/api-sync/before-components/ 2>/dev/null | sort) \
> /tmp/api-sync/new-components.txt
comm -23 \
<(ls /tmp/api-sync/after-utils/ 2>/dev/null | sort) \
<(ls /tmp/api-sync/before-utils/ 2>/dev/null | sort) \
> /tmp/api-sync/new-utils.txt
# Changed: files in both, but content differs
comm -12 \
<(ls /tmp/api-sync/after-components/ 2>/dev/null | sort) \
<(ls /tmp/api-sync/before-components/ 2>/dev/null | sort) \
| while read -r f; do
if ! diff -q "/tmp/api-sync/before-components/$f" "/tmp/api-sync/after-components/$f" >/dev/null 2>&1; then
echo "$f"
fi
done > /tmp/api-sync/changed-components.txt
comm -12 \
<(ls /tmp/api-sync/after-utils/ 2>/dev/null | sort) \
<(ls /tmp/api-sync/before-utils/ 2>/dev/null | sort) \
| while read -r f; do
if ! diff -q "/tmp/api-sync/before-utils/$f" "/tmp/api-sync/after-utils/$f" >/dev/null 2>&1; then
echo "$f"
fi
done > /tmp/api-sync/changed-utils.txt
# Log results
echo "=== New components ===" && cat /tmp/api-sync/new-components.txt
echo "=== New utils ===" && cat /tmp/api-sync/new-utils.txt
echo "=== Changed components ===" && cat /tmp/api-sync/changed-components.txt
echo "=== Changed utils ===" && cat /tmp/api-sync/changed-utils.txt
echo "=== Diff ===" && head -100 /tmp/api-sync/diff.patch
# Set outputs
if [ -s /tmp/api-sync/diff.patch ]; then
echo "has_diff=true" >> "$GITHUB_OUTPUT"
else
echo "has_diff=false" >> "$GITHUB_OUTPUT"
fi
if [ -s /tmp/api-sync/new-components.txt ] || [ -s /tmp/api-sync/new-utils.txt ]; then
echo "has_new=true" >> "$GITHUB_OUTPUT"
else
echo "has_new=false" >> "$GITHUB_OUTPUT"
fi
- name: Upload artifact
if: steps.classify.outputs.has_diff == 'true'
uses: actions/upload-artifact@v4
with:
name: api-diff
path: /tmp/api-sync/
retention-days: 1
# ─── Job 1: Open issues for new components/utils without reference pages
new-references:
needs: analyze
if: needs.analyze.outputs.has_new == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: api-diff
path: /tmp/api-sync
- name: Open issues for missing reference pages
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
PR_NUMBER=$(jq -r .number /tmp/api-sync/pr-meta.json)
PR_URL=$(jq -r .url /tmp/api-sync/pr-meta.json)
PR_AUTHOR=$(jq -r .author /tmp/api-sync/pr-meta.json)
REF_DIR="site/src/content/docs/reference"
# --- New components ---
if [ -s /tmp/api-sync/new-components.txt ]; then
while read -r filename; do
JSON_PATH="/tmp/api-sync/after-components/$filename"
NAME=$(jq -r .name "$JSON_PATH")
SLUG="${filename%.json}"
# Check if a reference page already uses this component
if grep -rq "<ComponentReference component=\"$NAME\"" "$REF_DIR/"; then
echo "Reference exists for component $NAME — skipping"
continue
fi
# Check for existing open issue (dedup by drift-type + component name)
EXISTING=$(gh issue list \
--label "docs" \
--search "docs(reference): add $NAME API reference page" \
--state open \
--json number \
--jq 'length')
if [ "$EXISTING" -gt 0 ]; then
echo "Open issue already exists for $NAME — skipping"
continue
fi
ASSIGNEE_FLAG=""
if [ -n "$PR_AUTHOR" ]; then
ASSIGNEE_FLAG="--assignee $PR_AUTHOR"
fi
BODY="$(cat <<EOF
<!-- drift-type:new-reference -->
<!-- trigger-pr:$PR_NUMBER -->
<!-- component:$NAME -->
## New Component: \`$NAME\`
A new component \`$NAME\` was added in #${PR_NUMBER} but has no API reference page yet.
### What's needed
- [ ] Create reference page with anatomy, prose, demos, and \`<ComponentReference component="$NAME" />\`
- [ ] Add sidebar entry in \`site/src/docs.config.ts\`
- [ ] Verify build: \`pnpm -C site build\`
### Context
- Triggering PR: $PR_URL
- Generated JSON: \`site/src/content/generated-component-reference/$filename\`
> Use the \`/api-reference $SLUG\` skill to scaffold this page.
EOF
)"
gh issue create \
--title "docs(reference): add $NAME API reference page" \
--body "$BODY" \
--label "docs,site,components" \
$ASSIGNEE_FLAG
echo "Created issue for component $NAME"
done < /tmp/api-sync/new-components.txt
fi
# --- New utils ---
if [ -s /tmp/api-sync/new-utils.txt ]; then
while read -r filename; do
JSON_PATH="/tmp/api-sync/after-utils/$filename"
NAME=$(jq -r .name "$JSON_PATH")
SLUG="${filename%.json}"
# Check if a reference page already uses this util
if grep -rq "<UtilReference util=\"$NAME\"" "$REF_DIR/"; then
echo "Reference exists for util $NAME — skipping"
continue
fi
# Check for existing open issue
EXISTING=$(gh issue list \
--label "docs" \
--search "docs(reference): add $NAME API reference page" \
--state open \
--json number \
--jq 'length')
if [ "$EXISTING" -gt 0 ]; then
echo "Open issue already exists for $NAME — skipping"
continue
fi
ASSIGNEE_FLAG=""
if [ -n "$PR_AUTHOR" ]; then
ASSIGNEE_FLAG="--assignee $PR_AUTHOR"
fi
BODY="$(cat <<EOF
<!-- drift-type:new-reference -->
<!-- trigger-pr:$PR_NUMBER -->
<!-- util:$NAME -->
## New Utility: \`$NAME\`
A new utility \`$NAME\` was added in #${PR_NUMBER} but has no API reference page yet.
### What's needed
- [ ] Create reference page with usage examples and \`<UtilReference util="$NAME" />\`
- [ ] Add sidebar entry in \`site/src/docs.config.ts\`
- [ ] Verify build: \`pnpm -C site build\`
### Context
- Triggering PR: $PR_URL
- Generated JSON: \`site/src/content/generated-util-reference/$filename\`
> Use the \`/api-reference $SLUG\` skill to scaffold this page.
EOF
)"
gh issue create \
--title "docs(reference): add $NAME API reference page" \
--body "$BODY" \
--label "docs,site" \
$ASSIGNEE_FLAG
echo "Created issue for util $NAME"
done < /tmp/api-sync/new-utils.txt
fi
# ─── Job 2: Detect stale docs (Claude Opus) ─────────────────────────
stale-docs:
needs: analyze
if: needs.analyze.outputs.has_diff == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: api-diff
path: /tmp/api-sync
- name: Detect stale docs
uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
claude_args: |
--model opus
--max-turns 25
--allowedTools "Read" "Glob" "Grep" "Bash(gh:*)" "Bash(cat:*)" "Bash(jq:*)" "Bash(diff:*)" "Bash(ls:*)" "Bash(head:*)" "Bash(tail:*)" "Bash(wc:*)" "Bash(sort:*)"
prompt: |
You are the stale-docs detection agent. Your job: given a pre-computed API diff,
find documentation that may need updating and open ONE GitHub issue summarizing all findings.
## Inputs
The following files are at /tmp/api-sync/:
- `diff.patch` — unified diff of API JSON between HEAD~1 and HEAD
- `changed-components.txt` — filenames of changed component JSONs (one per line, may be empty)
- `changed-utils.txt` — filenames of changed util JSONs (one per line, may be empty)
- `after-components/` — current component JSON files
- `after-utils/` — current util JSON files
- `pr-meta.json` — `{number, url, author, title}` of the triggering PR
Important: Focus on items in `changed-components.txt` and `changed-utils.txt`.
Skip any components/utils listed in `new-components.txt` or `new-utils.txt` —
a separate job already opens issues for those.
## Process
Step 1: Read `pr-meta.json` and `diff.patch`. Understand what API surfaces changed and how.
Step 2: For each changed component/util, read the "after" JSON to understand the current API shape.
Step 3: Search for documentation that references these APIs. Check ALL of:
- `site/src/content/docs/reference/` — MDX reference pages (look for stale prop descriptions,
missing new props/state/data-attributes, outdated type signatures)
- `site/src/content/docs/concepts/` — concept pages mentioning these APIs
- `site/src/content/docs/how-to/` — how-to guides mentioning these APIs
- `site/src/components/docs/demos/` — demo code using changed props/state/signatures
- `packages/*/README.md` — package READMEs mentioning these APIs
Use Grep and Glob to search efficiently. Look for:
- The component/util name (PascalCase, camelCase)
- Specific prop/state/parameter names that were added, removed, or changed in the diff
- HTML element names from `platforms.html.tagName` in the JSON (e.g. `media-play-button`)
- Data attribute names that changed
Step 4: For each file with hits, read the relevant section and assess:
- `high` — definitely stale (references a removed/renamed prop by old name, shows old signature)
- `medium` — likely stale (mentions API whose behavior/type changed)
- `low` — possibly stale (mentions the component but may not be affected)
Discard clear false positives. Include borderline cases for human review.
Step 5: If you found ANY stale references, open exactly ONE issue using `gh issue create`.
If you found NOTHING stale, do NOT create an issue — just output "No stale docs detected."
## Issue format
Read `pr-meta.json` to get PR_NUMBER, PR_URL, PR_AUTHOR, and PR_TITLE.
Assign the issue to the PR author: `--assignee $PR_AUTHOR` (skip if author is empty).
Title: `docs(site): stale docs from #$PR_NUMBER`
Labels: `docs,site`
Body (use this structure exactly):
```
<!-- drift-type:stale-docs -->
<!-- trigger-pr:{PR_NUMBER} -->
## Summary
API changes in #{PR_NUMBER} ({PR_TITLE}) may have made the following documentation stale.
## Triggering PR
{PR_URL}
## API Changes
{Brief summary of what changed in the API — new props, removed props, type changes, etc.}
## Stale Documentation Found
### High Confidence
| File | Line(s) | Issue | API Change |
|---|---|---|---|
{rows or "None found"}
### Medium Confidence
| File | Line(s) | Issue | API Change |
|---|---|---|---|
{rows or "None found"}
### Low Confidence
| File | Line(s) | Issue | API Change |
|---|---|---|---|
{rows or "None found"}
## Recommended Actions
{Bulleted list of specific things to fix}
```
## Rules
- Open at most ONE issue per run. Group everything into one issue.
- Do NOT create or modify any files. Do NOT create PRs. Issues only.
- Do NOT open an issue if there is nothing stale.
- Before creating an issue, check for existing open issues that have BOTH
`<!-- drift-type:stale-docs -->` and `<!-- trigger-pr:{PR_NUMBER} -->` in their body.
If one exists, skip creation to avoid duplicates.
- Be thorough but efficient — use Grep to find files, then Read only relevant sections.