Skip to content

Commit 4a90b63

Browse files
committed
Update PR automation workflow
1 parent 8bcb7e1 commit 4a90b63

1 file changed

Lines changed: 83 additions & 36 deletions

File tree

.github/workflows/pr-automation.yml

Lines changed: 83 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ jobs:
1313
startsWith(github.event.comment.body, '[fix]') ||
1414
startsWith(github.event.comment.body, '[debug]'))
1515
16-
runs-on: self-hosted
16+
runs-on: ${{ vars.RUNNER_TYPE || 'ubuntu-latest' }}
1717

1818
permissions:
1919
contents: write
2020
pull-requests: write
2121
statuses: write
2222

2323
steps:
24-
- name: Get PR details
24+
- name: Get PR details and set pending status
2525
id: pr
2626
uses: actions/github-script@v7
2727
with:
@@ -31,28 +31,34 @@ jobs:
3131
repo: context.repo.repo,
3232
pull_number: context.issue.number
3333
});
34+
const sha = pr.data.head.sha;
3435
core.setOutput('branch', pr.data.head.ref);
35-
core.setOutput('sha', pr.data.head.sha);
36+
core.setOutput('sha', sha);
3637
3738
const body = context.payload.comment.body;
3839
let command = 'unknown';
39-
if (body.startsWith('[action]')) command = 'action';
40-
else if (body.startsWith('[fix]')) command = 'fix';
41-
else if (body.startsWith('[debug]')) command = 'debug';
40+
let instructions = '';
41+
if (body.startsWith('[action]')) {
42+
command = 'action';
43+
instructions = body.slice('[action]'.length).trim();
44+
} else if (body.startsWith('[fix]')) {
45+
command = 'fix';
46+
instructions = body.slice('[fix]'.length).trim();
47+
} else if (body.startsWith('[debug]')) {
48+
command = 'debug';
49+
}
4250
core.setOutput('command', command);
51+
core.setOutput('instructions', instructions);
4352
44-
- name: Set pending status
45-
uses: actions/github-script@v7
46-
with:
47-
script: |
53+
// Set pending status immediately
4854
await github.rest.repos.createCommitStatus({
4955
owner: context.repo.owner,
5056
repo: context.repo.repo,
51-
sha: '${{ steps.pr.outputs.sha }}',
57+
sha: sha,
5258
state: 'pending',
53-
context: 'PR Automation / ${{ steps.pr.outputs.command }}',
59+
context: `PR Automation / ${command}`,
5460
description: 'Running...',
55-
target_url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
61+
target_url: `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
5662
});
5763
5864
- name: Checkout PR branch
@@ -62,15 +68,19 @@ jobs:
6268
fetch-depth: 0
6369

6470
- name: Setup Node.js (GitHub-hosted only)
65-
if: ${{ !contains(runner.name, 'self-hosted') }}
71+
if: ${{ vars.RUNNER_TYPE != 'self-hosted' }}
6672
uses: actions/setup-node@v4
6773
with:
6874
node-version: '20'
6975

7076
- name: Install Claude Code CLI (GitHub-hosted only)
71-
if: ${{ !contains(runner.name, 'self-hosted') }}
77+
if: ${{ vars.RUNNER_TYPE != 'self-hosted' }}
7278
run: npm install -g @anthropic-ai/claude-code
7379

80+
- name: Install superpowers plugin (GitHub-hosted only)
81+
if: ${{ vars.RUNNER_TYPE != 'self-hosted' }}
82+
run: claude plugins add anthropics/claude-code-superpowers --yes
83+
7484
- name: Find plan file
7585
id: plan
7686
if: steps.pr.outputs.command == 'action'
@@ -90,47 +100,84 @@ jobs:
90100
run: |
91101
# Use secret if set, otherwise use runner's env
92102
[ -n "$ANTHROPIC_API_KEY_SECRET" ] && export ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY_SECRET"
103+
INSTRUCTIONS='${{ steps.pr.outputs.instructions }}'
93104
claude --dangerously-skip-permissions --max-turns 100 -p "
94105
Execute the plan in '${{ steps.plan.outputs.file }}'.
95-
96-
Instructions:
97-
1. Read the plan file carefully
98-
2. Implement each step in order
99-
3. Commit changes with descriptive messages
100-
4. Push changes: git push origin ${{ steps.pr.outputs.branch }}
101-
5. Post a summary comment on the PR using:
102-
gh pr comment ${{ github.event.issue.number }} --repo ${{ github.repository }} --body 'SUMMARY'
103-
Replace SUMMARY with a brief markdown summary of what you did (files changed, features added, etc.)
106+
${INSTRUCTIONS:+
107+
## Additional Instructions
108+
$INSTRUCTIONS
109+
}
110+
## Process
111+
1. Read the plan file
112+
2. Use /subagent-driven-development to execute tasks
113+
3. Push: git push origin ${{ steps.pr.outputs.branch }}
114+
4. Post summary: gh pr comment ${{ github.event.issue.number }} --repo ${{ github.repository }} --body 'SUMMARY'
115+
116+
## Rules
117+
- Tests should be strong enough to catch regressions.
118+
- Do not modify tests to make them pass.
119+
- Test failure must be reported.
104120
" 2>&1 | tee claude-output.txt
105121
106-
- name: Fix review comments
122+
- name: Fix issues
107123
if: steps.pr.outputs.command == 'fix'
108124
env:
109125
ANTHROPIC_API_KEY_SECRET: ${{ secrets.ANTHROPIC_API_KEY }}
110126
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111127
run: |
112128
# Use secret if set, otherwise use runner's env
113129
[ -n "$ANTHROPIC_API_KEY_SECRET" ] && export ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY_SECRET"
130+
131+
# Gather all feedback sources
114132
INLINE=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.issue.number }}/comments --jq '.[].body' 2>/dev/null || echo "")
115133
REVIEWS=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.issue.number }}/reviews --jq '.[] | select(.body != "") | .body' 2>/dev/null || echo "")
134+
PR_COMMENTS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments --jq '.[].body' 2>/dev/null || echo "")
135+
136+
# Gather CI status
137+
CI_STATUS=$(gh pr checks ${{ github.event.issue.number }} --repo ${{ github.repository }} 2>/dev/null || echo "")
138+
FAILED_RUNS=$(gh run list --branch ${{ steps.pr.outputs.branch }} --status failure --limit 3 --json databaseId,name --jq '.[] | "\(.databaseId) \(.name)"' 2>/dev/null || echo "")
139+
140+
# Get failed run logs if any
141+
CI_LOGS=""
142+
for run_id in $(echo "$FAILED_RUNS" | cut -d' ' -f1); do
143+
[ -n "$run_id" ] && CI_LOGS="$CI_LOGS
144+
--- Run $run_id ---
145+
$(gh run view $run_id --log-failed 2>/dev/null | tail -100 || echo 'Could not fetch logs')"
146+
done
116147
148+
INSTRUCTIONS='${{ steps.pr.outputs.instructions }}'
117149
claude --dangerously-skip-permissions --max-turns 100 -p "
118-
Address the PR review comments.
119-
120-
=== Inline Review Comments ===
150+
Fix all issues with this PR: review comments AND CI failures.
151+
${INSTRUCTIONS:+
152+
## Additional Instructions
153+
$INSTRUCTIONS
154+
}
155+
=== Inline Code Comments ===
121156
$INLINE
122157
123158
=== PR Reviews ===
124159
$REVIEWS
125160
126-
Instructions:
127-
1. Read each comment and understand what change is requested
128-
2. Make the requested changes to the code
129-
3. Commit: git commit -am 'Address PR review feedback'
130-
4. Push: git push origin ${{ steps.pr.outputs.branch }}
131-
5. Post a summary comment on the PR using:
132-
gh pr comment ${{ github.event.issue.number }} --repo ${{ github.repository }} --body 'SUMMARY'
133-
Replace SUMMARY with a brief markdown summary of what you fixed
161+
=== PR Conversation ===
162+
$PR_COMMENTS
163+
164+
=== CI Status ===
165+
$CI_STATUS
166+
167+
=== Failed CI Logs (last 100 lines each) ===
168+
$CI_LOGS
169+
170+
## Process
171+
1. Use /systematic-debugging if CI failed
172+
2. Fix review comments and CI issues
173+
3. Run tests to verify: make test, cargo test, npm test, etc.
174+
4. Commit: git commit -am 'Fix review feedback and CI issues'
175+
5. Push: git push origin ${{ steps.pr.outputs.branch }}
176+
6. Post summary: gh pr comment ${{ github.event.issue.number }} --repo ${{ github.repository }} --body 'SUMMARY'
177+
178+
## Rules
179+
- All CI failures must be fixed.
180+
- All change requests must be either addressed or explained.
134181
" 2>&1 | tee claude-output.txt
135182
136183
- name: Debug test

0 commit comments

Comments
 (0)