Skip to content

Commit 4fc1433

Browse files
feat(workflow): add benchmark posting to secure workflow
Enable the secure Claude Code Review workflow to also download and post benchmark results from the CI workflow. This solves the fork PR comment permission issue. Changes: - Secure workflow now checks for benchmark artifacts from CI runs - Downloads benchmark results matching the same commit SHA - Posts formatted benchmark results as PR comment - Removed failing benchmark comment step from CI workflow - CI workflow only uploads artifacts, secure workflow posts comments This ensures both Claude reviews and benchmark results can be posted to forked PRs without exposing secrets. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ab102aa commit 4fc1433

File tree

2 files changed

+79
-39
lines changed

2 files changed

+79
-39
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -176,45 +176,6 @@ jobs:
176176
exit 1
177177
fi
178178
179-
- name: Post benchmark results to PR
180-
env:
181-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
182-
run: |
183-
set -euo pipefail
184-
185-
# Find the generated markdown file
186-
echo "🔍 Looking for benchmark markdown files..."
187-
BENCHMARK_FILE=$(find Nino.Benchmark -path "*/BenchmarkDotNet.Artifacts/results/*.md" -type f | head -n1)
188-
189-
if [[ -z "$BENCHMARK_FILE" || ! -f "$BENCHMARK_FILE" ]]; then
190-
echo "❌ No markdown benchmark report found"
191-
exit 1
192-
fi
193-
194-
echo "✅ Found benchmark report: $BENCHMARK_FILE"
195-
196-
# Read benchmark content
197-
PERF_CONTENT=$(cat "$BENCHMARK_FILE")
198-
199-
# Create PR comment with benchmark results
200-
{
201-
echo "## 📊 Benchmark Results"
202-
echo ""
203-
echo "<details>"
204-
echo "<summary>Click to expand benchmark results</summary>"
205-
echo ""
206-
echo "$PERF_CONTENT"
207-
echo ""
208-
echo "</details>"
209-
echo ""
210-
echo "---"
211-
echo "*Benchmark generated automatically on $(date -u '+%Y-%m-%d %H:%M:%S UTC')*"
212-
} > benchmark_comment.md
213-
214-
# Post comment to PR
215-
gh pr comment ${{ github.event.pull_request.number }} --body-file benchmark_comment.md
216-
echo "✅ Benchmark results posted to PR #${{ github.event.pull_request.number }}"
217-
218179
- name: Upload benchmark results
219180
uses: actions/upload-artifact@v4
220181
if: always()

.github/workflows/claude-code-review-secure.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,82 @@ jobs:
8686
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
8787
# or https://docs.claude.com/en/docs/claude-code/cli-reference for available options
8888
claude_args: '--allowed-tools "Bash(gh pr comment:*),Bash(gh pr view:*),Bash(cat:pr.diff),Bash(cat:pr-info.txt)"'
89+
90+
- name: Check for benchmark results
91+
id: benchmark
92+
continue-on-error: true
93+
run: |
94+
PR_NUM="${{ steps.download.outputs.pr_number }}"
95+
96+
# Look for benchmark artifacts from the CI workflow
97+
echo "Looking for benchmark artifacts for PR #$PR_NUM..."
98+
99+
# Get all workflow runs for this PR
100+
RUNS=$(gh api "repos/${{ github.repository }}/actions/runs?event=pull_request&status=completed" \
101+
--jq ".workflow_runs[] | select(.head_sha == \"${{ github.event.workflow_run.head_sha }}\") | .id")
102+
103+
BENCHMARK_FOUND=false
104+
for RUN_ID in $RUNS; do
105+
echo "Checking run $RUN_ID for benchmark artifacts..."
106+
107+
# Check if this run has benchmark artifacts
108+
ARTIFACTS=$(gh api "repos/${{ github.repository }}/actions/runs/$RUN_ID/artifacts" \
109+
--jq ".artifacts[] | select(.name | startswith(\"benchmark-results-pr-\"))")
110+
111+
if [ -n "$ARTIFACTS" ]; then
112+
echo "Found benchmark artifacts in run $RUN_ID"
113+
ARTIFACT_ID=$(echo "$ARTIFACTS" | jq -r '.id' | head -1)
114+
115+
# Download benchmark artifact
116+
gh api "repos/${{ github.repository }}/actions/artifacts/$ARTIFACT_ID/zip" > benchmark.zip
117+
unzip -q benchmark.zip -d benchmark-results
118+
119+
BENCHMARK_FOUND=true
120+
break
121+
fi
122+
done
123+
124+
if [ "$BENCHMARK_FOUND" = true ]; then
125+
echo "has_benchmark=true" >> $GITHUB_OUTPUT
126+
echo "✅ Benchmark results found and downloaded"
127+
else
128+
echo "has_benchmark=false" >> $GITHUB_OUTPUT
129+
echo "ℹ️ No benchmark results found for this PR"
130+
fi
131+
env:
132+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
133+
134+
- name: Post benchmark results to PR
135+
if: steps.benchmark.outputs.has_benchmark == 'true'
136+
run: |
137+
PR_NUM="${{ steps.download.outputs.pr_number }}"
138+
139+
# Find the benchmark markdown file
140+
BENCHMARK_FILE=$(find benchmark-results -name "*-report-github.md" -type f | head -1)
141+
142+
if [ -n "$BENCHMARK_FILE" ] && [ -f "$BENCHMARK_FILE" ]; then
143+
echo "Found benchmark report: $BENCHMARK_FILE"
144+
145+
# Create formatted comment
146+
{
147+
echo "## 📊 Benchmark Results"
148+
echo ""
149+
echo "<details>"
150+
echo "<summary>Click to expand benchmark results</summary>"
151+
echo ""
152+
cat "$BENCHMARK_FILE"
153+
echo ""
154+
echo "</details>"
155+
echo ""
156+
echo "---"
157+
echo "*Benchmark generated automatically on $(date -u '+%Y-%m-%d %H:%M:%S UTC')*"
158+
} > benchmark_comment.md
159+
160+
# Post to PR
161+
gh pr comment "$PR_NUM" --body-file benchmark_comment.md
162+
echo "✅ Benchmark results posted to PR #$PR_NUM"
163+
else
164+
echo "⚠️ Benchmark markdown file not found in downloaded artifacts"
165+
fi
166+
env:
167+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)