-
Notifications
You must be signed in to change notification settings - Fork 0
348 lines (278 loc) · 11.8 KB
/
spec-update.yml
File metadata and controls
348 lines (278 loc) · 11.8 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
name: "Spec: Update"
run-name: "Update Spec: ${{ github.event.issue.title }}"
# Updates existing specification
# Flow:
# 1. User adds `spec-update` label → analyzes and creates PR with updates
# 2. Maintainer adds `approved` label → merges PR to main
#
# Issue title format: [specification-id] Update: description
on:
issues:
types: [labeled]
concurrency:
group: spec-update-${{ github.event.issue.number }}
cancel-in-progress: false
jobs:
# ============================================================================
# Job 1: Analyze and update specification
# ============================================================================
update:
if: github.event.label.name == 'spec-update'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
steps:
- name: Extract specification ID
id: extract
env:
ISSUE_TITLE: ${{ github.event.issue.title }}
run: |
# Title format: [specification-id] ...
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. Expected format: [specification-id] ..."
exit 1
fi
echo "specification_id=$SPEC_ID" >> $GITHUB_OUTPUT
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Verify specification exists
id: verify
env:
SPEC_ID: ${{ steps.extract.outputs.specification_id }}
run: |
if [[ ! -f "plots/${SPEC_ID}/specification.md" ]]; then
echo "::error::Specification not found: plots/${SPEC_ID}/specification.md"
exit 1
fi
echo "exists=true" >> $GITHUB_OUTPUT
- name: React with eyes emoji
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/reactions \
-f content=eyes
- name: Process update with Claude
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: Update Existing Specification
You are updating an existing plot specification.
### Issue Details
- **Title:** ${{ github.event.issue.title }}
- **Number:** #${{ github.event.issue.number }}
- **Specification ID:** ${{ steps.extract.outputs.specification_id }}
- **Body:**
```
${{ github.event.issue.body }}
```
---
## Instructions
1. **Read current specification:**
- `plots/${{ steps.extract.outputs.specification_id }}/specification.md`
- `plots/${{ steps.extract.outputs.specification_id }}/specification.yaml`
2. **Post analysis comment:**
Post a SHORT comment (max 3-4 sentences) to the issue using `gh issue comment`:
- Is this a valid/useful change?
- What will be modified?
- Any concerns?
3. **Create update branch:**
```bash
git checkout -b "specification/${{ steps.extract.outputs.specification_id }}-update"
```
4. **Apply updates:**
- Modify `plots/${{ steps.extract.outputs.specification_id }}/specification.md` as needed
- Update `plots/${{ steps.extract.outputs.specification_id }}/specification.yaml`:
- Add entry to `history` array with:
- `date`: current timestamp (ISO 8601 format)
- `issue`: ${{ github.event.issue.number }}
- `changes`: brief description of what changed
5. **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/${{ steps.extract.outputs.specification_id }}/
git commit -m "spec: update ${{ steps.extract.outputs.specification_id }}
Updated from issue #${{ github.event.issue.number }}"
git push -u origin "specification/${{ steps.extract.outputs.specification_id }}-update"
```
---
## Important Rules
- Do NOT create a PR (the workflow does that)
- Do NOT add labels
- STOP after pushing the branch
- name: Retry Claude (on failure)
if: 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: Update Existing Specification
You are updating an existing plot specification.
### Issue Details
- **Title:** ${{ github.event.issue.title }}
- **Number:** #${{ github.event.issue.number }}
- **Specification ID:** ${{ steps.extract.outputs.specification_id }}
- **Body:**
```
${{ github.event.issue.body }}
```
---
## Instructions
1. **Read current specification:**
- `plots/${{ steps.extract.outputs.specification_id }}/specification.md`
- `plots/${{ steps.extract.outputs.specification_id }}/specification.yaml`
2. **Post analysis comment:**
Post a SHORT comment (max 3-4 sentences) to the issue using `gh issue comment`:
- Is this a valid/useful change?
- What will be modified?
- Any concerns?
3. **Create update branch:**
```bash
git checkout -b "specification/${{ steps.extract.outputs.specification_id }}-update"
```
4. **Apply updates:**
- Modify `plots/${{ steps.extract.outputs.specification_id }}/specification.md` as needed
- Update `plots/${{ steps.extract.outputs.specification_id }}/specification.yaml`:
- Add entry to `history` array with:
- `date`: current timestamp (ISO 8601 format)
- `issue`: ${{ github.event.issue.number }}
- `changes`: brief description of what changed
5. **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/${{ steps.extract.outputs.specification_id }}/
git commit -m "spec: update ${{ steps.extract.outputs.specification_id }}
Updated from issue #${{ github.event.issue.number }}"
git push -u origin "specification/${{ steps.extract.outputs.specification_id }}-update"
```
---
## Important Rules
- Do NOT create a PR (the workflow does that)
- Do NOT add labels
- STOP after pushing the branch
- name: Create Pull Request
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SPEC_ID: ${{ steps.extract.outputs.specification_id }}
run: |
SPEC_CONTENT=$(cat "plots/${SPEC_ID}/specification.md")
PR_URL=$(gh pr create \
--base main \
--head "specification/${SPEC_ID}-update" \
--title "spec: update ${SPEC_ID}" \
--body "$(cat <<EOF
## Update Specification: \`${SPEC_ID}\`
Closes #${{ github.event.issue.number }}
---
### Updated specification.md
${SPEC_CONTENT}
---
**Next:** Add \`approved\` label to the issue to merge this update.
---
:robot: *[spec-update 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
- name: Comment on issue
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
## :pencil2: Specification Update Ready
**Specification:** \`${SPEC_ID}\`
**PR:** #${PR_NUMBER}
---
### Updated specification.md
${SPEC_CONTENT}
---
**Next:** Add \`approved\` label to merge this update.
---
:robot: *[spec-update workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})*
EOF
)"
- name: Add rocket reaction on success
if: 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 update (triggered by approved label)
# ============================================================================
merge:
if: >
github.event.label.name == 'approved' &&
contains(github.event.issue.labels.*.name, 'spec-update')
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"
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 update
PR_NUMBER=$(gh pr list --head "specification/${SPEC_ID}-update" --json number -q '.[0].number')
if [[ -z "$PR_NUMBER" ]]; then
echo "::error::No PR found for update branch"
exit 1
fi
# Merge the PR
gh pr merge "$PR_NUMBER" --squash --delete-branch
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "::notice::Merged update PR #$PR_NUMBER"
- name: Comment and close 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
## :white_check_mark: Specification Updated!
**Specification:** \`${SPEC_ID}\`
**PR:** #${PR_NUMBER} (merged)
The specification has been updated in \`main\`.
---
:robot: *[spec-update workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})*
EOF
)"
# Close the issue
gh issue close ${{ github.event.issue.number }}