Skip to content

Commit

Permalink
[Package] Add GitHub action package build workflow (#51)
Browse files Browse the repository at this point in the history
This PR adds the CD workflow file, which will be triggered when a new
tag is pushed.
  • Loading branch information
MasterJH5574 authored Nov 17, 2024
1 parent 485ec04 commit 3ae4945
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 41 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/wheel_manylinux.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# GH actions.
name: Wheel-Manylinux


on: push

jobs:
Build:
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
strategy:
matrix:
config:
- image: 'mlcaidev/package-cpu:254d630'

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 --package . --package-name xgrammar --version ${{ github.ref_name }} --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: 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
47 changes: 6 additions & 41 deletions scripts/sync_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
import re
import subprocess

# Modify the following two settings during release
# -----------------------------------------------------------
# Tag used for stable build.
__stable_build__ = "v0.1.0"
# -----------------------------------------------------------


def py_str(cstr):
return cstr.decode("utf-8")
Expand Down Expand Up @@ -101,7 +95,7 @@ def update_conda(args, pkg, package_name):
)


def update_setup(args, pkg, package_name):
def update_setup(args, package_name):
pub_ver, _ = get_version_tag(args)
rewrites = [
(r'(?<=name=")[^\"]+', package_name),
Expand Down Expand Up @@ -142,33 +136,10 @@ def main():
"Defaults to package",
)
parser.add_argument(
"--revision",
type=str,
default="origin/main",
help="Specify a revision to build packages from. " "Defaults to 'origin/main'",
)
parser.add_argument(
"--gpu",
"--version",
type=str,
default="none",
choices=[
"none",
"cuda-11.7",
"cuda-11.8",
"cuda-12.1",
"cuda-12.2",
"cuda-12.3",
"rocm-6.1",
"rocm-6.2",
],
help="GPU (CUDA/ROCm) version to be linked to the resultant binaries,"
"or none, to disable CUDA/ROCm. Defaults to none.",
)
parser.add_argument(
"--skip-checkout",
action="store_true",
help="Run the syncronization process without checking out new source."
"For use when running in an existing checkout.",
required=True,
help="The version string (e.g., v0.1.0)",
)
parser.add_argument(
"--skip-conda",
Expand All @@ -181,18 +152,12 @@ def main():
args.src = args.package
package_name = args.package_name

if not args.skip_checkout:
if "nightly" not in args.package_name and not args.nightly:
if __stable_build__ is None:
raise RuntimeError("Only nightly is supported")
checkout_source(args.src, __stable_build__)
else:
checkout_source(args.src, args.revision)
checkout_source(args.src, args.version)

if not args.skip_conda:
update_conda(args, args.package, package_name)

update_setup(args, args.package, package_name)
update_setup(args, package_name)


if __name__ == "__main__":
Expand Down

0 comments on commit 3ae4945

Please sign in to comment.