|
| 1 | +name: Migration Parity and Benchmarks |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + 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" |
| 19 | + workflow_dispatch: |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: read |
| 23 | + |
| 24 | +env: |
| 25 | + PYTHON_VERSION: "3.12" |
| 26 | + |
| 27 | +jobs: |
| 28 | + detect-changes: |
| 29 | + name: Detect Migration Changes |
| 30 | + runs-on: ubuntu-24.04 |
| 31 | + outputs: |
| 32 | + should-run: ${{ steps.filter.outputs.should-run }} |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + fetch-depth: 0 |
| 37 | + |
| 38 | + - name: Check changed paths |
| 39 | + id: filter |
| 40 | + shell: bash |
| 41 | + run: | |
| 42 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 43 | + echo "should-run=true" >> "$GITHUB_OUTPUT" |
| 44 | + exit 0 |
| 45 | + fi |
| 46 | +
|
| 47 | + git diff --name-only \ |
| 48 | + "${{ github.event.pull_request.base.sha }}" \ |
| 49 | + "${{ github.event.pull_request.head.sha }}" \ |
| 50 | + | tee "$RUNNER_TEMP/changed-files.txt" |
| 51 | +
|
| 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 |
| 53 | + echo "should-run=true" >> "$GITHUB_OUTPUT" |
| 54 | + else |
| 55 | + echo "should-run=false" >> "$GITHUB_OUTPUT" |
| 56 | + fi |
| 57 | +
|
| 58 | + parity: |
| 59 | + name: Python-vs-Go Parity Gate |
| 60 | + needs: [detect-changes] |
| 61 | + if: needs.detect-changes.outputs.should-run == 'true' |
| 62 | + runs-on: ubuntu-24.04 |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v4 |
| 65 | + |
| 66 | + - uses: actions/setup-python@v5 |
| 67 | + with: |
| 68 | + python-version: ${{ env.PYTHON_VERSION }} |
| 69 | + |
| 70 | + - uses: astral-sh/setup-uv@v6 |
| 71 | + with: |
| 72 | + enable-cache: true |
| 73 | + |
| 74 | + - uses: actions/setup-go@v5 |
| 75 | + with: |
| 76 | + go-version-file: go.mod |
| 77 | + cache: true |
| 78 | + |
| 79 | + - name: Install Python reference CLI |
| 80 | + run: | |
| 81 | + uv sync --extra dev |
| 82 | + test -x "$GITHUB_WORKSPACE/.venv/bin/apm" |
| 83 | + echo "APM_PYTHON_BIN=$GITHUB_WORKSPACE/.venv/bin/apm" >> "$GITHUB_ENV" |
| 84 | +
|
| 85 | + - name: Run Go parity tests |
| 86 | + run: go test ./... |
| 87 | + |
| 88 | + - name: Compute migration score |
| 89 | + run: | |
| 90 | + go test -json ./... | tee "$RUNNER_TEMP/go-test-events.json" | go run .crane/scripts/score.go | tee "$RUNNER_TEMP/migration-score.json" |
| 91 | + python - "$RUNNER_TEMP/migration-score.json" <<'PY' |
| 92 | + import json |
| 93 | + import sys |
| 94 | +
|
| 95 | + with open(sys.argv[1], encoding="utf-8") as fh: |
| 96 | + score = json.load(fh) |
| 97 | +
|
| 98 | + print(json.dumps(score, indent=2, sort_keys=True)) |
| 99 | + if score.get("migration_score") != 1.0: |
| 100 | + raise SystemExit("migration_score must be 1.0 for completion parity") |
| 101 | + PY |
| 102 | +
|
| 103 | + - name: Upload parity evidence |
| 104 | + if: always() |
| 105 | + uses: actions/upload-artifact@v4 |
| 106 | + with: |
| 107 | + name: migration-parity-evidence |
| 108 | + path: | |
| 109 | + ${{ runner.temp }}/go-test-events.json |
| 110 | + ${{ runner.temp }}/migration-score.json |
| 111 | + if-no-files-found: ignore |
| 112 | + retention-days: 14 |
| 113 | + |
| 114 | + benchmarks: |
| 115 | + name: Migration Benchmarks |
| 116 | + needs: [parity] |
| 117 | + runs-on: ubuntu-24.04 |
| 118 | + steps: |
| 119 | + - uses: actions/checkout@v4 |
| 120 | + |
| 121 | + - uses: actions/setup-python@v5 |
| 122 | + with: |
| 123 | + python-version: ${{ env.PYTHON_VERSION }} |
| 124 | + |
| 125 | + - uses: astral-sh/setup-uv@v6 |
| 126 | + with: |
| 127 | + enable-cache: true |
| 128 | + |
| 129 | + - uses: actions/setup-go@v5 |
| 130 | + with: |
| 131 | + go-version-file: go.mod |
| 132 | + cache: true |
| 133 | + |
| 134 | + - name: Install dependencies |
| 135 | + run: uv sync --extra dev |
| 136 | + |
| 137 | + - name: Build Go CLI |
| 138 | + run: go build -o "$RUNNER_TEMP/apm-go" ./cmd/apm |
| 139 | + |
| 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 | +
|
| 145 | + - name: Run Python-vs-Go CLI benchmark |
| 146 | + run: | |
| 147 | + python scripts/ci/migration_cli_benchmark.py \ |
| 148 | + --python-bin "$GITHUB_WORKSPACE/.venv/bin/apm" \ |
| 149 | + --go-bin "$RUNNER_TEMP/apm-go" \ |
| 150 | + --json-out "$RUNNER_TEMP/migration-cli-benchmark.json" \ |
| 151 | + --markdown-out "$RUNNER_TEMP/migration-cli-benchmark.md" \ |
| 152 | + --max-ratio 5.0 |
| 153 | +
|
| 154 | + - name: Add benchmark summary |
| 155 | + if: always() |
| 156 | + run: | |
| 157 | + if [ -f "$RUNNER_TEMP/migration-cli-benchmark.md" ]; then |
| 158 | + cat "$RUNNER_TEMP/migration-cli-benchmark.md" >> "$GITHUB_STEP_SUMMARY" |
| 159 | + fi |
| 160 | +
|
| 161 | + - name: Upload benchmark evidence |
| 162 | + if: always() |
| 163 | + uses: actions/upload-artifact@v4 |
| 164 | + with: |
| 165 | + name: migration-benchmark-evidence |
| 166 | + path: | |
| 167 | + ${{ runner.temp }}/migration-cli-benchmark.json |
| 168 | + ${{ runner.temp }}/migration-cli-benchmark.md |
| 169 | + if-no-files-found: ignore |
| 170 | + retention-days: 14 |
0 commit comments