Release Python Package to PyPI #88
This file contains hidden or 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: 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 }}" | |
| - name: Build on Linux using manylinux_2_28_x86_64 Docker (manual run) | |
| if: runner.os == 'Linux' | |
| run: | | |
| docker run --rm \ | |
| -v "${{ github.workspace }}:/io" \ | |
| 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 /io/${{ env.CMAKE_TEMP_DIR }} \ | |
| && cmake -S /io -B /io/${{ env.CMAKE_TEMP_DIR }} -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ | |
| && cmake --build /io/${{ env.CMAKE_TEMP_DIR }} --config Release \ | |
| && find /io/${{ env.LIB_DIR }} -mindepth 2 -type f -exec mv -t /io/${{ env.LIB_DIR }} {} + \ | |
| && rm -rf /io/${{ env.CMAKE_TEMP_DIR }} \ | |
| && ls /io/pmma/extern/lib \ | |
| && /opt/python/${{ matrix.python-tag }}/bin/python /io/setup.py build_ext --build-lib /io/${{ env.BUILD_DIR }} --build-temp /io/${{ env.TEMP_DIR }} sdist bdist_wheel \ | |
| && ORIGINAL_WHEEL=\$(ls /io/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 |