Skip to content

Release Python Package to PyPI #65

Release Python Package to PyPI

Release Python Package to PyPI #65

name: Release Python Package to PyPI
on:
release:
types: [published]
workflow_dispatch:
jobs:
build:
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu
runner: ubuntu-18.04
arch: x64
python-version: '3.7'
- os: ubuntu
runner: ubuntu-18.04
arch: x64
python-version: '3.8'
- os: ubuntu
runner: ubuntu-18.04
arch: x64
python-version: '3.9'
- os: ubuntu
runner: ubuntu-18.04
arch: x64
python-version: '3.10'
- os: ubuntu
runner: ubuntu-18.04
arch: x64
python-version: '3.11'
- os: windows
runner: windows-latest
arch: x64
python-version: '3.7'
- os: windows
runner: windows-latest
arch: x64
python-version: '3.8'
- os: windows
runner: windows-latest
arch: x64
python-version: '3.9'
- os: windows
runner: windows-latest
arch: x64
python-version: '3.10'
- os: windows
runner: windows-latest
arch: x64
python-version: '3.11'
- os: macos
runner: macos-latest
arch: arm64
python-version: '3.8'
- os: macos
runner: macos-latest
arch: arm64
python-version: '3.9'
- os: macos
runner: macos-latest
arch: arm64
python-version: '3.10'
- os: macos
runner: macos-latest
arch: arm64
python-version: '3.11'
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: Set macOS Deployment Target
if: runner.os == 'macOS'
run: |
export MACOSX_DEPLOYMENT_TARGET=14.0
- 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 libxi-dev libxrandr-dev libxinerama-dev libxcursor-dev libwayland-dev libxkbcommon-dev libgl1-mesa-dev
- 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: Cache vcpkg installed packages
# uses: actions/cache@v3
# with:
# path: |
# ${{ env.VCPKG_DIR }}/installed
# ${{ env.VCPKG_DIR }}/buildtrees
# ${{ env.VCPKG_DIR }}/packages
# key: ${{ runner.os }}-vcpkg-cache-${{ hashFiles('**/vcpkg.json') }}
# restore-keys: |
# ${{ runner.os }}-vcpkg-cache-
#- 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
shell: bash
run: |
echo "Cleaning..."
rm -rf "${{ env.BUILD_DIR }}" "${{ env.LIB_DIR }}" || true
mkdir -p "${{ env.CMAKE_TEMP_DIR }}"
#- name: Configure CMake OLD
# 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
# export MACOSX_DEPLOYMENT_TARGET=14.0
# export CFLAGS="-arch arm64"
# export CXXFLAGS="-arch arm64"
# cmake -S . -B ${{ env.CMAKE_TEMP_DIR }} -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }}
# else
# cmake -S . -B ${{ env.CMAKE_TEMP_DIR }}
# fi
# shell: bash
- name: Configure CMake NEW
run: |
echo "Running CMake..."
if [[ "${{ runner.os }}" == "macOS" ]]; then
export MACOSX_DEPLOYMENT_TARGET=14.0
export CFLAGS="-arch arm64"
export CXXFLAGS="-arch arm64"
cmake -S . -B ${{ env.CMAKE_TEMP_DIR }} -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }}
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 Wheel
run: |
python setup.py build_ext --build-lib ${{ env.BUILD_DIR }} --build-temp ${{ env.TEMP_DIR }} sdist bdist_wheel
- name: Rename Linux wheel to manylinux2014
if: runner.os == 'Linux'
run: |
ORIGINAL_WHEEL=$(ls dist/*.whl)
RENAMED_WHEEL=$(echo "$ORIGINAL_WHEEL" | sed 's/linux/manylinux2014/')
mv "$ORIGINAL_WHEEL" "$RENAMED_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:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Move distribution files to expected location
run: |
mkdir -p dist
find artifacts -type f \( -name "*.whl" -o -name "*.tar.gz" \) -exec mv {} dist/ \;
- 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: dist