-
Notifications
You must be signed in to change notification settings - Fork 0
436 lines (352 loc) · 15.7 KB
/
spec-create.yml
File metadata and controls
436 lines (352 loc) · 15.7 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
428
429
430
431
432
433
434
435
436
name: "Spec: Create"
run-name: "Create Spec: ${{ github.event.issue.title }}"
# Creates new specification with approval gate
# Flow:
# 1. User adds `spec-request` label → creates branch + PR
# 2. Maintainer adds `approved` label → merges PR to main
#
# Triggers:
# - spec-request label added → create specification + PR
# - approved label added (on spec-request issue) → merge PR
on:
issues:
types: [labeled]
concurrency:
group: spec-create-${{ github.event.issue.number }}
cancel-in-progress: false
jobs:
# ============================================================================
# Job 1: Create specification (triggered by spec-request label)
# ============================================================================
create:
if: github.event.label.name == 'spec-request'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
outputs:
specification_id: ${{ steps.process.outputs.specification_id }}
branch: ${{ steps.process.outputs.branch }}
pr_number: ${{ steps.pr.outputs.pr_number }}
steps:
- name: Check if already processed
id: check
env:
ISSUE_TITLE: ${{ github.event.issue.title }}
run: |
# Skip if already has specification-id in title
if [[ "$ISSUE_TITLE" =~ ^\[[a-z0-9-]+\] ]]; then
echo "::notice::Skipping: Issue already has specification ID in title"
echo "should_run=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "should_run=true" >> $GITHUB_OUTPUT
- name: Checkout repository
if: steps.check.outputs.should_run == 'true'
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: React with eyes emoji
if: steps.check.outputs.should_run == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/reactions \
-f content=eyes
- name: Process with Claude
if: steps.check.outputs.should_run == 'true'
id: process
continue-on-error: true
timeout-minutes: 30
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
claude_args: "--model opus"
prompt: |
## Task: Create New Specification
You are creating a new plot specification.
### Issue Details
- **Title:** ${{ github.event.issue.title }}
- **Number:** #${{ github.event.issue.number }}
- **Author:** ${{ github.event.issue.user.login }}
- **Body:**
```
${{ github.event.issue.body }}
```
---
## Instructions
1. **Read the rules:** `prompts/spec-id-generator.md`
2. **Check for duplicates:**
- List all existing specs: `ls plots/`
- Read existing specification files if titles seem similar
- If duplicate found: Post comment explaining which spec matches, then STOP
3. **Generate specification-id:**
- Format: `{type}-{variant}` or `{type}-{variant}-{modifier}`
- Examples: `scatter-basic`, `bar-grouped-horizontal`, `heatmap-correlation`
- All lowercase, hyphens only
4. **Create specification branch:**
```bash
git checkout -b "specification/{specification-id}"
```
5. **Post analysis comment:**
Post a SHORT comment (max 3-4 sentences) to the issue using `gh issue comment`:
- Is this a valid/useful plot type?
- Does it already exist? (check `ls plots/`)
- Any concerns?
6. **Create specification files:**
- Read template: `prompts/templates/specification.md`
- Read metadata template: `prompts/templates/specification.yaml`
- Create directory: `plots/{specification-id}/`
- Create: `plots/{specification-id}/specification.md` (follow template structure)
- Create: `plots/{specification-id}/specification.yaml` with:
- `specification_id`: the generated id
- `title`: a proper title
- `created`: Use `$(date -u +"%Y-%m-%dT%H:%M:%SZ")` for current timestamp
- `issue`: ${{ github.event.issue.number }}
- `suggested`: ${{ github.event.issue.user.login }}
- `tags`: appropriate tags for this plot type
- Create empty folder: `plots/{specification-id}/implementations/`
- Create empty folder: `plots/{specification-id}/metadata/`
7. **Commit and push:**
```bash
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add plots/{specification-id}/
git commit -m "spec: add {specification-id} specification
Created from issue #${{ github.event.issue.number }}"
git push -u origin "specification/{specification-id}"
```
8. **Update issue title:**
```bash
gh issue edit ${{ github.event.issue.number }} --title "[{specification-id}] {original title}"
```
9. **Output for workflow:**
After completing, print these lines exactly:
```
SPECIFICATION_ID={specification-id}
BRANCH=specification/{specification-id}
```
---
## Important Rules
- Do NOT create a PR (the workflow does that)
- Do NOT add labels
- Do NOT close the issue
- STOP after pushing the branch
- name: Retry Claude (on failure)
if: steps.check.outputs.should_run == 'true' && steps.process.outcome == 'failure'
id: process_retry
timeout-minutes: 30
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
claude_args: "--model opus"
prompt: |
## Task: Create New Specification
You are creating a new plot specification.
### Issue Details
- **Title:** ${{ github.event.issue.title }}
- **Number:** #${{ github.event.issue.number }}
- **Author:** ${{ github.event.issue.user.login }}
- **Body:**
```
${{ github.event.issue.body }}
```
---
## Instructions
1. **Read the rules:** `prompts/spec-id-generator.md`
2. **Check for duplicates:**
- List all existing specs: `ls plots/`
- Read existing specification files if titles seem similar
- If duplicate found: Post comment explaining which spec matches, then STOP
3. **Generate specification-id:**
- Format: `{type}-{variant}` or `{type}-{variant}-{modifier}`
- Examples: `scatter-basic`, `bar-grouped-horizontal`, `heatmap-correlation`
- All lowercase, hyphens only
4. **Create specification branch:**
```bash
git checkout -b "specification/{specification-id}"
```
5. **Post analysis comment:**
Post a SHORT comment (max 3-4 sentences) to the issue using `gh issue comment`:
- Is this a valid/useful plot type?
- Does it already exist? (check `ls plots/`)
- Any concerns?
6. **Create specification files:**
- Read template: `prompts/templates/specification.md`
- Read metadata template: `prompts/templates/specification.yaml`
- Create directory: `plots/{specification-id}/`
- Create: `plots/{specification-id}/specification.md` (follow template structure)
- Create: `plots/{specification-id}/specification.yaml` with:
- `specification_id`: the generated id
- `title`: a proper title
- `created`: Use `$(date -u +"%Y-%m-%dT%H:%M:%SZ")` for current timestamp
- `issue`: ${{ github.event.issue.number }}
- `suggested`: ${{ github.event.issue.user.login }}
- `tags`: appropriate tags for this plot type
- Create empty folder: `plots/{specification-id}/implementations/`
- Create empty folder: `plots/{specification-id}/metadata/`
7. **Commit and push:**
```bash
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add plots/{specification-id}/
git commit -m "spec: add {specification-id} specification
Created from issue #${{ github.event.issue.number }}"
git push -u origin "specification/{specification-id}"
```
8. **Update issue title:**
```bash
gh issue edit ${{ github.event.issue.number }} --title "[{specification-id}] {original title}"
```
9. **Output for workflow:**
After completing, print these lines exactly:
```
SPECIFICATION_ID={specification-id}
BRANCH=specification/{specification-id}
```
---
## Important Rules
- Do NOT create a PR (the workflow does that)
- Do NOT add labels
- Do NOT close the issue
- STOP after pushing the branch
- name: Extract outputs
if: steps.check.outputs.should_run == 'true'
id: extract
run: |
# Extract specification ID from issue title (now updated by Claude)
TITLE=$(gh issue view ${{ github.event.issue.number }} --json title -q .title)
SPEC_ID=$(echo "$TITLE" | sed -n 's/^\[\([a-z0-9-]*\)\].*/\1/p')
if [[ -z "$SPEC_ID" ]]; then
echo "::error::Could not extract specification ID from title: $TITLE"
exit 1
fi
echo "specification_id=$SPEC_ID" >> $GITHUB_OUTPUT
echo "branch=specification/$SPEC_ID" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Pull Request
if: steps.check.outputs.should_run == 'true'
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SPEC_ID: ${{ steps.extract.outputs.specification_id }}
run: |
# Read the specification content for PR body
SPEC_CONTENT=$(cat "plots/${SPEC_ID}/specification.md")
PR_URL=$(gh pr create \
--base main \
--head "specification/${SPEC_ID}" \
--title "spec: add ${SPEC_ID} specification" \
--body "$(cat <<EOF
## New Specification: \`${SPEC_ID}\`
Related to #${{ github.event.issue.number }}
---
### specification.md
${SPEC_CONTENT}
---
**Next:** Add \`approved\` label to the issue to merge this PR.
---
:robot: *[spec-create workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})*
EOF
)")
PR_NUMBER=$(echo "$PR_URL" | grep -oE '[0-9]+$')
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
- name: Comment on issue
if: steps.check.outputs.should_run == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SPEC_ID: ${{ steps.extract.outputs.specification_id }}
PR_NUMBER: ${{ steps.pr.outputs.pr_number }}
run: |
SPEC_CONTENT=$(cat "plots/${SPEC_ID}/specification.md")
gh issue comment ${{ github.event.issue.number }} --body "$(cat <<EOF
## :white_check_mark: Specification Ready: \`${SPEC_ID}\`
**PR:** #${PR_NUMBER}
---
### specification.md
${SPEC_CONTENT}
---
**Next:** Add \`approved\` label to merge this specification to main.
---
:robot: *[spec-create workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})*
EOF
)"
- name: Add rocket reaction on success
if: steps.check.outputs.should_run == 'true' && success()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/reactions \
-f content=rocket
# ============================================================================
# Job 2: Merge specification (triggered by approved label)
# ============================================================================
merge:
if: >
github.event.label.name == 'approved' &&
contains(github.event.issue.labels.*.name, 'spec-request')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract specification ID
id: extract
env:
ISSUE_TITLE: ${{ github.event.issue.title }}
run: |
SPEC_ID=$(echo "$ISSUE_TITLE" | sed -n 's/^\[\([a-z0-9-]*\)\].*/\1/p')
if [[ -z "$SPEC_ID" ]]; then
echo "::error::Could not extract specification ID from title: $ISSUE_TITLE"
exit 1
fi
echo "specification_id=$SPEC_ID" >> $GITHUB_OUTPUT
- name: Find and merge PR
id: merge
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SPEC_ID: ${{ steps.extract.outputs.specification_id }}
run: |
# Find PR for this specification
PR_NUMBER=$(gh pr list --head "specification/${SPEC_ID}" --json number -q '.[0].number')
if [[ -z "$PR_NUMBER" ]]; then
echo "::error::No PR found for branch specification/${SPEC_ID}"
exit 1
fi
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
# Merge the PR
gh pr merge "$PR_NUMBER" --squash --delete-branch
echo "::notice::Merged PR #$PR_NUMBER for specification ${SPEC_ID}"
- name: Update issue labels
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Remove trigger, add status
gh issue edit ${{ github.event.issue.number }} --remove-label "spec-request" 2>/dev/null || true
gh issue edit ${{ github.event.issue.number }} --add-label "spec-ready"
- name: Comment on issue
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SPEC_ID: ${{ steps.extract.outputs.specification_id }}
PR_NUMBER: ${{ steps.merge.outputs.pr_number }}
run: |
gh issue comment ${{ github.event.issue.number }} --body "$(cat <<EOF
## :rocket: Specification Merged!
**Specification:** \`${SPEC_ID}\`
**PR:** #${PR_NUMBER} (merged)
The specification is now in \`main\` and synced to PostgreSQL.
---
**Next:** Add \`generate:{library}\` labels to start generating implementations.
Available libraries: \`matplotlib\`, \`seaborn\`, \`plotly\`, \`bokeh\`, \`altair\`, \`plotnine\`, \`pygal\`, \`highcharts\`, \`letsplot\`
Or use workflow dispatch for bulk operations.
---
:robot: *[spec-create workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})*
EOF
)"