7
7
workflow_dispatch :
8
8
9
9
jobs :
10
- pypi-publish :
11
- name : Upload release to PyPI
10
+ build-wheels :
11
+ name : Build wheels on ${{ matrix.os }}
12
+ runs-on : ${{ matrix.os }}
13
+ strategy :
14
+ fail-fast : false
15
+ matrix :
16
+ os : [ubuntu-22.04, windows-2022, macos-12]
17
+ # 包含 ARM 架构支持
18
+ include :
19
+ - os : macos-12
20
+ arch : arm64
21
+ - os : macos-12
22
+ arch : x86_64
23
+ - os : ubuntu-22.04
24
+ arch : x86_64
25
+ - os : ubuntu-22.04
26
+ arch : aarch64
27
+ emulator : qemu-arm
28
+ - os : windows-2022
29
+ arch : AMD64
30
+
31
+ steps :
32
+ - uses : actions/checkout@v4
33
+
34
+ # macOS ARM 架构特殊处理
35
+ - name : Set up macOS ARM
36
+ if : matrix.os == 'macos-12' && matrix.arch == 'arm64'
37
+ run : |
38
+ echo "CMAKE_OSX_ARCHITECTURES=arm64" >> $GITHUB_ENV
39
+ echo "CIBW_ARCHS_MACOS=arm64" >> $GITHUB_ENV
40
+
41
+ # Linux ARM 架构设置
42
+ - name : Set up QEMU for ARM
43
+ if : matrix.arch == 'aarch64'
44
+ uses : docker/setup-qemu-action@v3
45
+ with :
46
+ platforms : arm64
47
+
48
+ - name : Set up Python
49
+ uses : actions/setup-python@v5
50
+ with :
51
+ python-version : " 3.10"
52
+
53
+ # 安装 cibuildwheel 和构建工具
54
+ - name : Install cibuildwheel
55
+ run : python -m pip install cibuildwheel==2.16.2
56
+
57
+ # 配置包构建选项
58
+ - name : Set build options
59
+ run : |
60
+ echo "CIBW_BUILD=cp3*-*" >> $GITHUB_ENV
61
+ echo "CIBW_BEFORE_ALL_LINUX=apt-get update && apt-get install -y build-essential" >> $GITHUB_ENV
62
+ echo "CIBW_BEFORE_ALL_WINDOWS=choco install -y vcbuildtools" >> $GITHUB_ENV
63
+ echo "CIBW_ENVIRONMENT_LINUX=PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1" >> $GITHUB_ENV
64
+ echo "CIBW_ENVIRONMENT_WINDOWS=PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1" >> $GITHUB_ENV
65
+ echo "CIBW_ENVIRONMENT_MACOS=PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1" >> $GITHUB_ENV
66
+
67
+ # 执行多平台构建
68
+ - name : Build wheels
69
+ run : python -m cibuildwheel --output-dir wheelhouse
70
+ env :
71
+ CIBW_ARCHS : ${{ matrix.arch || 'auto' }}
72
+ CIBW_PLATFORM : ${{ matrix.os }}
73
+
74
+ # 上传生成的 wheel 文件
75
+ - uses : actions/upload-artifact@v3
76
+ with :
77
+ name : wheels
78
+ path : ./wheelhouse/*.whl
79
+
80
+ sdist :
81
+ name : Build source distribution
82
+ runs-on : ubuntu-latest
83
+ steps :
84
+ - uses : actions/checkout@v4
85
+ - name : Set up Python
86
+ uses : actions/setup-python@v5
87
+ with :
88
+ python-version : " 3.10"
89
+
90
+ - name : Install build tools
91
+ run : python -m pip install build
92
+
93
+ - name : Build sdist
94
+ run : python -m build --sdist --outdir dist/
95
+
96
+ - uses : actions/upload-artifact@v3
97
+ with :
98
+ name : sdist
99
+ path : dist/*.tar.gz
100
+
101
+ publish :
102
+ name : Publish to PyPI
103
+ needs : [build-wheels, sdist]
12
104
runs-on : ubuntu-latest
13
105
steps :
14
- - uses : actions/checkout@master
15
- - name : Set up Python
16
- uses : actions/setup-python@v1
17
- with :
18
- python-version : " 3.x"
19
- - name : Install pypa/build
20
- run : >-
21
- python -m
22
- pip install
23
- build
24
- --user
25
- - name : Build a binary wheel and a source tarball
26
- run : >-
27
- python -m
28
- build
29
- --sdist
30
- --wheel
31
- --outdir dist/
32
- .
33
- - name : Publish distribution to PyPI
34
- uses : pypa/gh-action-pypi-publish@release/v1
35
- with :
36
- password : ${{ secrets.PYPI_API_TOKEN }}
106
+ # 下载所有构建产物
107
+ - name : Download artifacts
108
+ uses : actions/download-artifact@v3
109
+ with :
110
+ name : wheels
111
+ path : dist
112
+ - name : Download sdist
113
+ uses : actions/download-artifact@v3
114
+ with :
115
+ name : sdist
116
+ path : dist
117
+
118
+ # 发布到 PyPI
119
+ - name : Publish package
120
+ uses : pypa/gh-action-pypi-publish@release/v1
121
+ with :
122
+ password : ${{ secrets.PYPI_API_TOKEN }}
123
+ skip_existing : true
124
+ verbose : true
0 commit comments