|
| 1 | +name: Distributions |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +concurrency: |
| 9 | + # Cancel previous runs of this workflow for the same branch |
| 10 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + |
| 15 | + sdists_for_pypi: |
| 16 | + name: Build sdist |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + - uses: actions/setup-python@v4 |
| 21 | + - name: make sdist |
| 22 | + run: | |
| 23 | + python3 -m pip install build |
| 24 | + python3 -m build --sdist |
| 25 | + - uses: actions/upload-artifact@v4 |
| 26 | + with: |
| 27 | + path: "dist/*.tar.gz" |
| 28 | + name: dist |
| 29 | + |
| 30 | + build_wheels: |
| 31 | + name: Build wheels on ${{ matrix.os }}, arch ${{ matrix.arch }} |
| 32 | + runs-on: ${{ matrix.os }} |
| 33 | + needs: sdists_for_pypi |
| 34 | + strategy: |
| 35 | + fail-fast: false |
| 36 | + matrix: |
| 37 | + include: |
| 38 | + - os: ubuntu-latest |
| 39 | + arch: x86_64 |
| 40 | + - os: ubuntu-latest |
| 41 | + arch: i686 |
| 42 | + - os: ubuntu-24.04-arm |
| 43 | + arch: aarch64 |
| 44 | + - os: macos-13 |
| 45 | + arch: auto |
| 46 | + - os: macos-14 |
| 47 | + arch: auto |
| 48 | + env: |
| 49 | + # SPKGs to install as system packages |
| 50 | + SPKGS: _bootstrap _prereq |
| 51 | + # Non-Python packages to install as spkgs |
| 52 | + TARGETS_PRE: gmp mpfr mpc 4ti2-ensure |
| 53 | + # Disable building PyPy wheels on all platforms |
| 54 | + CIBW_SKIP: "pp*" |
| 55 | + # |
| 56 | + CIBW_ARCHS: ${{ matrix.arch }} |
| 57 | + # https://cibuildwheel.readthedocs.io/en/stable/options/#requires-python |
| 58 | + CIBW_PROJECT_REQUIRES_PYTHON: ">=3.9" |
| 59 | + # Environment during wheel build |
| 60 | + CIBW_ENVIRONMENT: "PATH=$(pwd)/local/bin:$PATH CPATH=$(pwd)/local/include:$CPATH LIBRARY_PATH=$(pwd)/local/lib:$LIBRARY_PATH LD_LIBRARY_PATH=$(pwd)/local/lib:$LD_LIBRARY_PATH PKG_CONFIG_PATH=$(pwd)/local/share/pkgconfig:$PKG_CONFIG_PATH ACLOCAL_PATH=/usr/share/aclocal" |
| 61 | + # Use 'build', not 'pip wheel' |
| 62 | + CIBW_BUILD_FRONTEND: build |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v4 |
| 65 | + with: |
| 66 | + repository: passagemath/passagemath |
| 67 | + ref: main |
| 68 | + |
| 69 | + - uses: actions/download-artifact@v4 |
| 70 | + with: |
| 71 | + name: dist |
| 72 | + path: dist |
| 73 | + |
| 74 | + - uses: actions/setup-python@v5 |
| 75 | + # As of 2024-02-03, the macOS M1 runners do not have preinstalled python or pipx. |
| 76 | + # Installing pipx follows the approach of https://github.com/pypa/cibuildwheel/pull/1743 |
| 77 | + id: python |
| 78 | + with: |
| 79 | + python-version: "3.9 - 3.13" |
| 80 | + update-environment: false |
| 81 | + |
| 82 | + - name: Build platform wheels |
| 83 | + # We build the wheel from the sdist. |
| 84 | + # But we must run cibuildwheel with the unpacked source directory, not a tarball, |
| 85 | + # so that SAGE_ROOT is copied into the build containers. |
| 86 | + # |
| 87 | + # In the CIBW_BEFORE_ALL phase, we install libraries using the Sage distribution. |
| 88 | + # https://cibuildwheel.readthedocs.io/en/stable/options/#before-all |
| 89 | + run: | |
| 90 | + "${{ steps.python.outputs.python-path }}" -m pip install pipx |
| 91 | + export PATH=build/bin:$PATH |
| 92 | + export CIBW_BEFORE_ALL="( $(sage-print-system-package-command debian --yes --no-install-recommends install $(sage-get-system-packages debian $SPKGS)) || $(sage-print-system-package-command fedora --yes --no-install-recommends install $(sage-get-system-packages fedora $SPKGS | sed s/pkg-config/pkgconfig/)) || ( $(sage-print-system-package-command homebrew --yes --no-install-recommends install $(sage-get-system-packages homebrew $SPKGS)) || $(sage-print-system-package-command alpine --yes --no-install-recommends install $(sage-get-system-packages alpine $SPKGS)) || echo error ignored) ) && ./bootstrap && ./configure --enable-build-as-root --enable-fat-binary && MAKE=\"make -j6\" make V=0 $TARGETS_PRE" |
| 93 | + mkdir -p unpacked |
| 94 | + for pkg in py4ti2; do |
| 95 | + (cd unpacked && tar xfz - ) < dist/$pkg*.tar.gz |
| 96 | + "${{ steps.python.outputs.python-path }}" -m pipx run cibuildwheel==2.21.3 unpacked/$pkg* |
| 97 | + done |
| 98 | +
|
| 99 | + - uses: actions/upload-artifact@v4 |
| 100 | + with: |
| 101 | + name: ${{ matrix.os }}-${{ matrix.arch }}-wheels |
| 102 | + path: ./wheelhouse/*.whl |
| 103 | + |
| 104 | + pypi-publish: |
| 105 | + needs: build_wheels |
| 106 | + name: Upload release to PyPI |
| 107 | + runs-on: ubuntu-latest |
| 108 | + environment: |
| 109 | + name: pypi |
| 110 | + url: https://pypi.org/p/py4ti2 |
| 111 | + permissions: |
| 112 | + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing |
| 113 | + steps: |
| 114 | + - uses: actions/download-artifact@v4 |
| 115 | + with: |
| 116 | + pattern: "*-wheels" |
| 117 | + path: dist |
| 118 | + merge-multiple: true |
| 119 | + - uses: actions/download-artifact@v4 |
| 120 | + with: |
| 121 | + pattern: "dist" |
| 122 | + path: dist |
| 123 | + merge-multiple: true |
| 124 | + - name: Publish package distributions to PyPI |
| 125 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 126 | + with: |
| 127 | + # trusted publishing - no user/password required |
| 128 | + ## user: __token__ |
| 129 | + ## password: ${{ secrets.SAGEMATH_PYPI_API_TOKEN }} |
| 130 | + skip_existing: true |
| 131 | + verbose: true |
| 132 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') |
0 commit comments