|
| 1 | +name: "Intelligent Python Testing" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + types: [opened, synchronize, reopened] |
| 8 | + branches: [ main ] |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: intelligent-${{ github.event.pull_request.number && format('pr-{0}', github.event.pull_request.number) || format('run-{0}', github.run_id) }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +jobs: |
| 18 | + intelligent-test-selection: |
| 19 | + name: Select test plan |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + run_skip: ${{ steps.selector.outputs.run_skip }} |
| 23 | + run_docs: ${{ steps.selector.outputs.run_docs }} |
| 24 | + run_fast: ${{ steps.selector.outputs.run_fast }} |
| 25 | + run_full: ${{ steps.selector.outputs.run_full }} |
| 26 | + selected_workflows: ${{ steps.selector.outputs.selected_workflows }} |
| 27 | + lane_reasons: ${{ steps.selector.outputs.lane_reasons }} |
| 28 | + pytest_paths: ${{ steps.selector.outputs.pytest_paths }} |
| 29 | + functional_scripts: ${{ steps.selector.outputs.functional_scripts }} |
| 30 | + reasons: ${{ steps.selector.outputs.reasons }} |
| 31 | + changed_files: ${{ steps.selector.outputs.changed_files }} |
| 32 | + provenance: ${{ steps.selector.outputs.provenance }} |
| 33 | + steps: |
| 34 | + - name: Checkout code |
| 35 | + uses: actions/checkout@v6 |
| 36 | + with: |
| 37 | + fetch-depth: 0 # needed for merge-base/diff to be reliable |
| 38 | + |
| 39 | + - name: Set up Python |
| 40 | + uses: actions/setup-python@v6 |
| 41 | + with: |
| 42 | + python-version: "3.12" |
| 43 | + |
| 44 | + - name: Run selector + generate report |
| 45 | + id: selector |
| 46 | + run: | |
| 47 | + python -m pip install --upgrade pip |
| 48 | + pip install "pydantic>=2,<3" |
| 49 | + python tools/test_selector.py \ |
| 50 | + --write-github-output \ |
| 51 | + --write-summary \ |
| 52 | + --report-dir tmp/test-selection \ |
| 53 | + --json |
| 54 | +
|
| 55 | + - name: Upload selector report |
| 56 | + uses: actions/upload-artifact@v6 |
| 57 | + with: |
| 58 | + name: test-selection-report |
| 59 | + path: | |
| 60 | + tmp/test-selection/selection.json |
| 61 | + tmp/test-selection/decision.md |
| 62 | + retention-days: 7 |
| 63 | + if-no-files-found: error |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + skip: |
| 68 | + name: Skipped (lint config change) |
| 69 | + needs: intelligent-test-selection |
| 70 | + if: needs.intelligent-test-selection.outputs.run_skip == 'true' |
| 71 | + runs-on: ubuntu-latest |
| 72 | + steps: |
| 73 | + - run: | |
| 74 | + echo "Only lint config files changed; skipping docs/tests." |
| 75 | + echo "Pre-commit workflow is responsible for lint config validation." |
| 76 | +
|
| 77 | +
|
| 78 | + docs: |
| 79 | + name: Docs build |
| 80 | + needs: intelligent-test-selection |
| 81 | + if: needs.intelligent-test-selection.outputs.run_docs == 'true' |
| 82 | + uses: ./.github/workflows/build-book.yml |
| 83 | + with: |
| 84 | + python-version: "3.10" |
| 85 | + build_dir: "./_build/html" |
| 86 | + upload_artifact: false |
| 87 | + secrets: inherit |
| 88 | + |
| 89 | + |
| 90 | + fast-tests: |
| 91 | + name: Fast lane (targeted pytest + selected functional) |
| 92 | + needs: intelligent-test-selection |
| 93 | + if: needs.intelligent-test-selection.outputs.run_fast == 'true' |
| 94 | + runs-on: ubuntu-latest |
| 95 | + steps: |
| 96 | + - name: Checkout code |
| 97 | + uses: actions/checkout@v6 |
| 98 | + |
| 99 | + - name: Setup Python |
| 100 | + uses: actions/setup-python@v6 |
| 101 | + with: |
| 102 | + python-version: "3.12" |
| 103 | + |
| 104 | + - name: Install test deps |
| 105 | + run: | |
| 106 | + python -m pip install --upgrade pip |
| 107 | + pip install pytest |
| 108 | + pip install -e ".[tf]" --group dev |
| 109 | +
|
| 110 | + - name: Run targeted pytest (paths selected by selector) |
| 111 | + env: |
| 112 | + PYTEST_PATHS: ${{ needs.intelligent-test-selection.outputs.pytest_paths }} |
| 113 | + run: | |
| 114 | + python - << 'PY' |
| 115 | + import json, os, subprocess, sys |
| 116 | + paths = json.loads(os.environ.get("PYTEST_PATHS", "[]")) |
| 117 | + if not paths: |
| 118 | + print("No pytest paths selected; skipping targeted pytest.") |
| 119 | + sys.exit(0) |
| 120 | + cmd = ["python", "-m", "pytest"] + paths |
| 121 | + print("Running:", " ".join(cmd)) |
| 122 | + sys.exit(subprocess.call(cmd)) |
| 123 | + PY |
| 124 | +
|
| 125 | + - name: Run selected functional scripts |
| 126 | + env: |
| 127 | + FUN_SCRIPTS: ${{ needs.intelligent-test-selection.outputs.functional_scripts }} |
| 128 | + run: | |
| 129 | + python - << 'PY' |
| 130 | + import json, os, subprocess, sys |
| 131 | + scripts = json.loads(os.environ.get("FUN_SCRIPTS", "[]")) |
| 132 | + for s in scripts: |
| 133 | + print("Running:", s) |
| 134 | + rc = subprocess.call(["python", s]) |
| 135 | + if rc != 0: |
| 136 | + sys.exit(rc) |
| 137 | + PY |
| 138 | +
|
| 139 | + full-tests: |
| 140 | + name: Full matrix tests |
| 141 | + needs: intelligent-test-selection |
| 142 | + if: needs.intelligent-test-selection.outputs.run_full == 'true' |
| 143 | + uses: ./.github/workflows/python-package.yml |
| 144 | + with: |
| 145 | + concurrency_key: ${{ github.event.pull_request.number && format('pr-{0}', github.event.pull_request.number) || '' }} |
0 commit comments