-
Notifications
You must be signed in to change notification settings - Fork 283
141 lines (113 loc) · 4.31 KB
/
wheels.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: wheels
on:
pull_request:
push:
branches: master
release:
types: [released, prereleased]
workflow_dispatch: # allows running workflow manually from the Actions tab
jobs:
build-sdist:
runs-on: ubuntu-latest
env:
PIP_DISABLE_PIP_VERSION_CHECK: 1
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- run: sudo apt-get install -y libmagic1
- name: Build source distribution
run: |
pip install --upgrade setuptools wheel pip
python setup.py sdist
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/*.tar.*
build-wheels-matrix:
runs-on: ubuntu-latest
outputs:
include: ${{ steps.set-matrix.outputs.include }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- run: pip install cibuildwheel==2.18.1 # sync version with pypa/cibuildwheel below
- id: set-matrix
env:
# only mention one (trivial) python version, as py2.py3 wheels only need to be build once per arch
CIBW_PROJECT_REQUIRES_PYTHON: '==3.12.*'
# skip PyPy wheels for now, and skip i686 wheels because pytest is failing
CIBW_SKIP: pp* *i686
run: |
MATRIX_INCLUDE=$(
{
cibuildwheel --print-build-identifiers --platform linux --arch all | jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \
&& cibuildwheel --print-build-identifiers --platform macos --arch x86_64 | jq -nRc '{"only": inputs, "os": "macos-12"}' \
&& cibuildwheel --print-build-identifiers --platform macos --arch arm64 | jq -nRc '{"only": inputs, "os": "macos-14"}' \
&& cibuildwheel --print-build-identifiers --platform windows --arch x86,AMD64 | jq -nRc '{"only": inputs, "os": "windows-latest"}'
} | jq -sc
)
echo "include=$MATRIX_INCLUDE" >> $GITHUB_OUTPUT
build-wheels:
name: build ${{ matrix.only }}
needs: build-wheels-matrix
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.build-wheels-matrix.outputs.include) }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
- uses: pypa/[email protected] # sync version with pip install cibuildwheel above
timeout-minutes: 10
with:
only: ${{ matrix.only }}
env:
CIBW_BUILD_VERBOSITY: 1
# add compiled libmagic to the build directory (to include in the wheel)
CIBW_BEFORE_BUILD: ${{ ( startsWith( matrix.os, 'macos' ) && 'sudo chmod -R 777 /usr/local && bash add_libmagic.sh' ) || 'bash add_libmagic.sh' }}
# build macos wheels with maximum backwards compatibility (gcc -mmacosx-version-min flag)
MACOSX_DEPLOYMENT_TARGET: ${{ ( endsWith( matrix.only, 'arm64' ) && '11.0' ) || '12.0' }}
# simple smoke test run on each wheel: this is an HLS MP4 video, only recognised in recent versions of libmagic
CIBW_TEST_COMMAND: python -c "import magic; assert magic.Magic(mime=True).from_buffer(b'\x00\x00\x00\x1cftypiso5\x00\x00\x00\x01isomiso5hlsf\x00\x00') == 'video/mp4'"
- uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.only }}
path: wheelhouse/*.whl
publish:
if: github.event_name == 'release'
needs: [build-sdist, build-wheels]
runs-on: ubuntu-latest
permissions:
contents: write # softprops/action-gh-release
id-token: write # pypa/gh-action-pypi-publish
steps:
- uses: actions/setup-python@v5
with:
python-version: 3.x
- uses: actions/download-artifact@v4
with:
path: dist/
pattern: dist-*
merge-multiple: true
- run: ls -ltra dist/
- run: pip install --upgrade python-magic --find-links ./dist
- name: Smoketest
run: python -c "import magic; magic.Magic()"
- name: Upload release assets
uses: softprops/[email protected]
with:
files: dist/*
- name: Publish package distributions to PyPI
uses: pypa/[email protected]