Skip to content

Commit e50ad58

Browse files
authored
Fix ai-labeler.yml YAML syntax error (#146)
* Add shared splice-prompt.py script Extract the repeated inline Python logic that splices a user message into a prompt YAML's messages array. Three jobs in ai-labeler.yml duplicated this identically — pull it into a standalone script that takes the prompt template path and output path as arguments. * Fix ai-labeler.yml YAML syntax error The three inline python3 -c blocks had their code body at column 0, breaking out of the run: | block scalar and failing GitHub's YAML validation. Replace each with a one-liner call to the new shared splice-prompt.py script. * Fix shellcheck SC2129 and remove stale actionlint ignore Group consecutive GITHUB_STEP_SUMMARY redirects into a single block to satisfy SC2129. Drop the "could not parse as YAML" ignore for ai-labeler.yml since the inline Python that caused it is gone.
1 parent aa71144 commit e50ad58

File tree

3 files changed

+42
-95
lines changed

3 files changed

+42
-95
lines changed

.github/actionlint.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ self-hosted-runner:
44
config-variables: null
55

66
paths:
7-
# ai-labeler.yml embeds Python in a YAML run block that actionlint
8-
# can't parse as valid workflow YAML.
9-
.github/workflows/ai-labeler.yml:
10-
ignore:
11-
- 'could not parse as YAML'
12-
137
# SC2086 fires on ${{ }} expressions which are interpolated by GitHub
148
# Actions before the shell sees them. Safe to ignore repo-wide.
159
.github/workflows/**/*.yml:

.github/scripts/splice-prompt.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
"""Splice /tmp/user-message.txt into a prompt YAML's messages array."""
3+
import sys, yaml
4+
5+
prompt_file = sys.argv[1]
6+
output_file = sys.argv[2]
7+
8+
with open(prompt_file) as f:
9+
lines = f.readlines()
10+
with open('/tmp/user-message.txt') as f:
11+
user_msg = f.read()
12+
13+
# Find where messages array ends: first non-blank top-level key after 'messages:'
14+
insert_at = len(lines)
15+
for i, line in enumerate(lines):
16+
if i == 0:
17+
continue
18+
if line.strip() and not line[0].isspace():
19+
insert_at = i
20+
break
21+
22+
entry = [' - role: user\n', ' content: |\n']
23+
for ln in user_msg.splitlines():
24+
entry.append(' ' + ln + '\n')
25+
26+
lines[insert_at:insert_at] = entry
27+
with open(output_file, 'w') as f:
28+
f.writelines(lines)
29+
30+
# Validate: last message must be the user message we just added
31+
doc = yaml.safe_load(open(output_file))
32+
assert doc['messages'][-1]['role'] == 'user', 'prompt splice failed: last message is not user'

.github/workflows/ai-labeler.yml

Lines changed: 10 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,7 @@ jobs:
4141
4242
# Build full prompt YAML: splice user message into the messages array
4343
# (avoids yaml round-trip which reorders keys and changes scalar styles)
44-
python3 -c "
45-
with open('.github/prompts/classify-pr.prompt.yml') as f:
46-
lines = f.readlines()
47-
with open('/tmp/user-message.txt') as f:
48-
user_msg = f.read()
49-
50-
# Find where messages array ends: first non-blank top-level key after 'messages:'
51-
insert_at = len(lines)
52-
for i, line in enumerate(lines):
53-
if i == 0:
54-
continue
55-
if line.strip() and not line[0].isspace():
56-
insert_at = i
57-
break
58-
59-
entry = [' - role: user\n', ' content: |\n']
60-
for ln in user_msg.splitlines():
61-
entry.append(' ' + ln + '\n')
62-
63-
lines[insert_at:insert_at] = entry
64-
with open('/tmp/prompt.yml', 'w') as f:
65-
f.writelines(lines)
66-
67-
# Validate: last message must be the user message we just added
68-
import yaml
69-
doc = yaml.safe_load(open('/tmp/prompt.yml'))
70-
assert doc['messages'][-1]['role'] == 'user', 'prompt splice failed: last message is not user'
71-
"
44+
python3 .github/scripts/splice-prompt.py .github/prompts/classify-pr.prompt.yml /tmp/prompt.yml
7245
7346
- name: Classify
7447
id: classify
@@ -151,34 +124,7 @@ assert doc['messages'][-1]['role'] == 'user', 'prompt splice failed: last messag
151124
152125
# Build full prompt YAML: splice user message into the messages array
153126
# (avoids yaml round-trip which reorders keys and changes scalar styles)
154-
python3 -c "
155-
with open('.github/prompts/detect-breaking.prompt.yml') as f:
156-
lines = f.readlines()
157-
with open('/tmp/user-message.txt') as f:
158-
user_msg = f.read()
159-
160-
# Find where messages array ends: first non-blank top-level key after 'messages:'
161-
insert_at = len(lines)
162-
for i, line in enumerate(lines):
163-
if i == 0:
164-
continue
165-
if line.strip() and not line[0].isspace():
166-
insert_at = i
167-
break
168-
169-
entry = [' - role: user\n', ' content: |\n']
170-
for ln in user_msg.splitlines():
171-
entry.append(' ' + ln + '\n')
172-
173-
lines[insert_at:insert_at] = entry
174-
with open('/tmp/prompt.yml', 'w') as f:
175-
f.writelines(lines)
176-
177-
# Validate: last message must be the user message we just added
178-
import yaml
179-
doc = yaml.safe_load(open('/tmp/prompt.yml'))
180-
assert doc['messages'][-1]['role'] == 'user', 'prompt splice failed: last message is not user'
181-
"
127+
python3 .github/scripts/splice-prompt.py .github/prompts/detect-breaking.prompt.yml /tmp/prompt.yml
182128
echo "skip=false" >> $GITHUB_OUTPUT
183129
fi
184130
@@ -198,11 +144,13 @@ assert doc['messages'][-1]['role'] == 'user', 'prompt splice failed: last messag
198144
RESPONSE_FILE="${{ steps.detect.outputs.response-file }}"
199145
if ! jq empty "$RESPONSE_FILE" 2>/dev/null; then
200146
echo "::warning::Model response is not valid JSON; skipping breaking label. See step summary for details."
201-
echo "## Breaking change detection failed" >> "$GITHUB_STEP_SUMMARY"
202-
echo "Model returned invalid JSON. Breaking label was **not** applied." >> "$GITHUB_STEP_SUMMARY"
203-
echo '```' >> "$GITHUB_STEP_SUMMARY"
204-
cat "$RESPONSE_FILE" >> "$GITHUB_STEP_SUMMARY"
205-
echo '```' >> "$GITHUB_STEP_SUMMARY"
147+
{
148+
echo "## Breaking change detection failed"
149+
echo "Model returned invalid JSON. Breaking label was **not** applied."
150+
echo '```'
151+
cat "$RESPONSE_FILE"
152+
echo '```'
153+
} >> "$GITHUB_STEP_SUMMARY"
206154
exit 0
207155
fi
208156
BREAKING=$(jq -r '.breaking' "$RESPONSE_FILE")
@@ -261,34 +209,7 @@ assert doc['messages'][-1]['role'] == 'user', 'prompt splice failed: last messag
261209
262210
# Build full prompt YAML: splice user message into the messages array
263211
# (avoids yaml round-trip which reorders keys and changes scalar styles)
264-
python3 -c "
265-
with open('.github/prompts/spec-impact.prompt.yml') as f:
266-
lines = f.readlines()
267-
with open('/tmp/user-message.txt') as f:
268-
user_msg = f.read()
269-
270-
# Find where messages array ends: first non-blank top-level key after 'messages:'
271-
insert_at = len(lines)
272-
for i, line in enumerate(lines):
273-
if i == 0:
274-
continue
275-
if line.strip() and not line[0].isspace():
276-
insert_at = i
277-
break
278-
279-
entry = [' - role: user\n', ' content: |\n']
280-
for ln in user_msg.splitlines():
281-
entry.append(' ' + ln + '\n')
282-
283-
lines[insert_at:insert_at] = entry
284-
with open('/tmp/prompt.yml', 'w') as f:
285-
f.writelines(lines)
286-
287-
# Validate: last message must be the user message we just added
288-
import yaml
289-
doc = yaml.safe_load(open('/tmp/prompt.yml'))
290-
assert doc['messages'][-1]['role'] == 'user', 'prompt splice failed: last message is not user'
291-
"
212+
python3 .github/scripts/splice-prompt.py .github/prompts/spec-impact.prompt.yml /tmp/prompt.yml
292213
echo "skip=false" >> $GITHUB_OUTPUT
293214
fi
294215

0 commit comments

Comments
 (0)