Skip to content

Build and upload to PyPI #128

Build and upload to PyPI

Build and upload to PyPI #128

Workflow file for this run

name: Build and upload to PyPI
on:
push:
tags:
- '*'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }} ${{ matrix.arch }} (abi3)
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# Linux x86_64 - single abi3 wheel for all Python 3.10+
- os: ubuntu-latest
arch: auto
platform-id: manylinux_x86_64
# Linux aarch64 - single abi3 wheel for all Python 3.10+
- os: ubuntu-22.04-arm
arch: aarch64
platform-id: manylinux_aarch64
# macOS x86_64 - single abi3 wheel for all Python 3.10+
- os: macos-15-intel
arch: x86_64
platform-id: macosx_x86_64
# macOS arm64 - single abi3 wheel for all Python 3.10+
- os: macos-14
arch: arm64
platform-id: macosx_arm64
# Windows AMD64 - single abi3 wheel for all Python 3.10+
- os: windows-2022
arch: AMD64
platform-id: win_amd64
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Add msbuild to PATH
if: ${{ matrix.os == 'windows-latest'}}
uses: microsoft/setup-msbuild@v2
with:
vs-version: '[17.13,17.14)'
- name: Build wheels
uses: pypa/cibuildwheel@v2.22.0
env:
VERSIONEER_CLOSEST_TAG_ONLY: 1
CIBW_SKIP: pp* *i686
CIBW_ARCHS: ${{ matrix.arch }}
# Build only cp310 for abi3 wheel (compatible with all Python 3.10+)
CIBW_BUILD: cp310-*
CIBW_TEST_REQUIRES: pytest requests pytest-asyncio pytest-timeout
CIBW_BEFORE_ALL_LINUX: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && source $HOME/.cargo/env && apk add openssl-dev
CIBW_BEFORE_BUILD: pip install -r requirements.txt && make
CIBW_BUILD_VERBOSITY: 1
CIBW_ENVIRONMENT_LINUX: "PATH=$HOME/.cargo/bin:$PATH XLLAMACPP_BUILD_AARCH64=${{ matrix.arch == 'aarch64' && '1' || '' }}"
CIBW_ENVIRONMENT_MACOS: "XLLAMACPP_BUILD_AARCH64=${{ matrix.arch == 'aarch64' && '1' || '' }}"
CIBW_ENVIRONMENT_WINDOWS: "XLLAMACPP_BUILD_AARCH64=${{ matrix.arch == 'aarch64' && '1' || '' }}"
with:
package-dir: ./
- uses: actions/upload-artifact@v4
with:
name: wheel-abi3-${{ matrix.platform-id }}
path: wheelhouse/*.whl
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Build sdist
run: pipx run build --sdist
- uses: actions/upload-artifact@v4
with:
name: artifacts
path: ./dist/*.tar.gz
upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
# upload to PyPI on every tag starting with 'v'
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v4
with:
path: dist
pattern: 'wheel-*'
merge-multiple: true
- uses: actions/download-artifact@v4
with:
path: dist
name: artifacts
- name: Publish to PyPI
if: github.repository == 'xorbitsai/xllamacpp'
uses: pypa/gh-action-pypi-publish@v1.12.4
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
- name: Publish to Test PyPI
if: github.repository != 'xorbitsai/xllamacpp'
uses: pypa/gh-action-pypi-publish@v1.12.4
with:
user: __token__
password: ${{ secrets.TEST_PYPI_PASSWORD }}
verbose: true
repository_url: https://test.pypi.org/legacy/