CI build for PyPI #94
Workflow file for this run
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: CI build for PyPI | |
on: | |
push: | |
# branches: | |
# - master | |
tags: | |
- 'v*' | |
jobs: | |
build: | |
strategy: | |
matrix: | |
python-version: [3.11] | |
buildplat: | |
- platform: windows-2019 | |
manylinux_type: "" | |
os_name: win | |
arch: AMD64 | |
- platform: ubuntu-20.04 | |
manylinux_type: manylinux | |
arch: x86_64 | |
# - platform: ubuntu-20.04 | |
# manylinux_type: musllinux | |
# arch: x86_64 | |
python: [["cp36", "3.6"],["cp37", "3.7"],["cp38", "3.8"],["cp39", "3.9"],["cp310", "3.10"], ["cp311", "3.11"], ["cp312", "3.12"]] | |
runs-on: ${{ matrix.buildplat.platform }} | |
# if: startsWith(github.ref, 'refs/tags/v') | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: List files in repository | |
shell: bash | |
run: | | |
ls -R . | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install common dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install Cython numpy pybind11 scipy | |
- name: Install C++ compiler (Windows) | |
if: matrix.buildplat.os_name == 'win' | |
uses: msys2/setup-msys2@v2 | |
with: | |
install: mingw64/mingw-w64-x86_64-gcc | |
# - name: Install system dependencies | |
# run: | | |
# sudo apt-get update | |
# sudo apt-get install -y --no-install-recommends \ | |
# libblas-dev \ | |
# liblapack-dev | |
# 直接在env下设置环境变量 | |
- name: Set CIBW variables | |
run: | | |
echo "CIBW_BUILD=${{ format('{0}-{1}*', matrix.python[0], (matrix.buildplat.manylinux_type || matrix.buildplat.os_name)) }}" | |
echo "CIBW_ARCHS=${{ matrix.buildplat.arch }}" | |
env: | |
CIBW_BUILD: ${{ format('{0}-{1}*', matrix.python[0], (matrix.buildplat.manylinux_type || matrix.buildplat.os_name)) }} | |
CIBW_ARCHS: ${{ matrix.buildplat.arch }} | |
- name: Build wheels with cibuildwheel | |
shell: bash | |
env: | |
CIBW_BUILD: ${{ format('{0}-{1}*', matrix.python[0], (matrix.buildplat.manylinux_type || matrix.buildplat.os_name)) }} | |
CIBW_ARCHS: ${{ matrix.buildplat.arch }} | |
run: | | |
pip install cibuildwheel | |
if [ "${{ matrix.buildplat.platform }}" = "windows-2019" ]; then | |
cibuildwheel --output-dir wheelhouse --platform windows --arch ${{ matrix.buildplat.arch }} | |
else | |
cibuildwheel --output-dir wheelhouse --platform linux --arch ${{ matrix.buildplat.arch }} | |
fi | |
- name: Save Wheel Package as Artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: wheelhouse | |
path: wheelhouse/*.whl | |
package_source: | |
runs-on: ubuntu-latest # 可以在任何平台上执行,这里假设选择Ubuntu | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Python (for creating source distribution) | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.11' # 您可以选择一个合适的Python版本来构建源码包 | |
- name: Install common dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install Cython numpy pybind11 scipy | |
- name: Create source distribution | |
run: python setup.py sdist # 假设您的项目有一个setup.py文件 | |
- name: Move source distribution to specific directory | |
run: | | |
mkdir dist_sources | |
mv dist/*.tar.gz dist_sources/ # 移动生成的源码包到新的目录 | |
- name: Upload source distribution as artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: source-distribution | |
path: dist_sources/* | |
deploy_to_testpypi: | |
needs: [build, package_source] | |
runs-on: ubuntu-latest | |
env: | |
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} | |
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | |
steps: | |
- name: Download Wheel Package Artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: wheelhouse | |
path: ./wheelhouse | |
- name: Download Source Distribution Artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: source-distribution | |
path: ./source_distribution | |
- name: Publish to TestPyPI | |
run: | | |
pip install twine | |
twine upload --repository-url https://upload.pypi.org/legacy/ wheelhouse/*.whl source_distribution/*.tar.gz |