Skip to content

Commit da590ed

Browse files
committed
Move build_bin_wheels into its own module so that we can share.
1 parent 3b1f18e commit da590ed

File tree

2 files changed

+104
-76
lines changed

2 files changed

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

.github/workflows/build_and_test.yml

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -77,82 +77,7 @@ jobs:
7777

7878
build_bin_wheels:
7979
needs: build_and_test_python
80-
runs-on: ubuntu-latest
81-
permissions:
82-
packages: write
83-
env:
84-
PY_VER: ${{ matrix.python-version }}
85-
BASE_IMAGE: quay.io/pypa/manylinux_${{ matrix.mnl-version }}:latest
86-
GHCR_REPO: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
87-
strategy:
88-
fail-fast: false
89-
matrix:
90-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
91-
mnl-version: ['2_28', '2_34']
92-
steps:
93-
- name: Set up Python ${{ env.PY_VER }}
94-
uses: actions/setup-python@v5
95-
with:
96-
python-version: ${{ env.PY_VER }}
97-
98-
- uses: actions/checkout@v4
99-
100-
- name: Set up QEMU
101-
uses: docker/setup-qemu-action@v3
102-
103-
- name: Set up Docker Buildx
104-
uses: docker/setup-buildx-action@v3
105-
106-
- name: Login to GitHub Container Registry
107-
uses: docker/login-action@v3
108-
if: github.event_name != 'pull_request'
109-
with:
110-
registry: ghcr.io
111-
username: ${{ github.repository_owner }}
112-
password: ${{ secrets.GITHUB_TOKEN }}
113-
114-
- name: Set dynamic environment
115-
id: set-env
116-
run: |
117-
PLATFORMS="`docker manifest inspect ${{ env.BASE_IMAGE }} | \
118-
jq -r '.manifests[] | "\(.platform.os)/\(.platform.architecture)\(if .platform.variant != null then "/\(.platform.variant)" else "" end)"' | \
119-
sort -u | grep -v unknown | paste -sd ','`"
120-
GIT_BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
121-
GIT_BRANCH="${GIT_BRANCH#refs/tags/}"
122-
BUILD_IMAGE="${GHCR_REPO}:${GIT_BRANCH}-py${PY_VER}-mnl${{ matrix.mnl-version }}"
123-
test "${{ github.event_name }}" != 'pull_request' && \
124-
CACHE_SPEC="type=registry,ref=${BUILD_IMAGE}-buildcache" || \
125-
CACHE_SPEC="gha"
126-
echo "Platforms: ${PLATFORMS}"
127-
echo "Build Image: ${BUILD_IMAGE}"
128-
echo "PLATFORMS=${PLATFORMS}" >> $GITHUB_ENV
129-
echo "CACHE_SPEC=${CACHE_SPEC}" >> $GITHUB_ENV
130-
131-
- name: Build Binary Wheels
132-
uses: docker/build-push-action@v6
133-
with:
134-
context: .
135-
file: ./docker/Dockerfile.python_wheels
136-
build-args: |
137-
BASE_IMAGE=${{ env.BASE_IMAGE }}
138-
PY_VER=${{ env.PY_VER }}
139-
platforms: ${{ env.PLATFORMS }}
140-
push: false
141-
outputs: type=local,dest=dist_out
142-
cache-from: ${{ env.CACHE_SPEC }}
143-
cache-to: ${{ env.CACHE_SPEC }},mode=max
144-
145-
- name: Collect Wheels
146-
run: |
147-
mkdir dist
148-
mv `find dist_out -type f -name \*.whl` dist
149-
rm -r dist_out
150-
151-
- name: Upload built wheels
152-
uses: actions/upload-artifact@v4
153-
with:
154-
name: dist-py${{ env.PY_VER }}-mnl${{ matrix.mnl-version }}
155-
path: dist
80+
uses: sippy/libasyncproxy/.github/workflows/BuildPythonWheels.yml@wip
15681

15782
publish_pypi:
15883
needs: build_bin_wheels

0 commit comments

Comments
 (0)