From: Nicolas Patry Date: Thu, 22 Sep 2022 15:26:20 +0000 (+0200) Subject: Creating build gh action X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=fb7a652591fceb9190b254adad1e335bb182ef1d;p=safetensors.git Creating build gh action --- diff --git a/.github/workflows/python-release-conda.yml b/.github/workflows/python-release-conda.yml new file mode 100644 index 0000000..52c964a --- /dev/null +++ b/.github/workflows/python-release-conda.yml @@ -0,0 +1,133 @@ +name: Python Release - Conda + +on: + push: + tags: + - python-v* + +env: + ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }} + +jobs: + build_and_package: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, macos-latest] + python: ["3.7", "3.8", "3.9"] + # 3.10 Not yet available on Conda. + # python: ["3.7", "3.8", "3.9", "3.10"] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install miniconda + uses: conda-incubator/setup-miniconda@v2 + with: + auto-update-conda: true + python-version: ${{ matrix.python }} + + - name: Conda info + shell: bash -l {0} + run: conda info + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + + - name: Setup conda env + shell: bash -l {0} + run: | + conda install setuptools-rust + conda install -c defaults anaconda-client conda-build + + - name: Extract version + shell: bash -l {0} + working-directory: ./bindings/python + run: echo "SAFETENSORS_VERSION=`python setup.py --version`" >> $GITHUB_ENV + + - name: Build conda packages + shell: bash -l {0} + run: | + conda info + conda list + conda-build .github/conda --python=${{ matrix.python }} + + - name: Upload to Anaconda + shell: bash -l {0} + run: | + anaconda upload `conda-build .github/conda --output` --force + + build_and_package_linux: + runs-on: ubuntu-18.04 + container: quay.io/pypa/manylinux2014_x86_64 + + strategy: + fail-fast: false + matrix: + python: [37, 38, 39] + include: + - python: 37 + checksum: a1a7285dea0edc430b2bc7951d89bb30a2a1b32026d2a7b02aacaaa95cf69c7c + - python: 38 + checksum: 935d72deb16e42739d69644977290395561b7a6db059b316958d97939e9bdf3d + - python: 39 + checksum: 1ea2f885b4dbc3098662845560bc64271eb17085387a70c2ba3f29fff6f8d52f + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install miniconda + run: | + yum install -y wget openssl-devel + export FILENAME=Miniconda3-py${{ matrix.python }}_4.10.3-Linux-x86_64.sh + wget https://repo.anaconda.com/miniconda/$FILENAME + sha256sum $FILENAME | awk '$1=="${{ matrix.checksum}}"{print"good to go"}' + bash $FILENAME -b -p $HOME/miniconda + source $HOME/miniconda/bin/activate + + - name: Show glibc information + shell: bash -l {0} + run: ldd --version + + - name: Conda info + shell: bash -l {0} + run: | + source $HOME/miniconda/bin/activate + conda info + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + + - name: Setup conda env + shell: bash -l {0} + run: | + source $HOME/miniconda/bin/activate + conda install setuptools-rust + conda install -c defaults anaconda-client conda-build + + - name: Extract version + shell: bash -l {0} + working-directory: ./bindings/python + run: | + source $HOME/miniconda/bin/activate + echo "SAFETENSORS_VERSION=`python setup.py --version`" >> $GITHUB_ENV + + - name: Build conda packages + shell: bash -l {0} + run: | + source $HOME/miniconda/bin/activate + conda info + conda list + conda-build .github/conda --python=${{ matrix.python }} + + - name: Upload to Anaconda + shell: bash -l {0} + run: | + source $HOME/miniconda/bin/activate + anaconda upload `conda-build .github/conda --output` --force diff --git a/.github/workflows/python-release-extra.yml b/.github/workflows/python-release-extra.yml new file mode 100644 index 0000000..bca9740 --- /dev/null +++ b/.github/workflows/python-release-extra.yml @@ -0,0 +1,120 @@ +name: Python Release extra + +on: + push: + tags: + - python-v* + +env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: us-east-1 + PYPI_TOKEN: ${{ secrets.PYPI_TOKEN_DIST }} + DIST_DIR: '${{ github.sha }}_extra' + +jobs: + + create_wheels_manylinux_2014_ppc64le: + runs-on: ubuntu-latest + name: Create wheels for manylinux2014 - PowerPC + steps: + - uses: actions/checkout@v1 + + - name: Upgrade libssl + run: sudo apt-get install -y libssl-dev + + - name: Pull images + run: | + docker pull multiarch/qemu-user-static + docker pull quay.io/pypa/manylinux2014_ppc64le:latest + + - name: Install QEMU + run: | + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + + - name: Build and audit wheels + working-directory: ./bindings/python + run: | + docker run -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION -e DIST_DIR \ + --rm -v `pwd`/../..:/io quay.io/pypa/manylinux2014_ppc64le \ + /bin/bash -c "yum install -y openssl-devel && cd /io/bindings/python; sh build-wheels.sh" + + create_wheels_manylinux_2014_aarch64: + runs-on: ubuntu-latest + name: Create wheels for manylinux2014 - Aarch64 + steps: + - uses: actions/checkout@v2 + + - name: Upgrade libssl + run: sudo apt-get install -y libssl-dev + + - name: Pull images + run: | + docker pull multiarch/qemu-user-static + docker pull quay.io/pypa/manylinux2014_aarch64:latest + + - name: Install QEMU + run: | + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + + - name: Build and audit wheels + working-directory: ./bindings/python + run: | + docker run -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION -e DIST_DIR \ + --rm -v `pwd`/../..:/io quay.io/pypa/manylinux2014_aarch64 \ + /bin/bash -c "yum install -y openssl-devel && cd /io/bindings/python; sh build-wheels.sh" + + create_wheels_manylinux_2014_x390x: + runs-on: ubuntu-latest + name: Create wheels for manylinux2014 - S390X + steps: + - uses: actions/checkout@v2 + + - name: Upgrade libssl + run: sudo apt-get install -y libssl-dev + + - name: Pull images + run: | + docker pull multiarch/qemu-user-static + docker pull quay.io/pypa/manylinux2014_s390x:latest + + - name: Install QEMU + run: | + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + + - name: Build and audit wheels + working-directory: ./bindings/python + run: | + docker run -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION -e DIST_DIR \ + --rm -v `pwd`/../..:/io quay.io/pypa/manylinux2014_s390x \ + /bin/bash -c "yum install -y openssl-devel && cd /io/bindings/python; sh build-wheels.sh" + + upload_package: + name: Upload package to PyPi + runs-on: ubuntu-latest + needs: + - create_wheels_manylinux_2014_ppc64le + - create_wheels_manylinux_2014_aarch64 + - create_wheels_manylinux_2014_x390x + + steps: + - uses: actions/checkout@v2 + + - name: Install Python + uses: actions/setup-python@v1 + + - name: Retrieve all wheels + shell: bash + run: | + pip install awscli + aws s3 sync "s3://safetensors-releases/python/$DIST_DIR" ./bindings/python/dist + + - name: Install dependencies + run: | + pip install setuptools wheel setuptools-rust + + - name: Upload to PyPi + working-directory: ./bindings/python + run: | + pip install twine + twine upload dist/* -u __token__ -p "$PYPI_TOKEN" diff --git a/.github/workflows/python-release.yml b/.github/workflows/python-release.yml new file mode 100644 index 0000000..af763fa --- /dev/null +++ b/.github/workflows/python-release.yml @@ -0,0 +1,181 @@ +name: Python Release + +on: + push: + # tags: + # - python-v* + +env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: us-east-1 + PYPI_TOKEN: ${{ secrets.PYPI_TOKEN_DIST }} + DIST_DIR: ${{ github.sha }} + +jobs: + + create_wheels_manylinux: + runs-on: ubuntu-latest + name: Create wheels for manylinux2010 + container: quay.io/pypa/manylinux2010_x86_64 + steps: + # v1 is required when using manylinux2010 + - uses: actions/checkout@v1 + + - name: Install dependencies + run: yum install -y openssl-devel + + - name: Build and audit wheels + working-directory: ./bindings/python + run: sh build-wheels.sh + + create_wheels_windows_32bit: + name: Create wheels for windows 32-bit + runs-on: windows-latest + strategy: + matrix: + python: ["3.7", "3.8", "3.9", "3.10"] + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable-i686-pc-windows-msvc + override: true + + - name: Override toolchain + shell: bash + working-directory: ./bindings/python + run: echo "stable-i686-pc-windows-msvc" > rust-toolchain + + - name: Install Python + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python }} + architecture: x86 + + - name: Install dependencies + run: | + # On old versions of python there is an old version of setuptools already installed + pip install setuptools wheel setuptools-rust==0.11.3 --ignore-installed --force-reinstall + + - name: Build wheel + working-directory: ./bindings/python + run: python setup.py bdist_wheel + + - name: Upload wheels + shell: bash + run: | + pip install awscli + aws s3 sync --exact-timestamps ./bindings/python/dist "s3://safetensors-releases/python/$DIST_DIR" + + + create_wheels_others_64bit: + name: Create wheels for other OSes + env: + MACOSX_DEPLOYMENT_TARGET: 10.11 + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, macos-10.15] + python: ["3.7", "3.8", "3.9", "3.10"] + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Install Python + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python }} + architecture: x64 + + - name: Install dependencies + run: | + # On old versions of python there is an old version of setuptools already installed + pip install setuptools wheel setuptools-rust==0.11.3 --ignore-installed --force-reinstall + + - name: Build wheel + working-directory: ./bindings/python + run: python setup.py bdist_wheel + + - name: Rename wheels + shell: bash + working-directory: ./bindings/python/dist + run: for file in *.whl ; do mv $file ${file//macosx_10_1[0-9]/macosx_10_11} ; done + + - name: Upload wheels + shell: bash + run: | + pip install awscli + aws s3 sync --exact-timestamps ./bindings/python/dist "s3://safetensors-releases/python/$DIST_DIR" + + create_wheels_macos_arm64: + name: Create wheels for MacOS M1 + runs-on: macos-arm64 + strategy: + matrix: + python: ["3.9.13", "3.10.6"] + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Install Python + shell: bash + run: | + echo $HOME + export PYENV_ROOT="$HOME/.pyenv" + command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH" + eval "$(pyenv init -)" + pyenv shell ${{ matrix.python }} + which pyenv + which python + pip install -U setuptools wheel setuptools-rust awscli + cd ./bindings/python + python setup.py bdist_wheel + cd ../../ + aws s3 sync --exact-timestamps ./bindings/python/dist "s3://safetensors-releases/python/$DIST_DIR" + + # Upload_package: + # name: Upload package to PyPi + # runs-on: ubuntu-latest + # needs: [create_wheels_manylinux, create_wheels_windows_32bit, create_wheels_others_64bit, create_wheels_macos_arm64] + + # steps: + # - uses: actions/checkout@v1 + + # - name: Install Python + # uses: actions/setup-python@v1 + + # - name: Retrieve all wheels + # shell: bash + # run: | + # pip install awscli + # aws s3 sync "s3://safetensors-releases/python/$DIST_DIR" ./bindings/python/dist + + # - name: Install dependencies + # run: | + # pip install setuptools wheel setuptools-rust + + # - name: Create source distribution + # working-directory: ./bindings/python + # run: sh build-sdist.sh + + # - name: Upload to PyPi + # working-directory: ./bindings/python + # run: | + # pip install twine + # twine upload dist/* -u __token__ -p "$PYPI_TOKEN" diff --git a/bindings/python/build-sdist.sh b/bindings/python/build-sdist.sh new file mode 100755 index 0000000..0e63021 --- /dev/null +++ b/bindings/python/build-sdist.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -ex + +# Create a symlink for tokenizers-lib +ln -sf ../../tokenizers tokenizers-lib +# Modify cargo.toml to include this symlink +sed -i 's/\.\.\/\.\.\/tokenizers/\.\/tokenizers-lib/' Cargo.toml +# Build the source distribution +python setup.py sdist diff --git a/bindings/python/build-wheels.sh b/bindings/python/build-wheels.sh new file mode 100755 index 0000000..493286f --- /dev/null +++ b/bindings/python/build-wheels.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -ex + +if ! command -v cargo &> /dev/null +then + curl https://sh.rustup.rs -sSf | sh -s -- -y +fi + +export PATH="$HOME/.cargo/bin:$PATH" + +for PYBIN in /opt/python/cp{37,38,39,310}*/bin; do + export PYTHON_SYS_EXECUTABLE="$PYBIN/python" + + "${PYBIN}/pip" install -U setuptools-rust setuptools wheel + "${PYBIN}/python" setup.py bdist_wheel + rm -rf build/* +done + +for whl in ./dist/*.whl; do + auditwheel repair "$whl" -w dist/ +done + +# Keep only manylinux wheels +rm ./dist/*-linux_* + + +# Upload wheels +/opt/python/cp37-cp37m/bin/pip install -U awscli +/opt/python/cp37-cp37m/bin/python -m awscli s3 sync --exact-timestamps ./dist "s3://safetensors-releases/python/$DIST_DIR"