Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 49 additions & 19 deletions .github/workflows/migration-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,12 @@ name: Migration Parity and Benchmarks
on:
pull_request:
branches: [main]
paths:
- ".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"
workflow_dispatch:

permissions:
contents: read
issues: write
pull-requests: write

env:
PYTHON_VERSION: "3.12"
Expand All @@ -37,19 +26,26 @@ jobs:

- name: Check changed paths
id: filter
env:
HEAD_REF: ${{ github.event.pull_request.head.ref }}
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "should-run=true" >> "$GITHUB_OUTPUT"
exit 0
fi

if [ "${{ github.event_name }}" = "pull_request" ] && [[ "$HEAD_REF" == crane/* ]]; then
echo "should-run=true" >> "$GITHUB_OUTPUT"
exit 0
fi

git diff --name-only \
"${{ github.event.pull_request.base.sha }}" \
"${{ github.event.pull_request.head.sha }}" \
| tee "$RUNNER_TEMP/changed-files.txt"

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
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
echo "should-run=true" >> "$GITHUB_OUTPUT"
else
echo "should-run=false" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -137,11 +133,6 @@ jobs:
- name: Build Go CLI
run: go build -o "$RUNNER_TEMP/apm-go" ./cmd/apm

- name: Run Python performance guards
run: |
uv run pytest tests/benchmarks/test_scaling_guards.py -v
uv run pytest tests/benchmarks -v --tb=short -m benchmark

- name: Run Python-vs-Go CLI benchmark
run: |
python scripts/ci/migration_cli_benchmark.py \
Expand All @@ -151,13 +142,52 @@ jobs:
--markdown-out "$RUNNER_TEMP/migration-cli-benchmark.md" \
--max-ratio 5.0

- name: Run Python scaling guards
run: uv run pytest tests/benchmarks/test_scaling_guards.py -v

- name: Add benchmark summary
if: always()
run: |
if [ -f "$RUNNER_TEMP/migration-cli-benchmark.md" ]; then
cat "$RUNNER_TEMP/migration-cli-benchmark.md" >> "$GITHUB_STEP_SUMMARY"
fi

- name: Post benchmark PR comment
if: always() && github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
if [ ! -f "$RUNNER_TEMP/migration-cli-benchmark.md" ]; then
echo "No migration benchmark markdown found; skipping PR comment."
exit 0
fi

marker="<!-- apm-migration-benchmark:${HEAD_SHA} -->"
{
echo "$marker"
echo "## Migration Benchmark Results"
echo
echo "- **Commit**: \`${HEAD_SHA}\`"
echo "- **Run**: ${RUN_URL}"
echo
cat "$RUNNER_TEMP/migration-cli-benchmark.md"
} > "$RUNNER_TEMP/migration-benchmark-pr-comment.md"

comment_id=$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" --paginate \
--jq ".[] | select(.body | contains(\"${marker}\")) | .id" | tail -n 1)

if [ -n "$comment_id" ]; then
gh api \
--method PATCH \
"repos/${GITHUB_REPOSITORY}/issues/comments/${comment_id}" \
--field body@"$RUNNER_TEMP/migration-benchmark-pr-comment.md"
else
gh pr comment "$PR_NUMBER" --body-file "$RUNNER_TEMP/migration-benchmark-pr-comment.md"
fi

- name: Upload benchmark evidence
if: always()
uses: actions/upload-artifact@v4
Expand Down
18 changes: 15 additions & 3 deletions scripts/ci/migration_cli_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def _measure(
label: str,
env: dict[str, str],
) -> dict[str, object]:
base.mkdir(parents=True, exist_ok=True)
samples: list[dict[str, object]] = []
for index in range(repeats):
cwd = _workspace(base, label, index) if mutates_workspace else base
Expand All @@ -75,22 +76,33 @@ def _measure(
}


def _speed_label(ratio: float) -> str:
if ratio == 0:
return "n/a"
if ratio < 1:
return f"{1 / ratio:.2f}x faster"
if ratio > 1:
return f"{ratio:.2f}x slower"
return "same"


def _markdown(results: list[dict[str, object]], max_ratio: float) -> str:
lines = [
"## Migration CLI Benchmark",
"",
f"Max allowed Go/Python median ratio: `{max_ratio:.2f}`",
"",
"| Command | Python median | Go median | Go/Python | Return codes |",
"|---|---:|---:|---:|---|",
"| Command | Python median | Go median | Go/Python | Result | Return codes |",
"|---|---:|---:|---:|---|---|",
]
for row in results:
lines.append(
"| {command} | {python:.4f}s | {go:.4f}s | {ratio:.2f}x | {codes} |".format(
"| {command} | {python:.4f}s | {go:.4f}s | {ratio:.2f}x | {result} | {codes} |".format(
command=row["command"],
python=row["python_median_seconds"],
go=row["go_median_seconds"],
ratio=row["ratio"],
result=_speed_label(float(row["ratio"])),
codes=row["returncodes"],
)
)
Expand Down
Loading