Release Python Package to PyPI #157
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: | |
| workflow_dispatch: | |
| release: | |
| types: [published] | |
| jobs: | |
| build_deps_windows: | |
| name: Build Windows Dependencies | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| lfs: true | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| cache: 'pip' | |
| - name: Install Meson using Python | |
| run: | | |
| python -m pip install --upgrade pip meson | |
| - name: Set up Git credentials | |
| run: | | |
| git config --global user.email "github-actions@github.com" | |
| git config --global user.name "GitHub Actions" | |
| git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/PycraftDeveloper/PMMA.git | |
| - name: Configure and build C++ API via CMake | |
| run: | | |
| python "build_tools/build_deps.py" -in_github_workflow | |
| build_deps_linux: | |
| name: Build AnyLinux Dependencies | |
| runs-on: ubuntu-latest | |
| env: | |
| DOCKER_IMAGE: docker.io/pycraftdev/pmma-manylinux:latest | |
| steps: | |
| - name: Pre-pull Docker image (cached by GitHub’s runner) | |
| run: docker pull $DOCKER_IMAGE | |
| - name: Build Linux wheel inside Docker | |
| run: | | |
| docker run --rm \ | |
| -e TERM=xterm \ | |
| -v "${{ github.workspace }}/dist:/output_dist" \ | |
| $DOCKER_IMAGE \ | |
| /bin/bash -c ' | |
| set -e | |
| git config --global user.email "github-actions@github.com" | |
| git config --global user.name "GitHub Actions" | |
| git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/PycraftDeveloper/PMMA.git | |
| git clone https://github.com/${{ github.repository }} /PMMA | |
| cd /PMMA | |
| python3 "build_tools/build_deps.py" -in_github_workflow | |
| ' | |
| build_linux: | |
| name: Build Linux wheels (matrix) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-tag: ["cp38-cp38", "cp39-cp39", "cp310-cp310", "cp311-cp311"] | |
| env: | |
| DOCKER_IMAGE: docker.io/pycraftdev/pmma-manylinux:latest | |
| needs: [build_deps_linux] | |
| steps: | |
| - name: Ensure dist directory exists | |
| run: mkdir -p dist | |
| - name: Pre-pull Docker image (cached by GitHub’s runner) | |
| run: docker pull $DOCKER_IMAGE | |
| - name: Build Linux wheel inside Docker | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| docker run --rm \ | |
| -e TERM=xterm \ | |
| -e GITHUB_TOKEN=$GITHUB_TOKEN \ | |
| -e PYTHON_TAG=${{ matrix.python-tag }} \ | |
| -v "${{ github.workspace }}/dist:/output_dist" \ | |
| $DOCKER_IMAGE \ | |
| /bin/bash -c ' | |
| set -e | |
| tag=$PYTHON_TAG | |
| dir="/tmp/build_$tag" | |
| git config --global user.email "github-actions@github.com" | |
| git config --global user.name "GitHub Actions" | |
| git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/PycraftDeveloper/PMMA.git | |
| git clone https://github.com/${{ github.repository }} "$dir" | |
| cd "$dir" | |
| PYTHON_BIN="/opt/python/$tag/bin/python" | |
| python3 "build_tools/workflow_integration.py" -in_github_workflow | |
| $PYTHON_BIN "build_pmma.py" | |
| original=$(ls dist/*.whl) | |
| renamed=$(echo "$original" | sed "s/linux/manylinux_2_28/") | |
| mv "$original" "$renamed" | |
| cp dist/* /output_dist/ | |
| ' | |
| - name: Upload wheel | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheel-linux-${{ matrix.python-tag }} | |
| path: dist/*.whl | |
| build_windows: | |
| strategy: | |
| matrix: | |
| include: | |
| - os: windows | |
| runs-on: windows-latest | |
| python-version: '3.8' | |
| - os: windows | |
| runs-on: windows-latest | |
| python-version: '3.9' | |
| - os: windows | |
| runs-on: windows-latest | |
| python-version: '3.10' | |
| - os: windows | |
| runs-on: windows-latest | |
| python-version: '3.11' | |
| runs-on: ${{ matrix.runs-on }} | |
| needs: [build_deps_windows] | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| lfs: true | |
| # Python with built-in pip cache | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: 'pip' | |
| # Install Python build deps (reuses pip cache above) | |
| - name: Install Python build tools | |
| run: | | |
| python -m pip install --upgrade pip setuptools wheel cython numpy meson | |
| - name: Set up Git credentials | |
| run: | | |
| git config --global user.email "github-actions@github.com" | |
| git config --global user.name "GitHub Actions" | |
| git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/PycraftDeveloper/PMMA.git | |
| - name: Configure and build C++ API via CMake | |
| run: | | |
| python "build_tools/workflow_integration.py" -in_github_workflow | |
| python "build_tools/build_pmma.py" -in_github_workflow | |
| - name: Upload wheel | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheel-${{ matrix.os }}-${{ matrix.python-version }} | |
| path: dist/*.whl | |
| # ────────────────────────────────────── | |
| # 3. sdist and publish | |
| # ────────────────────────────────────── | |
| sdist: | |
| name: Build Source Distribution | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: actions/setup-python@v5 | |
| 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 + GitHub Release | |
| runs-on: ubuntu-latest | |
| needs: [build_windows, sdist, build_linux] | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: ./artifacts | |
| - name: Move distribution files | |
| run: | | |
| mkdir -p dist | |
| find artifacts -type f \( -name "*.whl" -o -name "*.tar.gz" \) -exec mv {} dist/ \; | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@v1.12.4 | |
| with: | |
| user: __token__ | |
| password: ${{ secrets.PYPI_API_TOKEN }} | |
| packages_dir: dist | |
| - name: Upload to GitHub Release | |
| if: github.event_name == 'release' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| UPLOAD_URL: ${{ github.event.release.upload_url }} | |
| run: | | |
| for f in dist/*; do | |
| echo "Uploading $f ..." | |
| curl -X POST \ | |
| -H "Authorization: token $GITHUB_TOKEN" \ | |
| -H "Content-Type: application/octet-stream" \ | |
| --data-binary @"$f" \ | |
| "${UPLOAD_URL%\{*}?name=$(basename "$f")" | |
| done |