|
| 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 (and upload to PyPI on release tags) |
| 17 | + runs-on: ubuntu-latest |
| 18 | + env: |
| 19 | + CAN_DEPLOY: ${{ secrets.SAGEMATH_PYPI_API_TOKEN != '' }} |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + - uses: actions/setup-python@v4 |
| 23 | + - name: make sdist |
| 24 | + run: | |
| 25 | + python3 -m pip install build |
| 26 | + python3 -m build --sdist |
| 27 | + - uses: actions/upload-artifact@v4 |
| 28 | + with: |
| 29 | + path: "dist/*.tar.gz" |
| 30 | + name: dist |
| 31 | + - uses: pypa/gh-action-pypi-publish@release/v1 |
| 32 | + with: |
| 33 | + user: __token__ |
| 34 | + password: ${{ secrets.SAGEMATH_PYPI_API_TOKEN }} |
| 35 | + skip_existing: true |
| 36 | + verbose: true |
| 37 | + if: env.CAN_DEPLOY == 'true' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags') |
| 38 | + |
| 39 | + build_wheels: |
| 40 | + name: Build wheels on ${{ matrix.os }}, arch ${{ matrix.arch }} |
| 41 | + runs-on: ${{ matrix.os }} |
| 42 | + needs: sdists_for_pypi |
| 43 | + strategy: |
| 44 | + fail-fast: false |
| 45 | + matrix: |
| 46 | + include: |
| 47 | + - os: ubuntu-latest |
| 48 | + arch: x86_64 |
| 49 | + - os: ubuntu-latest |
| 50 | + arch: i686 |
| 51 | + - os: macos-13 |
| 52 | + arch: x86_64 |
| 53 | + - os: macos-14 |
| 54 | + arch: arm64 |
| 55 | + env: |
| 56 | + # SPKGs to install as system packages |
| 57 | + SPKGS: _bootstrap _prereq |
| 58 | + # Non-Python packages to install as spkgs |
| 59 | + TARGETS_PRE: coin-build-deps |
| 60 | + # Disable building PyPy wheels on all platforms |
| 61 | + # Disable musllinux until #33083 provides alpine package information |
| 62 | + CIBW_SKIP: "pp* *-musllinux*" |
| 63 | + # |
| 64 | + CIBW_ARCHS: ${{ matrix.arch }} |
| 65 | + # https://cibuildwheel.readthedocs.io/en/stable/options/#requires-python |
| 66 | + CIBW_PROJECT_REQUIRES_PYTHON: ">=3.9" |
| 67 | + # Environment during wheel build |
| 68 | + 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" |
| 69 | + # Use 'build', not 'pip wheel' |
| 70 | + CIBW_BUILD_FRONTEND: build |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v4 |
| 73 | + with: |
| 74 | + repository: sagemath/sage |
| 75 | + ref: develop |
| 76 | + |
| 77 | + - uses: actions/download-artifact@v4 |
| 78 | + with: |
| 79 | + name: dist |
| 80 | + path: dist |
| 81 | + |
| 82 | + - uses: actions/setup-python@v5 |
| 83 | + # As of 2024-02-03, the macOS M1 runners do not have preinstalled python or pipx. |
| 84 | + # Installing pipx follows the approach of https://github.com/pypa/cibuildwheel/pull/1743 |
| 85 | + id: python |
| 86 | + with: |
| 87 | + python-version: "3.8 - 3.12" |
| 88 | + update-environment: false |
| 89 | + |
| 90 | + - name: Build platform wheels |
| 91 | + # We build the wheel from the sdist. |
| 92 | + # But we must run cibuildwheel with the unpacked source directory, not a tarball, |
| 93 | + # so that SAGE_ROOT is copied into the build containers. |
| 94 | + # |
| 95 | + # In the CIBW_BEFORE_ALL phase, we install libraries using the Sage distribution. |
| 96 | + # https://cibuildwheel.readthedocs.io/en/stable/options/#before-all |
| 97 | + run: | |
| 98 | + "${{ steps.python.outputs.python-path }}" -m pip install pipx |
| 99 | + export PATH=build/bin:$PATH |
| 100 | + 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" |
| 101 | + mkdir -p unpacked |
| 102 | + for pkg in coin; do |
| 103 | + (cd unpacked && tar xfz - ) < dist/$pkg*.tar.gz |
| 104 | + "${{ steps.python.outputs.python-path }}" -m pipx run cibuildwheel==2.18.0 unpacked/$pkg* |
| 105 | + done |
| 106 | +
|
| 107 | + - uses: actions/upload-artifact@v4 |
| 108 | + with: |
| 109 | + name: ${{ matrix.os }}-${{ matrix.arch }}-wheels |
| 110 | + path: ./wheelhouse/*.whl |
| 111 | + |
| 112 | + pypi-publish: |
| 113 | + # This needs to be a separate job because pypa/gh-action-pypi-publish cannot run on macOS |
| 114 | + # https://github.com/pypa/gh-action-pypi-publish |
| 115 | + name: Upload wheels to PyPI |
| 116 | + needs: build_wheels |
| 117 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') |
| 118 | + runs-on: ubuntu-latest |
| 119 | + env: |
| 120 | + CAN_DEPLOY: ${{ secrets.SAGEMATH_PYPI_API_TOKEN != '' }} |
| 121 | + steps: |
| 122 | + |
| 123 | + - uses: actions/download-artifact@v4 |
| 124 | + with: |
| 125 | + pattern: "*-*-wheels" |
| 126 | + path: wheelhouse |
| 127 | + merge-multiple: true |
| 128 | + |
| 129 | + - name: Publish package distributions to PyPI |
| 130 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 131 | + with: |
| 132 | + user: __token__ |
| 133 | + password: ${{ secrets.SAGEMATH_PYPI_API_TOKEN }} |
| 134 | + packages_dir: wheelhouse/ |
| 135 | + skip_existing: true |
| 136 | + verbose: true |
| 137 | + if: env.CAN_DEPLOY == 'true' |
0 commit comments