Skip to content

[Package] Setup Python packaging #5

[Package] Setup Python packaging

[Package] Setup Python packaging #5

# GH actions.
name: Wheel-Manylinux
on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: '0 4 * * *' # 4 AM UTC
jobs:
Build:
strategy:
matrix:
pkg_kind: ['nightly']
# pkg_kind: ['nightly', 'stable']
config:
- image: 'mlcaidev/package-cpu:254d630'
exclude:
- pkg_kind: ${{ github.event_name == 'schedule' && 'stable' || '' }}
runs-on: ubuntu-latest
steps:
- name: Reclaim disk space
run: |
df -h
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo rm -rf /usr/local/.ghcup
df -h
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Checkout source
run: |
git clone https://github.com/mlc-ai/package package --recursive
- name: Setup script env
run: |
rm -rf conda
ln -s package/3rdparty/tlcpack/conda conda
- name: Sync XGrammar Package
run: |
python scripts/sync_package.py --gpu none --package . --package-name ${{ matrix.pkg_kind == 'nightly' && 'xgrammar-nightly' || 'xgrammar' }} --revision origin/main ${{ matrix.pkg_kind == 'nightly' && '--skip-checkout' || '' }} --skip-conda
- name: Build XGrammar
env:
IMAGE: ${{ matrix.config.image }}
run: |
scripts/docker/bash.sh --no-gpu $IMAGE ./scripts/build_xgrammar_wheel_manylinux.sh
Publish-to-pypi:
name: >-
Upload release to PyPI
if: github.ref == 'refs/heads/main'
# if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- Build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://test.pypi.org/p/xgrammar-nightly
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Retrieve all wheels
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: xgrammar/python/repaired_wheels/
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1