|
| 1 | +name: 'Wheel Builder' |
| 2 | +description: 'Build Binary wheels for a Python project' |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + dockerfile: |
| 8 | + description: 'Dockerfile to use' |
| 9 | + type: string |
| 10 | + required: false |
| 11 | + default: './docker/Dockerfile.python_wheels' |
| 12 | + context: |
| 13 | + description: 'Context to pass into container' |
| 14 | + type: string |
| 15 | + required: false |
| 16 | + default: '.' |
| 17 | + py_versions: |
| 18 | + description: 'Versions of Python to build against' |
| 19 | + type: string |
| 20 | + required: false |
| 21 | + default: '["3.8","3.9","3.10","3.11","3.12"]' |
| 22 | + |
| 23 | +jobs: |
| 24 | + build_bin_wheels: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + permissions: |
| 27 | + packages: write |
| 28 | + env: |
| 29 | + PY_VER: ${{ matrix.python-version }} |
| 30 | + BASE_IMAGE: quay.io/pypa/manylinux_${{ matrix.mnl-version }}:latest |
| 31 | + GHCR_REPO: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }} |
| 32 | + strategy: |
| 33 | + fail-fast: false |
| 34 | + matrix: |
| 35 | + python-version: ${{ fromJson(inputs.py_versions) }} |
| 36 | + mnl-version: ['2_28', '2_34'] |
| 37 | + steps: |
| 38 | + - name: Set up Python ${{ env.PY_VER }} |
| 39 | + uses: actions/setup-python@v5 |
| 40 | + with: |
| 41 | + python-version: ${{ env.PY_VER }} |
| 42 | + |
| 43 | + - name: Set up QEMU |
| 44 | + uses: docker/setup-qemu-action@v3 |
| 45 | + |
| 46 | + - name: Set up Docker Buildx |
| 47 | + uses: docker/setup-buildx-action@v3 |
| 48 | + |
| 49 | + - name: Login to GitHub Container Registry |
| 50 | + uses: docker/login-action@v3 |
| 51 | + if: github.event_name != 'pull_request' |
| 52 | + with: |
| 53 | + registry: ghcr.io |
| 54 | + username: ${{ github.repository_owner }} |
| 55 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + |
| 57 | + - name: Set dynamic environment |
| 58 | + id: set-env |
| 59 | + run: | |
| 60 | + PLATFORMS="`docker manifest inspect ${{ env.BASE_IMAGE }} | \ |
| 61 | + jq -r '.manifests[] | "\(.platform.os)/\(.platform.architecture)\(if .platform.variant != null then "/\(.platform.variant)" else "" end)"' | \ |
| 62 | + sort -u | grep -v unknown | paste -sd ','`" |
| 63 | + GIT_BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" |
| 64 | + GIT_BRANCH="${GIT_BRANCH#refs/tags/}" |
| 65 | + BUILD_IMAGE="${GHCR_REPO}:${GIT_BRANCH}-py${PY_VER}-mnl${{ matrix.mnl-version }}" |
| 66 | + test "${{ github.event_name }}" != 'pull_request' && \ |
| 67 | + CACHE_SPEC="type=registry,ref=${BUILD_IMAGE}-buildcache" || \ |
| 68 | + CACHE_SPEC="gha" |
| 69 | + echo "Platforms: ${PLATFORMS}" |
| 70 | + echo "Build Image: ${BUILD_IMAGE}" |
| 71 | + echo "PLATFORMS=${PLATFORMS}" >> $GITHUB_ENV |
| 72 | + echo "CACHE_SPEC=${CACHE_SPEC}" >> $GITHUB_ENV |
| 73 | +
|
| 74 | + - name: Build Binary Wheels |
| 75 | + uses: docker/build-push-action@v6 |
| 76 | + with: |
| 77 | + context: ${{ inputs.context }} |
| 78 | + file: ${{ inputs.dockerfile }} |
| 79 | + build-args: | |
| 80 | + BASE_IMAGE=${{ env.BASE_IMAGE }} |
| 81 | + PY_VER=${{ env.PY_VER }} |
| 82 | + platforms: ${{ env.PLATFORMS }} |
| 83 | + push: false |
| 84 | + outputs: type=local,dest=dist_out |
| 85 | + cache-from: ${{ env.CACHE_SPEC }} |
| 86 | + cache-to: ${{ env.CACHE_SPEC }},mode=max |
| 87 | + |
| 88 | + - name: Collect Wheels |
| 89 | + run: | |
| 90 | + mkdir dist |
| 91 | + mv `find dist_out -type f -name \*.whl` dist |
| 92 | + rm -r dist_out |
| 93 | +
|
| 94 | + - name: Upload Wheels |
| 95 | + uses: actions/upload-artifact@v4 |
| 96 | + with: |
| 97 | + name: dist-py${{ env.PY_VER }}-mnl${{ matrix.mnl-version }} |
| 98 | + path: dist |
0 commit comments