Skip to content

Release Python Package to PyPI #32

Release Python Package to PyPI

Release Python Package to PyPI #32

name: Release Python Package to PyPI
on:
release:
types: [published]
workflow_dispatch:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
env:
BUILD_DIR: pmma/build
LIB_DIR: pmma/lib
TEMP_DIR: pmma/temporary
CMAKE_TEMP_DIR: pmma/temporary/cmake
VCPKG_DIR: build_tools/vcpkg
VCPKG_CMAKE: build_tools/vcpkg/scripts/buildsystems/vcpkg.cmake
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update || true
sudo apt-get install -y cmake build-essential || true
sudo apt-get -y install libglfw3 libglfw3-dev
- name: Install dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew install glfw3 glew
- name: Install dependencies (Windows)
if: runner.os == 'Windows'
run: |
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' --yes
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Setup PIP
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine cython numpy
- name: Cache vcpkg
if: runner.os == 'Windows'
uses: actions/cache@v3
with:
path: ${{ env.VCPKG_DIR }}
key: ${{ runner.os }}-vcpkg-${{ hashFiles('**/vcpkg.json') }}
restore-keys: |
${{ runner.os }}-vcpkg-
- name: Clone and bootstrap vcpkg (Windows only)
if: runner.os == 'Windows'
run: |
git clone https://github.com/microsoft/vcpkg.git $env:VCPKG_DIR
.\build_tools\vcpkg\bootstrap-vcpkg.bat
.\build_tools\vcpkg\vcpkg.exe install glfw3
.\build_tools\vcpkg\vcpkg.exe integrate install
- name: Clean old build directories
run: |
echo "Cleaning..."
rm -rf ${{ env.BUILD_DIR }} ${{ env.TEMP_DIR }} ${{ env.LIB_DIR }} || true
mkdir -p ${{ env.CMAKE_TEMP_DIR }}
- name: Configure CMake
run: |
echo "Running CMake..."
if [[ "${{ runner.os }}" == "Windows" ]]; then
cmake -S . -B ${{ env.CMAKE_TEMP_DIR }} -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_CMAKE }}
elif [[ "${{ runner.os }}" == "macOS" ]]; then
cmake -S . -B ${{ env.CMAKE_TEMP_DIR }} -DCMAKE_OSX_ARCHITECTURES=x86_64
else
cmake -S . -B ${{ env.CMAKE_TEMP_DIR }}
fi
shell: bash
- name: Build Shared Library
run: |
cmake --build ${{ env.CMAKE_TEMP_DIR }} --config Release
find ${{ env.LIB_DIR }} -mindepth 2 -type f -exec mv -t ${{ env.LIB_DIR }} {} +
rm -rf ${{ env.CMAKE_TEMP_DIR }}
shell: bash
- name: Build PMMA Python Extension
run: |
python setup.py build_ext --build-lib ${{ env.BUILD_DIR }} --build-temp ${{ env.TEMP_DIR }}
- name: Build Wheel
run: |
python setup.py sdist bdist_wheel
- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: wheels-${{ runner.os }}
path: dist/*.whl
sdist:
name: Build Source Distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.10'
- run: |
pip install setuptools wheel cython numpy
python setup.py sdist
- uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz
publish:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: [build, sdist]
steps:
- uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Publish all wheels and sdist
uses: pypa/gh-action-pypi-publish@v1.4.2
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: ./artifacts