Skip to content

Commit f0039f4

Browse files
committed
Make prompt build safer
1 parent 89f1382 commit f0039f4

File tree

2 files changed

+21
-50
lines changed

2 files changed

+21
-50
lines changed

.github/workflows/claude-fix-issue.yml

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,39 +57,24 @@ jobs:
5757
5858
TITLE=$(echo "$ISSUE_JSON" | jq -r '.title')
5959
URL=$(echo "$ISSUE_JSON" | jq -r '.url')
60-
BODY=$(echo "$ISSUE_JSON" | jq -r '.body')
61-
6260
echo "title=$TITLE" >> "$GITHUB_OUTPUT"
6361
echo "url=$URL" >> "$GITHUB_OUTPUT"
64-
{
65-
echo "body<<BODY_EOF"
66-
echo "$BODY"
67-
echo "BODY_EOF"
68-
} >> "$GITHUB_OUTPUT"
62+
echo "$ISSUE_JSON" | jq -r '.body' > /tmp/issue-body.txt
6963
7064
- name: "Build prompt"
71-
env:
72-
ISSUE_NUMBER: ${{ inputs.issue-number }}
73-
ISSUE_TITLE: ${{ steps.issue.outputs.title }}
74-
ISSUE_URL: ${{ steps.issue.outputs.url }}
75-
ISSUE_BODY: ${{ steps.issue.outputs.body }}
7665
run: |
77-
python3 << 'PYEOF'
78-
import os
79-
80-
n = os.environ["ISSUE_NUMBER"]
81-
title = os.environ["ISSUE_TITLE"]
82-
url = os.environ["ISSUE_URL"]
83-
body = os.environ["ISSUE_BODY"]
84-
85-
prompt = f"""You are working on phpstan/phpstan-src, the source code of PHPStan - a PHP static analysis tool.
66+
{
67+
cat << 'PROMPT_PART1'
68+
You are working on phpstan/phpstan-src, the source code of PHPStan - a PHP static analysis tool.
8669
8770
Your task is to fix the following GitHub issue from the phpstan/phpstan repository:
88-
Issue phpstan/phpstan#{n}: {title}
89-
URL: {url}
71+
Issue phpstan/phpstan#${{ inputs.issue-number }}: ${{ steps.issue.outputs.title }}
72+
URL: ${{ steps.issue.outputs.url }}
9073
9174
Issue body:
92-
{body}
75+
PROMPT_PART1
76+
cat /tmp/issue-body.txt
77+
cat << 'PROMPT_PART2'
9378
9479
## Step 1: Write a regression test
9580
@@ -149,14 +134,11 @@ jobs:
149134
## Test
150135
Describe the regression test that was added.
151136
152-
Fixes phpstan/phpstan#{n}
137+
Fixes phpstan/phpstan#${{ inputs.issue-number }}
153138
154139
These files are critical - they will be used for the commit message and PR description.
155-
"""
156-
157-
with open("/tmp/claude-prompt.txt", "w") as f:
158-
f.write(prompt)
159-
PYEOF
140+
PROMPT_PART2
141+
} > /tmp/claude-prompt.txt
160142
161143
- name: "Run Claude Code"
162144
env:

.github/workflows/claude-fix-pr-ci.yml

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,18 @@ jobs:
138138

139139
- name: "Build prompt"
140140
if: steps.check-attempts.outputs.skip != 'true' && steps.failures.outputs.skip != 'true'
141-
env:
142-
PR_NUMBER: ${{ github.event.pull_request.number }}
143-
ATTEMPT: ${{ steps.check-attempts.outputs.attempt_number }}
144141
run: |
145-
python3 << 'PYEOF'
146-
import os
147-
148-
pr_number = os.environ["PR_NUMBER"]
149-
attempt = os.environ["ATTEMPT"]
142+
{
143+
cat << 'PROMPT_PART1'
144+
You are working on phpstan/phpstan-src. CI has failed on PR #${{ github.event.pull_request.number }} which was created by an automated process.
150145
151-
with open("/tmp/ci-failure-context.txt", "r") as f:
152-
failure_logs = f.read()
153-
154-
prompt = f"""You are working on phpstan/phpstan-src. CI has failed on PR #{pr_number} which was created by an automated process.
155-
156-
This is CI fix attempt {attempt} of maximum 2.
146+
This is CI fix attempt ${{ steps.check-attempts.outputs.attempt_number }} of maximum 2.
157147
158148
## CI Failure Logs
159149
160-
{failure_logs}
150+
PROMPT_PART1
151+
cat /tmp/ci-failure-context.txt
152+
cat << 'PROMPT_PART2'
161153
162154
## Your Task
163155
@@ -189,11 +181,8 @@ jobs:
189181
- Do NOT create a branch, push, or create a PR — this is handled automatically after you finish
190182
- Focus only on fixing the CI failures, do not refactor or add unrelated changes
191183
- If you cannot determine how to fix the failure, create a file /tmp/ci-fix-failed.txt with an explanation
192-
"""
193-
194-
with open("/tmp/claude-ci-prompt.txt", "w") as f:
195-
f.write(prompt)
196-
PYEOF
184+
PROMPT_PART2
185+
} > /tmp/claude-ci-prompt.txt
197186
198187
- name: "Run Claude Code"
199188
if: steps.check-attempts.outputs.skip != 'true' && steps.failures.outputs.skip != 'true'

0 commit comments

Comments
 (0)