Build and upload to PyPI #4221
Workflow file for this run
This file contains 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: Build and upload to PyPI | |
on: | |
push: | |
branches: | |
- master | |
tags: | |
- v* | |
pull_request: | |
merge_group: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref || github.run_id }} | |
cancel-in-progress: true | |
jobs: | |
determine-arm64-runner: | |
runs-on: ubuntu-latest | |
permissions: read-all | |
outputs: | |
runner: ${{ steps.set-runner.outputs.runner }} | |
steps: | |
- name: Determine which runner to use for ARM64 build | |
id: set-runner | |
run: | | |
if [ "${{ github.repository_owner }}" == "deepmodeling" ]; then | |
echo "runner=[\"Linux\",\"ARM64\"]" >> $GITHUB_OUTPUT | |
else | |
echo "runner=\"ubuntu-latest\"" >> $GITHUB_OUTPUT | |
fi | |
build_wheels: | |
name: Build wheels for cp${{ matrix.python }}-${{ matrix.platform_id }} | |
needs: determine-arm64-runner | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
# linux-64 | |
- os: ubuntu-latest | |
python: 38 | |
platform_id: manylinux_x86_64 | |
# macos-x86-64 | |
- os: macos-latest | |
python: 39 | |
platform_id: macosx_universal2 | |
# win-64 | |
- os: windows-2019 | |
python: 38 | |
platform_id: win_amd64 | |
# linux-aarch64 | |
- os: ${{ fromJson(needs.determine-arm64-runner.outputs.runner) }} | |
python: 310 | |
platform_id: manylinux_aarch64 | |
dp_variant: cpu | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install uv | |
uses: astral-sh/setup-uv@v3 | |
with: | |
enable-cache: true | |
cache-dependency-glob: | | |
**/requirements*.txt | |
**/pyproject.toml | |
if: runner.os != 'Linux' | |
- uses: docker/setup-qemu-action@v3 | |
name: Setup QEMU | |
if: matrix.platform_id == 'manylinux_aarch64' && matrix.os == 'ubuntu-latest' | |
- name: Build wheels | |
uses: pypa/cibuildwheel@v2.21 | |
env: | |
CIBW_ARCHS: all | |
CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }} | |
CIBW_BUILD_FRONTEND: 'build[uv]' | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: cibw-wheels-cp${{ matrix.python }}-${{ matrix.platform_id }}-${{ strategy.job-index }} | |
path: ./wheelhouse/*.whl | |
build_sdist: | |
name: Build source distribution | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Build sdist | |
run: pipx run uv tool run --with build[uv] --from build python -m build --installer uv --sdist | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: cibw-sdist | |
path: dist/*.tar.gz | |
upload_pypi: | |
needs: [build_wheels, build_sdist] | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v') | |
permissions: | |
# IMPORTANT: this permission is mandatory for trusted publishing | |
id-token: write | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
pattern: cibw-* | |
path: dist | |
merge-multiple: true | |
- uses: pypa/gh-action-pypi-publish@release/v1 |