|
| 1 | +# Continuous integration. |
| 2 | +# |
| 3 | +# Four jobs: lint (seconds), the test matrix, mypy, and a packaging check. |
| 4 | +# |
| 5 | +# python-wrap is pure Python with no dependencies, so the matrix is wide rather than |
| 6 | +# deep: every interpreter the classifiers name, on all three operating systems. Time and |
| 7 | +# threading behave differently on Windows (coarser clocks) and macOS (spawn, not fork), |
| 8 | +# and a decorator library that schedules, throttles and times things is exactly where |
| 9 | +# that shows up. |
| 10 | +name: CI |
| 11 | + |
| 12 | +on: |
| 13 | + push: |
| 14 | + branches: [main] |
| 15 | + pull_request: |
| 16 | + workflow_dispatch: |
| 17 | + |
| 18 | +# A force-push should not leave the previous run burning minutes on a dead commit. |
| 19 | +concurrency: |
| 20 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 21 | + cancel-in-progress: true |
| 22 | + |
| 23 | +permissions: |
| 24 | + contents: read |
| 25 | + |
| 26 | +env: |
| 27 | + FORCE_COLOR: "1" |
| 28 | + |
| 29 | +jobs: |
| 30 | + lint: |
| 31 | + name: ruff |
| 32 | + runs-on: ubuntu-latest |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v7 |
| 35 | + |
| 36 | + - name: Install uv |
| 37 | + uses: astral-sh/setup-uv@v10.3.2 |
| 38 | + with: |
| 39 | + enable-cache: true |
| 40 | + cache-dependency-glob: "uv.lock" |
| 41 | + python-version: "3.13" |
| 42 | + |
| 43 | + - run: uv sync --group dev --frozen |
| 44 | + |
| 45 | + - name: ruff check |
| 46 | + run: uv run --no-sync ruff check src tests |
| 47 | + |
| 48 | + - name: ruff format |
| 49 | + run: uv run --no-sync ruff format --check --diff src tests |
| 50 | + |
| 51 | + test: |
| 52 | + name: py${{ matrix.python-version }} · ${{ matrix.os }} |
| 53 | + runs-on: ${{ matrix.os }} |
| 54 | + strategy: |
| 55 | + # One red cell should not hide the other fourteen. |
| 56 | + fail-fast: false |
| 57 | + matrix: |
| 58 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 59 | + python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] |
| 60 | + |
| 61 | + steps: |
| 62 | + - uses: actions/checkout@v7 |
| 63 | + |
| 64 | + - name: Install uv |
| 65 | + uses: astral-sh/setup-uv@v10.3.2 |
| 66 | + with: |
| 67 | + enable-cache: true |
| 68 | + cache-dependency-glob: "uv.lock" |
| 69 | + python-version: ${{ matrix.python-version }} |
| 70 | + |
| 71 | + - run: uv sync --group dev --frozen |
| 72 | + |
| 73 | + - name: pytest |
| 74 | + run: uv run --no-sync pytest --cov --cov-report=term-missing --cov-report=xml |
| 75 | + |
| 76 | + # One coverage report is enough; it is the same code on every cell. Keeping it as an |
| 77 | + # artifact (rather than a third-party upload) needs no token and cannot fail the |
| 78 | + # build for a reason unrelated to the code. |
| 79 | + - name: Upload the coverage report |
| 80 | + if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.13' |
| 81 | + uses: actions/upload-artifact@v7 |
| 82 | + with: |
| 83 | + name: coverage |
| 84 | + path: coverage.xml |
| 85 | + if-no-files-found: warn |
| 86 | + |
| 87 | + typecheck: |
| 88 | + name: mypy |
| 89 | + runs-on: ubuntu-latest |
| 90 | + steps: |
| 91 | + - uses: actions/checkout@v7 |
| 92 | + |
| 93 | + - name: Install uv |
| 94 | + uses: astral-sh/setup-uv@v10.3.2 |
| 95 | + with: |
| 96 | + enable-cache: true |
| 97 | + cache-dependency-glob: "uv.lock" |
| 98 | + python-version: "3.13" |
| 99 | + |
| 100 | + - run: uv sync --group dev --frozen |
| 101 | + |
| 102 | + # Strict mode, configured in pyproject.toml; `files` already points at src/. |
| 103 | + - name: mypy |
| 104 | + run: uv run --no-sync mypy |
| 105 | + |
| 106 | + build: |
| 107 | + name: build & wheel contents |
| 108 | + runs-on: ubuntu-latest |
| 109 | + steps: |
| 110 | + - uses: actions/checkout@v7 |
| 111 | + |
| 112 | + - name: Install uv |
| 113 | + uses: astral-sh/setup-uv@v10.3.2 |
| 114 | + with: |
| 115 | + enable-cache: true |
| 116 | + cache-dependency-glob: "uv.lock" |
| 117 | + python-version: "3.13" |
| 118 | + |
| 119 | + - name: Build the sdist and wheel |
| 120 | + run: uv build |
| 121 | + |
| 122 | + - name: twine check |
| 123 | + run: uvx twine check --strict dist/* |
| 124 | + |
| 125 | + # The package ships `py.typed` so that type checkers use its annotations. A wheel |
| 126 | + # that drops it still imports and still passes twine, and silently turns every |
| 127 | + # downstream user's types into `Any`. |
| 128 | + - name: The wheel ships py.typed |
| 129 | + run: | |
| 130 | + python3 -m zipfile -l dist/*.whl | tee wheel-listing.txt |
| 131 | + grep -q 'python_wrap/py.typed' wheel-listing.txt |
| 132 | +
|
| 133 | + # Install the built wheel, not the source tree, into an empty venv and run from a |
| 134 | + # scratch directory so `src/` cannot stand in for anything the wheel left out. |
| 135 | + - name: Install the wheel into a clean environment |
| 136 | + run: | |
| 137 | + uv venv "$RUNNER_TEMP/smoke" --python 3.13 |
| 138 | + uv pip install --python "$RUNNER_TEMP/smoke" dist/*.whl |
| 139 | + cd "$RUNNER_TEMP" |
| 140 | + "$RUNNER_TEMP/smoke/bin/python" -c "import python_wrap; print(python_wrap.__version__)" |
| 141 | +
|
| 142 | + - name: Upload the distributions |
| 143 | + uses: actions/upload-artifact@v7 |
| 144 | + with: |
| 145 | + name: dist |
| 146 | + path: dist/ |
| 147 | + if-no-files-found: error |
0 commit comments