|
| 1 | +name: Publish To PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: |
| 6 | + - published |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +jobs: |
| 13 | + build-sdist: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + - uses: actions/setup-python@v5 |
| 18 | + with: |
| 19 | + python-version: "3.12" |
| 20 | + - name: Install build tooling |
| 21 | + run: python -m pip install --upgrade pip build twine |
| 22 | + - name: Build source distribution |
| 23 | + run: python -m build --sdist |
| 24 | + - name: Check source distribution |
| 25 | + run: python -m twine check dist/* |
| 26 | + - name: Upload source distribution |
| 27 | + uses: actions/upload-artifact@v4 |
| 28 | + with: |
| 29 | + name: python-sdist |
| 30 | + path: dist/ |
| 31 | + |
| 32 | + build-wheels: |
| 33 | + name: Build wheels on ${{ matrix.os }} |
| 34 | + runs-on: ${{ matrix.os }} |
| 35 | + strategy: |
| 36 | + fail-fast: false |
| 37 | + matrix: |
| 38 | + os: [ubuntu-latest, windows-latest, macos-latest] # macos-latest = Apple Silicon arm64 |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + - name: Build wheels |
| 42 | + uses: pypa/cibuildwheel@v2.23.3 |
| 43 | + env: |
| 44 | + # arda ships a pybind11/scikit-build-core C++ ext (src/_markup); scikit-build-core |
| 45 | + # pulls cmake + ninja into the build env automatically. |
| 46 | + CIBW_BUILD: "cp310-* cp311-* cp312-* cp313-*" |
| 47 | + CIBW_SKIP: "*-musllinux_* *-manylinux_i686 *-win32" |
| 48 | + CIBW_TEST_SKIP: "*" |
| 49 | + - name: Upload wheel artifacts |
| 50 | + uses: actions/upload-artifact@v4 |
| 51 | + with: |
| 52 | + name: python-wheels-${{ matrix.os }} |
| 53 | + path: wheelhouse/*.whl |
| 54 | + |
| 55 | + test-wheels: |
| 56 | + name: Smoke-test wheel (${{ matrix.os }}, py${{ matrix.python-version }}) |
| 57 | + needs: build-wheels |
| 58 | + strategy: |
| 59 | + fail-fast: false |
| 60 | + matrix: |
| 61 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 62 | + python-version: ["3.10", "3.11", "3.12", "3.13"] |
| 63 | + include: |
| 64 | + - os: ubuntu-latest |
| 65 | + artifact: python-wheels-ubuntu-latest |
| 66 | + - os: windows-latest |
| 67 | + artifact: python-wheels-windows-latest |
| 68 | + - os: macos-latest |
| 69 | + artifact: python-wheels-macos-latest |
| 70 | + runs-on: ${{ matrix.os }} |
| 71 | + steps: |
| 72 | + - uses: actions/setup-python@v5 |
| 73 | + with: |
| 74 | + python-version: ${{ matrix.python-version }} |
| 75 | + - name: Download wheel artifacts |
| 76 | + uses: actions/download-artifact@v4 |
| 77 | + with: |
| 78 | + name: ${{ matrix.artifact }} |
| 79 | + path: wheels/ |
| 80 | + - name: Install wheel and import arda |
| 81 | + shell: bash |
| 82 | + run: | |
| 83 | + pip install --upgrade pip |
| 84 | + tag="cp${{ matrix.python-version }}"; tag="${tag/./}" |
| 85 | + python - "$tag" <<'PY' |
| 86 | + import sys, glob, subprocess |
| 87 | + tag = sys.argv[1] |
| 88 | + matches = sorted(glob.glob(f"wheels/arda_mapper-*-{tag}-*.whl")) |
| 89 | + if len(matches) != 1: |
| 90 | + raise SystemExit(f"expected 1 wheel for {tag}, found {len(matches)}: {matches}") |
| 91 | + subprocess.check_call([sys.executable, "-m", "pip", "install", matches[0]]) |
| 92 | + PY |
| 93 | + python -c "import arda; print('[OK] arda', arda.__version__)" |
| 94 | +
|
| 95 | + publish: |
| 96 | + name: Publish To PyPI |
| 97 | + needs: [build-sdist, build-wheels, test-wheels] |
| 98 | + runs-on: ubuntu-latest |
| 99 | + environment: pypi |
| 100 | + permissions: |
| 101 | + contents: read |
| 102 | + id-token: write # required for OIDC trusted publishing |
| 103 | + steps: |
| 104 | + - uses: actions/checkout@v4 |
| 105 | + - name: Download distributions |
| 106 | + uses: actions/download-artifact@v4 |
| 107 | + with: |
| 108 | + pattern: python-* |
| 109 | + merge-multiple: true |
| 110 | + path: dist/ |
| 111 | + - name: Validate package version matches release tag |
| 112 | + if: github.event_name == 'release' |
| 113 | + run: | |
| 114 | + python - <<'PY' |
| 115 | + from pathlib import Path |
| 116 | + import tomllib |
| 117 | + version = tomllib.loads(Path("pyproject.toml").read_text())["project"]["version"] |
| 118 | + tag = "${{ github.event.release.tag_name }}" |
| 119 | + norm = tag[1:] if tag.startswith("v") else tag |
| 120 | + if version != norm: |
| 121 | + raise SystemExit(f"Version mismatch: pyproject.toml={version}, tag={tag}") |
| 122 | + print(f"Version check passed: {version} == {tag}") |
| 123 | + PY |
| 124 | + - name: List distributions |
| 125 | + run: ls -R dist/ |
| 126 | + - name: Publish distributions to PyPI |
| 127 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments