Skip to content

Commit dbabdff

Browse files
committed
ci: ensure migration benchmark runs
1 parent 0ef7093 commit dbabdff

2 files changed

Lines changed: 64 additions & 22 deletions

File tree

.github/workflows/migration-ci.yml

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,12 @@ name: Migration Parity and Benchmarks
33
on:
44
pull_request:
55
branches: [main]
6-
paths:
7-
- ".crane/**"
8-
- ".github/workflows/migration-ci.yml"
9-
- "cmd/**"
10-
- "internal/**"
11-
- "pkg/**"
12-
- "go.mod"
13-
- "go.sum"
14-
- "pyproject.toml"
15-
- "scripts/ci/**"
16-
- "src/**"
17-
- "tests/benchmarks/**"
18-
- "tests/unit/test_crane_score.py"
196
workflow_dispatch:
207

218
permissions:
229
contents: read
10+
issues: write
11+
pull-requests: write
2312

2413
env:
2514
PYTHON_VERSION: "3.12"
@@ -37,19 +26,26 @@ jobs:
3726

3827
- name: Check changed paths
3928
id: filter
29+
env:
30+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
4031
shell: bash
4132
run: |
4233
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
4334
echo "should-run=true" >> "$GITHUB_OUTPUT"
4435
exit 0
4536
fi
4637
38+
if [ "${{ github.event_name }}" = "pull_request" ] && [[ "$HEAD_REF" == crane/* ]]; then
39+
echo "should-run=true" >> "$GITHUB_OUTPUT"
40+
exit 0
41+
fi
42+
4743
git diff --name-only \
4844
"${{ github.event.pull_request.base.sha }}" \
4945
"${{ github.event.pull_request.head.sha }}" \
5046
| tee "$RUNNER_TEMP/changed-files.txt"
5147
52-
if grep -Eq '^(\.crane/|cmd/|internal/|pkg/|go\.mod$|go\.sum$|pyproject\.toml$|src/|tests/benchmarks/|tests/unit/test_crane_score\.py$)' "$RUNNER_TEMP/changed-files.txt"; then
48+
if grep -Eq '^(\.crane/|\.github/workflows/migration-ci\.yml$|cmd/|internal/|pkg/|go\.mod$|go\.sum$|pyproject\.toml$|scripts/ci/|src/|tests/benchmarks/|tests/unit/test_crane_score\.py$)' "$RUNNER_TEMP/changed-files.txt"; then
5349
echo "should-run=true" >> "$GITHUB_OUTPUT"
5450
else
5551
echo "should-run=false" >> "$GITHUB_OUTPUT"
@@ -137,11 +133,6 @@ jobs:
137133
- name: Build Go CLI
138134
run: go build -o "$RUNNER_TEMP/apm-go" ./cmd/apm
139135

140-
- name: Run Python performance guards
141-
run: |
142-
uv run pytest tests/benchmarks/test_scaling_guards.py -v
143-
uv run pytest tests/benchmarks -v --tb=short -m benchmark
144-
145136
- name: Run Python-vs-Go CLI benchmark
146137
run: |
147138
python scripts/ci/migration_cli_benchmark.py \
@@ -151,13 +142,52 @@ jobs:
151142
--markdown-out "$RUNNER_TEMP/migration-cli-benchmark.md" \
152143
--max-ratio 5.0
153144
145+
- name: Run Python scaling guards
146+
run: uv run pytest tests/benchmarks/test_scaling_guards.py -v
147+
154148
- name: Add benchmark summary
155149
if: always()
156150
run: |
157151
if [ -f "$RUNNER_TEMP/migration-cli-benchmark.md" ]; then
158152
cat "$RUNNER_TEMP/migration-cli-benchmark.md" >> "$GITHUB_STEP_SUMMARY"
159153
fi
160154
155+
- name: Post benchmark PR comment
156+
if: always() && github.event_name == 'pull_request'
157+
env:
158+
GH_TOKEN: ${{ github.token }}
159+
PR_NUMBER: ${{ github.event.pull_request.number }}
160+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
161+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
162+
run: |
163+
if [ ! -f "$RUNNER_TEMP/migration-cli-benchmark.md" ]; then
164+
echo "No migration benchmark markdown found; skipping PR comment."
165+
exit 0
166+
fi
167+
168+
marker="<!-- apm-migration-benchmark:${HEAD_SHA} -->"
169+
{
170+
echo "$marker"
171+
echo "## Migration Benchmark Results"
172+
echo
173+
echo "- **Commit**: \`${HEAD_SHA}\`"
174+
echo "- **Run**: ${RUN_URL}"
175+
echo
176+
cat "$RUNNER_TEMP/migration-cli-benchmark.md"
177+
} > "$RUNNER_TEMP/migration-benchmark-pr-comment.md"
178+
179+
comment_id=$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" --paginate \
180+
--jq ".[] | select(.body | contains(\"${marker}\")) | .id" | tail -n 1)
181+
182+
if [ -n "$comment_id" ]; then
183+
gh api \
184+
--method PATCH \
185+
"repos/${GITHUB_REPOSITORY}/issues/comments/${comment_id}" \
186+
--field body@"$RUNNER_TEMP/migration-benchmark-pr-comment.md"
187+
else
188+
gh pr comment "$PR_NUMBER" --body-file "$RUNNER_TEMP/migration-benchmark-pr-comment.md"
189+
fi
190+
161191
- name: Upload benchmark evidence
162192
if: always()
163193
uses: actions/upload-artifact@v4

scripts/ci/migration_cli_benchmark.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def _measure(
6060
label: str,
6161
env: dict[str, str],
6262
) -> dict[str, object]:
63+
base.mkdir(parents=True, exist_ok=True)
6364
samples: list[dict[str, object]] = []
6465
for index in range(repeats):
6566
cwd = _workspace(base, label, index) if mutates_workspace else base
@@ -75,22 +76,33 @@ def _measure(
7576
}
7677

7778

79+
def _speed_label(ratio: float) -> str:
80+
if ratio == 0:
81+
return "n/a"
82+
if ratio < 1:
83+
return f"{1 / ratio:.2f}x faster"
84+
if ratio > 1:
85+
return f"{ratio:.2f}x slower"
86+
return "same"
87+
88+
7889
def _markdown(results: list[dict[str, object]], max_ratio: float) -> str:
7990
lines = [
8091
"## Migration CLI Benchmark",
8192
"",
8293
f"Max allowed Go/Python median ratio: `{max_ratio:.2f}`",
8394
"",
84-
"| Command | Python median | Go median | Go/Python | Return codes |",
85-
"|---|---:|---:|---:|---|",
95+
"| Command | Python median | Go median | Go/Python | Result | Return codes |",
96+
"|---|---:|---:|---:|---|---|",
8697
]
8798
for row in results:
8899
lines.append(
89-
"| {command} | {python:.4f}s | {go:.4f}s | {ratio:.2f}x | {codes} |".format(
100+
"| {command} | {python:.4f}s | {go:.4f}s | {ratio:.2f}x | {result} | {codes} |".format(
90101
command=row["command"],
91102
python=row["python_median_seconds"],
92103
go=row["go_median_seconds"],
93104
ratio=row["ratio"],
105+
result=_speed_label(float(row["ratio"])),
94106
codes=row["returncodes"],
95107
)
96108
)

0 commit comments

Comments
 (0)