Skip to content

Commit 8c8545b

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

File tree

2 files changed

+100
-75
lines changed

2 files changed

+100
-75
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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

.github/workflows/build_and_test.yml

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -76,83 +76,10 @@ jobs:
7676
shell: bash
7777

7878
build_bin_wheels:
79-
needs: build_and_test_python
80-
runs-on: ubuntu-latest
8179
permissions:
8280
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
81+
needs: build_and_test_python
82+
uses: sippy/libasyncproxy/.github/workflows/BuildPythonWheels.yml@wip
15683

15784
publish_pypi:
15885
needs: build_bin_wheels

0 commit comments

Comments
 (0)