Skip to content

Move build_bin_wheels into its own module so that we can share. #2

Move build_bin_wheels into its own module so that we can share.

Move build_bin_wheels into its own module so that we can share. #2

name: 'Wheel Builder'
description: 'Build Binary wheels for a Python project'
on:
workflow_call:
inputs:
dockerfile:
description: 'Dockerfile to use'
required: false
default: './docker/Dockerfile.python_wheels'
context:
description: 'Context to pass into container'
required: false
default: '.'
py_versions:
description: 'Versions of Python to build against'
required: false
type: array
default:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
jobs:
build_bin_wheels:
runs-on: ubuntu-latest
permissions:
packages: write
env:
PY_VER: ${{ matrix.python-version }}
BASE_IMAGE: quay.io/pypa/manylinux_${{ matrix.mnl-version }}:latest
GHCR_REPO: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
strategy:
fail-fast: false
matrix:
python-version: ${{ inputs.py_versions }}
mnl-version: ['2_28', '2_34']
steps:
- name: Set up Python ${{ env.PY_VER }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PY_VER }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set dynamic environment
id: set-env
run: |
PLATFORMS="`docker manifest inspect ${{ env.BASE_IMAGE }} | \
jq -r '.manifests[] | "\(.platform.os)/\(.platform.architecture)\(if .platform.variant != null then "/\(.platform.variant)" else "" end)"' | \
sort -u | grep -v unknown | paste -sd ','`"
GIT_BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
GIT_BRANCH="${GIT_BRANCH#refs/tags/}"
BUILD_IMAGE="${GHCR_REPO}:${GIT_BRANCH}-py${PY_VER}-mnl${{ matrix.mnl-version }}"
test "${{ github.event_name }}" != 'pull_request' && \
CACHE_SPEC="type=registry,ref=${BUILD_IMAGE}-buildcache" || \
CACHE_SPEC="gha"
echo "Platforms: ${PLATFORMS}"
echo "Build Image: ${BUILD_IMAGE}"
echo "PLATFORMS=${PLATFORMS}" >> $GITHUB_ENV
echo "CACHE_SPEC=${CACHE_SPEC}" >> $GITHUB_ENV
- name: Build Binary Wheels
uses: docker/build-push-action@v6
with:
context: ${{ inputs.context }}
file: ${{ inputs.dockerfile }}
build-args: |
BASE_IMAGE=${{ env.BASE_IMAGE }}
PY_VER=${{ env.PY_VER }}
platforms: ${{ env.PLATFORMS }}
push: false
outputs: type=local,dest=dist_out
cache-from: ${{ env.CACHE_SPEC }}
cache-to: ${{ env.CACHE_SPEC }},mode=max
- name: Collect Wheels
run: |
mkdir dist
mv `find dist_out -type f -name \*.whl` dist
rm -r dist_out
- name: Upload Wheels
uses: actions/upload-artifact@v4
with:
name: dist-py${{ env.PY_VER }}-mnl${{ matrix.mnl-version }}
path: dist