|
38 | 38 | uses: anthropics/claude-code-base-action@e8132bc5e637a42c27763fc757faa37e1ee43b34 |
39 | 39 | with: |
40 | 40 | claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} |
41 | | - show_full_output: true |
| 41 | + model: claude-opus-4-6 |
| 42 | + max_turns: "50" |
| 43 | + timeout_minutes: "10" |
42 | 44 | prompt: | |
43 | 45 | Analyze PR #${{ github.event.pull_request.number }} for breaking changes. |
44 | 46 |
|
@@ -76,36 +78,58 @@ jobs: |
76 | 78 | - If code examples help, include them in markdown code blocks |
77 | 79 | - Only include categories that have actual breaking changes |
78 | 80 | - Return empty string for breaking_changes_content if no breaking changes |
79 | | -
|
80 | | - claude_args: | |
81 | | - --model claude-opus-4-6 |
82 | | - --max-turns 50 |
83 | | - --json-schema '{"type":"object","properties":{"has_breaking_changes":{"type":"boolean","description":"Whether this PR contains breaking changes"},"breaking_changes_content":{"type":"string","description":"Formatted breaking changes section content (without ## Breaking Changes header), or empty string if none"},"reasoning":{"type":"string","description":"Brief explanation of why this is or is not a breaking change"}},"required":["has_breaking_changes","breaking_changes_content","reasoning"]}' |
| 81 | + Return ONLY a valid JSON object with this exact schema: |
| 82 | + {"has_breaking_changes": boolean, "breaking_changes_content": string, "reasoning": string} |
| 83 | + Do not wrap the JSON in markdown code fences. |
84 | 84 |
|
85 | 85 | - name: Parse Claude output |
86 | 86 | id: parse |
87 | 87 | env: |
88 | | - CLAUDE_OUTPUT: ${{ steps.claude.outputs.structured_output }} |
| 88 | + CLAUDE_EXECUTION_FILE: ${{ steps.claude.outputs.execution_file }} |
89 | 89 | run: | |
90 | | - HAS_BC=$(echo "$CLAUDE_OUTPUT" | jq -r '.has_breaking_changes // false') |
91 | | - BC_CONTENT=$(echo "$CLAUDE_OUTPUT" | jq -r '.breaking_changes_content // ""') |
92 | | - REASONING=$(echo "$CLAUDE_OUTPUT" | jq -r '.reasoning // ""') |
93 | | -
|
94 | | - echo "has_breaking_changes=$HAS_BC" >> $GITHUB_OUTPUT |
95 | | -
|
96 | | - DELIMITER="EOF_$(date +%s%N)" |
97 | | -
|
98 | | - { |
99 | | - echo "breaking_changes_content<<$DELIMITER" |
100 | | - printf '%s\n' "$BC_CONTENT" |
101 | | - echo "$DELIMITER" |
102 | | - } >> $GITHUB_OUTPUT |
103 | | -
|
104 | | - { |
105 | | - echo "reasoning<<$DELIMITER" |
106 | | - printf '%s\n' "$REASONING" |
107 | | - echo "$DELIMITER" |
108 | | - } >> $GITHUB_OUTPUT |
| 90 | + python3 - <<'PY' |
| 91 | + import json |
| 92 | + import os |
| 93 | + import re |
| 94 | + from pathlib import Path |
| 95 | +
|
| 96 | + execution_file = Path(os.environ["CLAUDE_EXECUTION_FILE"]) |
| 97 | + execution_log = json.loads(execution_file.read_text()) |
| 98 | +
|
| 99 | + assistant_content = "" |
| 100 | + for item in reversed(execution_log): |
| 101 | + if item.get("role") != "assistant": |
| 102 | + continue |
| 103 | + content = item.get("content", "") |
| 104 | + if isinstance(content, str): |
| 105 | + assistant_content = content |
| 106 | + break |
| 107 | + if isinstance(content, list): |
| 108 | + text_parts = [] |
| 109 | + for block in content: |
| 110 | + if isinstance(block, dict) and block.get("type") == "text": |
| 111 | + text_parts.append(block.get("text", "")) |
| 112 | + assistant_content = "\n".join(text_parts).strip() |
| 113 | + if assistant_content: |
| 114 | + break |
| 115 | +
|
| 116 | + if not assistant_content: |
| 117 | + raise SystemExit("No assistant response found in Claude execution log") |
| 118 | +
|
| 119 | + assistant_content = assistant_content.strip() |
| 120 | + fenced = re.fullmatch(r"```(?:json)?\s*(.*?)\s*```", assistant_content, re.DOTALL) |
| 121 | + if fenced: |
| 122 | + assistant_content = fenced.group(1).strip() |
| 123 | +
|
| 124 | + data = json.loads(assistant_content) |
| 125 | +
|
| 126 | + github_output = Path(os.environ["GITHUB_OUTPUT"]) |
| 127 | + delimiter = "EOF_PARSE_OUTPUT" |
| 128 | + with github_output.open("a", encoding="utf-8") as f: |
| 129 | + f.write(f"has_breaking_changes={str(data.get('has_breaking_changes', False)).lower()}\n") |
| 130 | + f.write(f"breaking_changes_content<<{delimiter}\n{data.get('breaking_changes_content', '')}\n{delimiter}\n") |
| 131 | + f.write(f"reasoning<<{delimiter}\n{data.get('reasoning', '')}\n{delimiter}\n") |
| 132 | + PY |
109 | 133 |
|
110 | 134 | - name: Add breaking-change-analyzed label |
111 | 135 | env: |
|
0 commit comments