Skip to content

Commit 4a750a7

Browse files
fix(workflows): refine label management and enhance API response validation
- Updated label removal logic in multiple workflow files - Added timeout and validation for API responses in Claude API calls - Improved concurrency handling in plot update workflow
1 parent 8cb6eab commit 4a750a7

11 files changed

Lines changed: 107 additions & 57 deletions

.github/workflows/bot-ai-review.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ jobs:
252252
# Update sub-issue
253253
if [ -n "$SUB_ISSUE" ]; then
254254
gh issue edit "$SUB_ISSUE" \
255-
--remove-label "reviewing,ai-rejected" \
255+
--remove-label "reviewing" \
256+
--remove-label "ai-rejected" \
256257
--add-label "not-feasible"
257258
258259
# Post final status to sub-issue

.github/workflows/bot-auto-merge.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ jobs:
5858
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5959
run: |
6060
gh issue edit ${{ steps.sub_issue.outputs.number }} \
61-
--remove-label "reviewing,ai-rejected" \
61+
--remove-label "reviewing" \
62+
--remove-label "ai-rejected" \
6263
--add-label "ai-approved"
6364
6465
- name: Enable auto-merge
@@ -142,7 +143,10 @@ jobs:
142143
143144
# Update labels
144145
gh issue edit $SUB_ISSUE \
145-
--remove-label "ai-approved,reviewing,generating,testing" \
146+
--remove-label "ai-approved" \
147+
--remove-label "reviewing" \
148+
--remove-label "generating" \
149+
--remove-label "testing" \
146150
--add-label "merged"
147151
148152
# Post completion comment

.github/workflows/bot-auto-tag.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: "Bot: Auto-Tag"
2+
run-name: "Auto-Tag: ${{ github.event.pull_request.head.ref }}"
23

34
on:
45
pull_request:
@@ -136,8 +137,8 @@ jobs:
136137
sed -i "s|\${SPEC_CONTENT}|${SPEC_CONTENT}|g" /tmp/tag_prompt.txt
137138
sed -i "s|\${PLOT_CONTENT}|${PLOT_CONTENT}|g" /tmp/tag_prompt.txt
138139
139-
# Call Claude API
140-
RESPONSE=$(curl -s https://api.anthropic.com/v1/messages \
140+
# Call Claude API (with timeout)
141+
RESPONSE=$(curl -s --max-time 60 --connect-timeout 10 https://api.anthropic.com/v1/messages \
141142
-H "Content-Type: application/json" \
142143
-H "x-api-key: $ANTHROPIC_API_KEY" \
143144
-H "anthropic-version: 2023-06-01" \
@@ -150,6 +151,14 @@ jobs:
150151
}]
151152
}")
152153
154+
# Validate API response
155+
if ! echo "$RESPONSE" | jq -e '.content[0].text' > /dev/null 2>&1; then
156+
echo "::warning::API response invalid or empty"
157+
echo "Response: $(echo "$RESPONSE" | jq -r '.error // .' 2>/dev/null || echo "$RESPONSE")"
158+
echo "tags_generated=false" >> $GITHUB_OUTPUT
159+
exit 0
160+
fi
161+
153162
# Extract tags from response
154163
TAGS=$(echo "$RESPONSE" | jq -r '.content[0].text // empty')
155164

.github/workflows/bot-validate-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
permissions:
2222
contents: read
2323
issues: write
24-
id-token: write
2524

2625
steps:
2726
- name: Check conditions
@@ -80,6 +79,7 @@ jobs:
8079
8180
- name: Run Claude Code to validate and assign spec ID
8281
if: steps.check.outputs.should_run == 'true'
82+
timeout-minutes: 60
8383
uses: anthropics/claude-code-action@v1
8484
with:
8585
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}

.github/workflows/ci-lint.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: Lint and Format Check
1+
name: "CI: Lint and Format Check"
2+
run-name: "Lint: ${{ github.ref_name }}"
23

34
on:
45
push:

.github/workflows/ci-plottest.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: Plot Tests
1+
name: "CI: Plot Tests"
2+
run-name: "Plot Tests: ${{ github.head_ref }}"
23

34
on:
45
pull_request:
@@ -115,3 +116,4 @@ jobs:
115116
with:
116117
name: test-results-${{ matrix.python-version }}
117118
path: test-results/
119+
retention-days: 30

.github/workflows/ci-unittest.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: Unit Tests
1+
name: "CI: Unit Tests"
2+
run-name: "Tests: ${{ github.ref_name }}"
23

34
on:
45
push:
@@ -40,6 +41,7 @@ jobs:
4041
with:
4142
name: coverage-report
4243
path: coverage.xml
44+
retention-days: 30
4345
if: always()
4446

4547
- name: Upload coverage to Codecov

.github/workflows/gen-library-impl.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ on:
3030
description: "Library-specific dependencies"
3131
required: true
3232
type: string
33+
outputs:
34+
pr_number:
35+
description: "PR number created (if any)"
36+
value: ${{ jobs.generate.outputs.pr_number }}
37+
pr_exists:
38+
description: "Whether a PR was created"
39+
value: ${{ jobs.generate.outputs.pr_exists }}
3340
secrets:
3441
CLAUDE_CODE_OAUTH_TOKEN:
3542
required: true
@@ -39,11 +46,13 @@ on:
3946
jobs:
4047
generate:
4148
runs-on: ubuntu-latest
49+
outputs:
50+
pr_number: ${{ steps.pr.outputs.pr_number }}
51+
pr_exists: ${{ steps.pr.outputs.pr_exists }}
4252
permissions:
4353
contents: write
4454
pull-requests: write
4555
issues: write
46-
id-token: write
4756
actions: read
4857

4958
steps:
@@ -57,7 +66,10 @@ jobs:
5766
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5867
run: |
5968
gh issue edit ${{ inputs.sub_issue_number }} \
60-
--remove-label "testing,reviewing,ai-approved,ai-rejected" \
69+
--remove-label "testing" \
70+
--remove-label "reviewing" \
71+
--remove-label "ai-approved" \
72+
--remove-label "ai-rejected" \
6173
--add-label "generating" 2>/dev/null || true
6274
6375
- name: Set up Python
@@ -108,6 +120,7 @@ jobs:
108120
fi
109121
110122
- name: Run Claude Code to generate implementation
123+
timeout-minutes: 60
111124
uses: anthropics/claude-code-action@v1
112125
with:
113126
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}

.github/workflows/gen-preview.yml

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: Generate Plot Previews
1+
name: "Gen: Preview Images"
2+
run-name: "Preview: ${{ github.event.workflow_run.head_branch }}"
23

34
on:
45
workflow_run:
@@ -321,3 +322,41 @@ jobs:
321322
path: |
322323
plot_metadata.json
323324
previous_versions.json
325+
326+
# ============================================================================
327+
# Job 2: Notify when tests fail (no preview generated)
328+
# ============================================================================
329+
notify-failure:
330+
name: Notify Test Failure
331+
runs-on: ubuntu-latest
332+
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
333+
permissions:
334+
pull-requests: write
335+
issues: write
336+
actions: read
337+
338+
steps:
339+
- name: Get PR number from workflow run
340+
id: get_pr
341+
env:
342+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
343+
run: |
344+
PR_NUMBER=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }} --jq '.pull_requests[0].number' 2>/dev/null || echo "")
345+
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
346+
347+
- name: Post failure notice
348+
if: steps.get_pr.outputs.pr_number != ''
349+
env:
350+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
351+
run: |
352+
PR_NUM="${{ steps.get_pr.outputs.pr_number }}"
353+
354+
gh pr comment "$PR_NUM" --body "## ❌ Tests Failed
355+
356+
Plot tests failed - no preview images were generated.
357+
358+
**Please check the test workflow for details:**
359+
[View test results](https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }})
360+
361+
---
362+
🤖 *[gen-preview workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})*"

.github/workflows/gen-update-plot.yml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ on:
55
pull_request:
66
types: [labeled]
77

8+
# Prevent race conditions when multiple repairs trigger for same PR
9+
concurrency:
10+
group: repair-${{ github.event.pull_request.head.ref }}
11+
cancel-in-progress: false
12+
813
jobs:
914
update-plot:
1015
name: Regenerate Plot from AI Feedback
@@ -88,7 +93,8 @@ jobs:
8893
# Update sub-issue
8994
if [ -n "$SUB_ISSUE" ]; then
9095
gh issue edit $SUB_ISSUE \
91-
--remove-label "ai-rejected,reviewing" \
96+
--remove-label "ai-rejected" \
97+
--remove-label "reviewing" \
9298
--add-label "not-feasible"
9399
fi
94100
@@ -199,7 +205,8 @@ jobs:
199205
# Update sub-issue
200206
if [ -n "$SUB_ISSUE" ]; then
201207
gh issue edit $SUB_ISSUE \
202-
--remove-label "ai-rejected,reviewing" \
208+
--remove-label "ai-rejected" \
209+
--remove-label "reviewing" \
203210
--add-label "generating"
204211
fi
205212
@@ -287,8 +294,8 @@ jobs:
287294
f.write(content)
288295
PYEOF
289296
290-
# Call Claude API
291-
RESPONSE=$(curl -s https://api.anthropic.com/v1/messages \
297+
# Call Claude API (with timeout)
298+
RESPONSE=$(curl -s --max-time 120 --connect-timeout 10 https://api.anthropic.com/v1/messages \
292299
-H "Content-Type: application/json" \
293300
-H "x-api-key: $ANTHROPIC_API_KEY" \
294301
-H "anthropic-version: 2023-06-01" \
@@ -301,6 +308,13 @@ jobs:
301308
}]
302309
}")
303310
311+
# Validate API response
312+
if ! echo "$RESPONSE" | jq -e '.content[0].text' > /dev/null 2>&1; then
313+
echo "::error::API response invalid or empty"
314+
echo "Response: $(echo "$RESPONSE" | jq -r '.error // .' 2>/dev/null || echo "$RESPONSE")"
315+
exit 1
316+
fi
317+
304318
# Extract improved code
305319
IMPROVED_CODE=$(echo "$RESPONSE" | jq -r '.content[0].text // empty')
306320
@@ -334,11 +348,7 @@ jobs:
334348
echo "No changes to commit"
335349
else
336350
git add plots/
337-
git commit -m "fix($LIBRARY): address AI review feedback for $SPEC_ID (attempt $ATTEMPT/3)
338-
339-
:robot: Generated with [Claude Code](https://claude.com/claude-code)
340-
341-
Co-Authored-By: Claude <noreply@anthropic.com>"
351+
git commit -m "fix($LIBRARY): address AI review feedback for $SPEC_ID (attempt $ATTEMPT/3)"
342352
343353
git push
344354
echo "Changes pushed"
@@ -389,3 +399,8 @@ jobs:
389399
COMMENTEOF
390400
391401
gh issue comment "$SUB_ISSUE" --body-file /tmp/update_comment.md
402+
403+
- name: Cleanup temporary files
404+
if: always()
405+
run: |
406+
rm -f /tmp/improve_prompt.txt /tmp/latest_feedback.md /tmp/all_attempts.md /tmp/update_comment.md

0 commit comments

Comments
 (0)