Windows pip and CI #25
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- '*' | |
workflow_dispatch: | |
pull_request: | |
jobs: | |
build: | |
name: Build distribution 📦 | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-20.04, windows-2022] | |
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install pypa/build | |
run: >- | |
python3 -m | |
pip install | |
build | |
--user | |
- name: Build a binary wheel and a source tarball (linux) | |
if: runner.os == 'Linux' | |
run: KUN_USE_GIT_VERSION=${{ startsWith(github.ref, 'refs/tags/') && '0' || '1' }} python3 -m build --wheel | |
- name: Build a binary wheel and a source tarball (windows) | |
if: runner.os == 'Windows' | |
run: | | |
$env:KUN_USE_GIT_VERSION=${{ startsWith(github.ref, 'refs/tags/') && '0' || '1' }} | |
python3 -m build --wheel | |
- name: Store the distribution packages | |
uses: actions/upload-artifact@v4 | |
with: | |
name: python-package-distributions-${{ matrix.os }}${{ matrix.python-version }} | |
path: dist/ | |
publish-to-pypi: | |
name: >- | |
Publish Python 🐍 distribution 📦 to PyPI | |
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes | |
needs: | |
- build | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | |
environment: | |
name: pypi | |
url: https://pypi.org/p/KunQuant # Replace <package-name> with your PyPI project name | |
permissions: | |
id-token: write # IMPORTANT: mandatory for trusted publishing | |
steps: | |
- name: Download all the dists | |
uses: actions/download-artifact@v4 | |
with: | |
name: python-package-distributions-ubuntu-20.04${{ matrix.python-version }} | |
path: dist/ | |
- name: Repair wheel for manylinux (Linux only) | |
if: runner.os == 'Linux' | |
run: | | |
sudo apt install --upgrade patchelf | |
python -m pip install auditwheel | |
auditwheel repair dist/*.whl -w dist/ --plat manylinux_2_31_x86_64 | |
rm dist/*linux_x86_64.whl | |
- name: Publish distribution 📦 to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
publish-to-testpypi: | |
name: Publish Python 🐍 distribution 📦 to TestPyPI | |
needs: | |
- build | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | |
environment: | |
name: testpypi | |
url: https://test.pypi.org/p/KunQuant | |
permissions: | |
id-token: write # IMPORTANT: mandatory for trusted publishing | |
steps: | |
- name: Download all the dists | |
uses: actions/download-artifact@v4 | |
with: | |
name: python-package-distributions-ubuntu-20.04${{ matrix.python-version }} | |
path: dist/ | |
- name: Repair wheel for manylinux (Linux only) | |
if: runner.os == 'Linux' | |
run: | | |
sudo apt install --upgrade patchelf | |
python -m pip install auditwheel | |
auditwheel repair dist/*.whl -w dist/ --plat manylinux_2_31_x86_64 | |
rm dist/*linux_x86_64.whl | |
- name: Download all windows the dists | |
uses: actions/download-artifact@v4 | |
with: | |
name: python-package-distributions-windows-2022${{ matrix.python-version }} | |
path: dist/ | |
- name: Publish distribution 📦 to TestPyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: https://test.pypi.org/legacy/ |