Skip to content

Release Python Package to PyPI #95

Release Python Package to PyPI

Release Python Package to PyPI #95

name: Release Python Package to PyPI
on:
release:
types: [published]
workflow_dispatch:
jobs:
build:
strategy:
matrix:
include:
# - os: linux
# runner: ubuntu-latest
# arch: x64
# python-version: '3.8'
# python-tag: 'cp38-cp38'
#
# - os: linux
# runner: ubuntu-latest
# arch: x64
# python-version: '3.9'
# python-tag: 'cp39-cp39'
#
- os: linux
runner: ubuntu-latest
arch: x64
python-version: '3.10'
python-tag: 'cp310-cp310'
#
# - os: linux
# runner: ubuntu-latest
# arch: x64
# python-version: '3.11'
# python-tag: 'cp311-cp311'
#
# - os: windows
# runner: windows-latest
# arch: x64
# python-version: '3.8'
# python-tag: 'cp38-cp38'
#
# - os: windows
# runner: windows-latest
# arch: x64
# python-version: '3.9'
# python-tag: 'cp39-cp39'
#
- os: windows
runner: windows-latest
arch: x64
python-version: '3.10'
python-tag: 'cp310-cp310'
#
# - os: windows
# runner: windows-latest
# arch: x64
# python-version: '3.11'
# python-tag: 'cp311-cp311'
#
# - os: macos
# runner: macos-latest
# arch: arm64
# python-version: '3.8'
# python-tag: 'cp38-cp38'
#
# - os: macos
# runner: macos-latest
# arch: arm64
# python-version: '3.9'
# python-tag: 'cp39-cp39'
#
- os: macos
runner: macos-latest
arch: arm64
python-version: '3.10'
python-tag: 'cp310-cp310'
#
# - os: macos
# runner: macos-latest
# arch: arm64
# python-version: '3.11'
# python-tag: 'cp311-cp311'
runs-on: ${{ matrix.runner }}
env:
BUILD_DIR: pmma/build
LIB_DIR: pmma/lib
TEMP_DIR: temporary
CMAKE_TEMP_DIR: temporary/cmake
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Python
if: runner.os != 'Linux'
uses: actions/setup-python@v5
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 (Windows)
if: runner.os == 'Windows'
run: choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' --yes
- name: Setup pip (non-Linux)
if: runner.os != 'Linux'
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine cython numpy
- name: Clean old build directories
shell: bash
run: |
mkdir -p "${{ env.CMAKE_TEMP_DIR }}"
cp -a extern/. pmma/extern/
- name: Build on Linux using manylinux_2_28_x86_64 Docker (manual run)
if: runner.os == 'Linux'
run: |
docker run --rm \
-v "${{ github.workspace }}:/PMMA" \
quay.io/pypa/manylinux_2_28_x86_64 \
/bin/bash -c "
yum install -y cmake make gcc gcc-c++ mesa-libGL-devel libXrandr-devel libXinerama-devel libXcursor-devel libXi-devel wayland-devel libxkbcommon-devel \
&& /opt/python/${{ matrix.python-tag }}/bin/python -m pip install --upgrade pip setuptools wheel cython numpy \
&& mkdir -p /PMMA/${{ env.CMAKE_TEMP_DIR }} \
&& cmake -S /PMMA -B /PMMA/${{ env.CMAKE_TEMP_DIR }} -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
&& cmake --build /PMMA/${{ env.CMAKE_TEMP_DIR }} --config Release \
&& find /PMMA/${{ env.LIB_DIR }} -mindepth 2 -type f -exec mv -t /PMMA/${{ env.LIB_DIR }} {} + \
&& rm -rf /PMMA/${{ env.CMAKE_TEMP_DIR }} \
&& ls -lR /PMMA | less \
&& /opt/python/${{ matrix.python-tag }}/bin/python /PMMA/setup.py build_ext --build-lib /PMMA/${{ env.BUILD_DIR }} --build-temp /PMMA/${{ env.TEMP_DIR }} sdist bdist_wheel \
&& ORIGINAL_WHEEL=\$(ls /PMMA/dist/*.whl) \
&& RENAMED_WHEEL=\$(echo \"\$ORIGINAL_WHEEL\" | sed 's/linux/manylinux_2_28/') \
&& mv \"\$ORIGINAL_WHEEL\" \"\$RENAMED_WHEEL\"
"
- name: Configure CMake (non-Linux)
if: runner.os != 'Linux'
run: |
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 (non-Linux)
if: runner.os != 'Linux'
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 (non-Linux)
if: runner.os != 'Linux'
run: |
python setup.py build_ext --build-lib ${{ env.BUILD_DIR }} --build-temp ${{ env.TEMP_DIR }} sdist bdist_wheel
- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: wheel-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.arch }}
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
- name: Upload wheels and sdist to GitHub Release
if: github.event_name == 'release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPLOAD_URL: ${{ github.event.release.upload_url }}
run: |
for file in dist/*; do
filename=$(basename "$file")
echo "Uploading $filename ..."
upload_url="${UPLOAD_URL%\{*}"
curl \
-X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @"$file" \
"$upload_url?name=$filename"
done