Skip to content

Commit

Permalink
FIX-#416: Build bdist and sdist in CI and upload to PyPI (#423)
Browse files Browse the repository at this point in the history
Signed-off-by: Iaroslav Igoshev <[email protected]>
  • Loading branch information
YarShev authored May 29, 2024
1 parent 7d71495 commit 91ff541
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 41 deletions.
112 changes: 112 additions & 0 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Workflow to build wheels for upload to PyPI.
# Inspired by numpy's cibuildwheel config https://github.com/numpy/numpy/blob/main/.github/workflows/wheels.yml

name: Build and upload to PyPI

on:
push:
workflow_dispatch:

jobs:
build_sdist:
name: Build sdist
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags'))
runs-on: ubuntu-latest
steps:
- name: Checkout unidist
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install Cython
run: pip install Cython

- name: Build sdist
run: python setup.py sdist

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: cibw-sdist
path: dist/*.tar.gz

- name: Sanity check sdist files
run: ls ./dist

build_wheels:
needs: build_sdist
name: Build wheel for ${{ matrix.python }}-${{ matrix.buildplat[1] }}
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags'))
runs-on: ${{ matrix.buildplat[0] }}
strategy:
# Ensure that a wheel builder finishes even if another fails
fail-fast: false
matrix:
# GitHub Actions doesn't support pairing matrix values together, let's improvise
# https://github.com/github/feedback/discussions/7835#discussioncomment-1769026
buildplat:
- [ubuntu-22.04, manylinux_x86_64]
- [ubuntu-22.04, musllinux_x86_64]
- [macos-12, macosx_x86_64]
# Note: M1 images on Github Actions start from macOS 14
- [macos-14, macosx_arm64]
- [windows-2022, win_amd64]
- [windows-2022, win32]
python: ["cp39", "cp310", "cp311", "cp312"]

steps:
- name: Checkout unidist
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation"
CIBW_BEFORE_BUILD: pip install wheel setuptools Cython
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.python }}-${{ matrix.buildplat[1] }}
path: ./wheelhouse/*.whl

upload_pypi:
needs: [build_wheels, build_sdist]
name: Upload to PyPI
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags'))
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
# unpacks all CIBW artifacts into dist/
pattern: cibw-*
path: dist
merge-multiple: true

- name: Upload bdist and sdist
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://pypi.org/p/unidist
41 changes: 0 additions & 41 deletions docs/build_wheels.rst

This file was deleted.

0 comments on commit 91ff541

Please sign in to comment.