Skip to content

Commit 03dda0b

Browse files
authored
Refactor JSON processing in aicode-preprocess.yml
Refactor JSON handling in workflow to use a temporary file for improved reliability and avoid shell quoting issues.
1 parent 9374fe7 commit 03dda0b

1 file changed

Lines changed: 19 additions & 30 deletions

File tree

.github/workflows/aicode-preprocess.yml

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,49 +59,38 @@ jobs:
5959
JSON_LINE=$(echo "$OUTPUT" | grep "ENHANCED_TASK_JSON:" || true)
6060
if [ -n "$JSON_LINE" ]; then
6161
JSON_DATA=$(echo "$JSON_LINE" | sed 's/ENHANCED_TASK_JSON://')
62-
# Use multiline format to avoid shell quoting issues with JSON
63-
echo "task_json<<EOF" >> $GITHUB_OUTPUT
64-
echo "$JSON_DATA" >> $GITHUB_OUTPUT
65-
echo "EOF" >> $GITHUB_OUTPUT
66-
62+
# Write JSON to file to avoid shell quoting issues when reading back
63+
echo "$JSON_DATA" > /tmp/task_json.json
64+
6765
# Extract Confluence URL
6866
CONFLUENCE_URL=$(echo "$JSON_DATA" | jq -r '.confluenceUrl // "N/A"')
6967
echo "confluence_url=$CONFLUENCE_URL" >> $GITHUB_OUTPUT
68+
echo "has_json=true" >> $GITHUB_OUTPUT
7069
else
7170
echo "confluence_url=N/A" >> $GITHUB_OUTPUT
71+
echo "has_json=false" >> $GITHUB_OUTPUT
7272
fi
7373
7474
- name: Trigger main agent workflow
7575
if: always()
7676
run: |
77-
# Read enhanced task from JSON output to avoid shell quoting issues
78-
# Use jq to safely parse the JSON string from GitHub Actions output
79-
TASK_JSON_RAW="${{ steps.preprocess.outputs.task_json }}"
80-
81-
if [ -n "$TASK_JSON_RAW" ] && [ "$TASK_JSON_RAW" != "null" ] && [ "$TASK_JSON_RAW" != "" ]; then
82-
# Try to parse as JSON - if it's already a JSON string, parse it first
83-
if echo "$TASK_JSON_RAW" | jq -e . >/dev/null 2>&1; then
84-
# It's valid JSON, extract values
85-
ENHANCED_TASK=$(echo "$TASK_JSON_RAW" | jq -r '.enhanced // empty')
86-
ORIGINAL_TASK=$(echo "$TASK_JSON_RAW" | jq -r '.original // empty')
87-
CONFLUENCE_URL=$(echo "$TASK_JSON_RAW" | jq -r '.confluenceUrl // "N/A"')
77+
# Read enhanced task from JSON file to avoid shell quoting issues
78+
# Check if JSON file exists from previous step
79+
if [ -f /tmp/task_json.json ]; then
80+
# Read JSON from file and extract values
81+
if jq -e . /tmp/task_json.json >/dev/null 2>&1; then
82+
# Valid JSON, extract values
83+
ENHANCED_TASK=$(jq -r '.enhanced // empty' /tmp/task_json.json)
84+
ORIGINAL_TASK=$(jq -r '.original // empty' /tmp/task_json.json)
85+
CONFLUENCE_URL=$(jq -r '.confluenceUrl // "N/A"' /tmp/task_json.json)
8886
else
89-
# Might be a JSON string that needs to be parsed (double-encoded)
90-
# Try to unescape and parse
91-
TASK_JSON_PARSED=$(echo "$TASK_JSON_RAW" | jq -Rr '.')
92-
if echo "$TASK_JSON_PARSED" | jq -e . >/dev/null 2>&1; then
93-
ENHANCED_TASK=$(echo "$TASK_JSON_PARSED" | jq -r '.enhanced // empty')
94-
ORIGINAL_TASK=$(echo "$TASK_JSON_PARSED" | jq -r '.original // empty')
95-
CONFLUENCE_URL=$(echo "$TASK_JSON_PARSED" | jq -r '.confluenceUrl // "N/A"')
96-
else
97-
# Fallback to outputs if JSON parsing fails
98-
ENHANCED_TASK="${{ steps.preprocess.outputs.enhanced_task }}"
99-
ORIGINAL_TASK="${{ github.event.client_payload.task }}"
100-
CONFLUENCE_URL="${{ steps.preprocess.outputs.confluence_url }}"
101-
fi
87+
# Invalid JSON, fallback to outputs
88+
ENHANCED_TASK="${{ steps.preprocess.outputs.enhanced_task }}"
89+
ORIGINAL_TASK="${{ github.event.client_payload.task }}"
90+
CONFLUENCE_URL="${{ steps.preprocess.outputs.confluence_url }}"
10291
fi
10392
else
104-
# Fallback to outputs if JSON not available
93+
# No JSON file, fallback to outputs
10594
ENHANCED_TASK="${{ steps.preprocess.outputs.enhanced_task }}"
10695
ORIGINAL_TASK="${{ github.event.client_payload.task }}"
10796
CONFLUENCE_URL="${{ steps.preprocess.outputs.confluence_url }}"

0 commit comments

Comments
 (0)