Require exhaustive Python behavior parity before Go cutover #20
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Migration Parity and Benchmarks | |
| on: | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| issues: write | |
| pull-requests: write | |
| env: | |
| PYTHON_VERSION: "3.12" | |
| jobs: | |
| detect-changes: | |
| name: Detect Migration Changes | |
| runs-on: ubuntu-24.04 | |
| outputs: | |
| should-run: ${{ steps.filter.outputs.should-run }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - 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/|\.github/workflows/migration-ci\.yml$|cmd/|internal/|pkg/|go\.mod$|go\.sum$|pyproject\.toml$|scripts/ci/|src/|tests/benchmarks/|tests/parity/|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" | |
| fi | |
| parity: | |
| name: Python-vs-Go Parity Gate | |
| needs: [detect-changes] | |
| if: needs.detect-changes.outputs.should-run == 'true' | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - uses: astral-sh/setup-uv@v6 | |
| with: | |
| enable-cache: true | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Install Python reference CLI | |
| run: | | |
| uv sync --extra dev | |
| test -x "$GITHUB_WORKSPACE/.venv/bin/apm" | |
| echo "APM_PYTHON_BIN=$GITHUB_WORKSPACE/.venv/bin/apm" >> "$GITHUB_ENV" | |
| - name: Extract Python behavior contracts | |
| run: | | |
| uv run python scripts/ci/python_behavior_contracts.py extract \ | |
| --output "$RUNNER_TEMP/python-behavior-contracts.json" | |
| echo "APM_PYTHON_CONTRACT_INVENTORY=$RUNNER_TEMP/python-behavior-contracts.json" >> "$GITHUB_ENV" | |
| - name: Run CLI-agnostic Python behavior tests | |
| shell: bash | |
| run: | | |
| go build -o "$RUNNER_TEMP/apm-go" ./cmd/apm | |
| set +e | |
| APM_GO_BIN="$RUNNER_TEMP/apm-go" \ | |
| uv run pytest tests/parity/test_python_behavior_contracts.py -q --tb=short \ | |
| | tee "$RUNNER_TEMP/python-cli-contract-tests.txt" | |
| status=${PIPESTATUS[0]} | |
| set -e | |
| echo "PYTHON_CLI_CONTRACT_STATUS=$status" >> "$GITHUB_ENV" | |
| - name: Run Go parity tests | |
| shell: bash | |
| run: | | |
| set +e | |
| go test -json ./... | tee "$RUNNER_TEMP/go-test-events.json" | |
| status=${PIPESTATUS[0]} | |
| set -e | |
| echo "GO_TEST_STATUS=$status" >> "$GITHUB_ENV" | |
| - name: Compute migration score | |
| run: | | |
| go run .crane/scripts/score.go < "$RUNNER_TEMP/go-test-events.json" | tee "$RUNNER_TEMP/migration-score.json" | |
| uv run python scripts/ci/python_behavior_contracts.py check \ | |
| --inventory "$RUNNER_TEMP/python-behavior-contracts.json" \ | |
| --coverage tests/parity/python_contract_coverage.yml \ | |
| --summary "$RUNNER_TEMP/python-contract-coverage.md" || true | |
| python - "$RUNNER_TEMP/migration-score.json" <<'PY' | |
| import json | |
| import sys | |
| with open(sys.argv[1], encoding="utf-8") as fh: | |
| score = json.load(fh) | |
| print(json.dumps(score, indent=2, sort_keys=True)) | |
| if score.get("migration_score") != 1.0: | |
| raise SystemExit("migration_score must be 1.0 for completion parity") | |
| PY | |
| test "${PYTHON_CLI_CONTRACT_STATUS:-1}" = "0" | |
| test "${GO_TEST_STATUS:-1}" = "0" | |
| - name: Upload parity evidence | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: migration-parity-evidence | |
| path: | | |
| ${{ runner.temp }}/go-test-events.json | |
| ${{ runner.temp }}/migration-score.json | |
| ${{ runner.temp }}/python-behavior-contracts.json | |
| ${{ runner.temp }}/python-contract-coverage.md | |
| ${{ runner.temp }}/python-cli-contract-tests.txt | |
| if-no-files-found: ignore | |
| retention-days: 14 | |
| benchmarks: | |
| name: Migration Benchmarks | |
| needs: [detect-changes, parity] | |
| if: always() && needs.detect-changes.outputs.should-run == 'true' | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - uses: astral-sh/setup-uv@v6 | |
| with: | |
| enable-cache: true | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Install dependencies | |
| run: uv sync --extra dev | |
| - name: Build Go CLI | |
| run: go build -o "$RUNNER_TEMP/apm-go" ./cmd/apm | |
| - name: Run Python-vs-Go CLI benchmark | |
| run: | | |
| python scripts/ci/migration_cli_benchmark.py \ | |
| --python-bin "$GITHUB_WORKSPACE/.venv/bin/apm" \ | |
| --go-bin "$RUNNER_TEMP/apm-go" \ | |
| --json-out "$RUNNER_TEMP/migration-cli-benchmark.json" \ | |
| --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 | |
| with: | |
| name: migration-benchmark-evidence | |
| path: | | |
| ${{ runner.temp }}/migration-cli-benchmark.json | |
| ${{ runner.temp }}/migration-cli-benchmark.md | |
| if-no-files-found: ignore | |
| retention-days: 14 |