-
Notifications
You must be signed in to change notification settings - Fork 2
260 lines (220 loc) · 8.95 KB
/
Copy pathtestbuild.yml
File metadata and controls
260 lines (220 loc) · 8.95 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
name: Just test
# 触发机制为“非主分支的提交”
on:
workflow_dispatch:
push:
branches-ignore:
- main # 排除主分支
- master # 如果有 master 分支,也可以排除
jobs:
build: # 编译C库
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: windows-2022
arch: x86_64 # windows x86_6
- os: ubuntu-22.04
arch: x86_64 # Ubuntu x86_64
- os: macos-13
arch: x86_64 # macOS Intel
- os: macos-14
arch: arm64 # macOS Apple Silicon
fail-fast: true
defaults:
run:
shell: bash
steps:
- name: Set MSYS2 (Windows) # windows平台使用MSYS2工具编译程序
if: contains(matrix.os, 'windows')
uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
install: >-
git
mingw-w64-ucrt-x86_64-gcc
make
- name: Configured git attributes for line endings (Windows) # 防止接下来在windows平台checkout代码时,文本文件的换行符发生变化,导致MSYS2工作出错
if: contains(matrix.os, 'windows')
run: git config --global core.autocrlf input
- name: Checkout code # 下载库代码
uses: actions/checkout@v3
with:
fetch-depth: 1
# --------------------------- 安装依赖 ------------------------------------------
# - name: Install dependencies (Ubuntu)
# if: contains(matrix.os, 'ubuntu')
# run: |
# sudo apt update
# sudo apt install -y build-essential
# 在 ubuntu 系统上创建低版本 glibc (2.17) 的环境进行编译,以提供向后兼容能力
- name: Create CentOS 7.7 container (Ubuntu)
if: contains(matrix.os, 'ubuntu')
run: |
CONTAINER_ID=$(docker create -v ${{ github.workspace }}:/workspace -w /workspace centos:7.7.1908 sleep infinity)
echo "CONTAINER_ID=$CONTAINER_ID" >> $GITHUB_ENV
docker start $CONTAINER_ID
- name: Update yum in container (Ubuntu)
if: contains(matrix.os, 'ubuntu')
run: |
docker exec ${{ env.CONTAINER_ID }} bash -c "
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup && \
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo && \
yum clean all -y && yum makecache -y && yum install -y gcc make
"
- name: Install dependencies (macOS)
# 匹配包含 "macos" 的操作系统
if: contains(matrix.os, 'macos')
run: |
brew install libomp
# ----------------- 编译C库和C程序 ----------------------------------
- name: Build the project (macOS)
if: contains(matrix.os, 'macos')
working-directory: ./pyfmm/C_extension
run: |
make ARCH="-arch ${{ matrix.arch }}" \
CC=gcc-14
make cleanbuild
otool -L lib/*.so
# - name: Build the project (Ubuntu)
# if: contains(matrix.os, 'ubuntu')
# working-directory: ./pyfmm/C_extension
# run: |
# make
# make cleanbuild
# ldd lib/*.so
- name: Build the project in container (Ubuntu)
if: contains(matrix.os, 'ubuntu')
working-directory:
run: |
docker exec ${{ env.CONTAINER_ID }} bash -c "cd pyfmm/C_extension && ls && make && make cleanbuild && cd -"
cd ./pyfmm/C_extension
ldd lib/*.so
cd -
- name: Cleanup container (Ubuntu)
if: contains(matrix.os, 'ubuntu')
run: |
docker stop ${{ env.CONTAINER_ID }}
docker rm ${{ env.CONTAINER_ID }}
- name: Build the project (Windows)
if: contains(matrix.os, 'windows')
shell: msys2 {0}
working-directory: ./pyfmm/C_extension
run: |
make
make cleanbuild
ldd lib/*.so
# ------------------------ 定义接下来打包程序命名时的系统名后缀 ---------------
- name: Define the package OS suffix
run: |
# 符合pypi命名规范,否则上传失败
if [[ "${{ matrix.os }}" == *"ubuntu"* ]]; then
SUFFIX_PLAT_NAME="manylinux2014_x86_64"
elif [[ "${{ matrix.os }}" == *"macos"* && "${{ matrix.arch }}" == *"x86_64"* ]]; then
SUFFIX_PLAT_NAME="macosx_10_9_x86_64"
elif [[ "${{ matrix.os }}" == *"macos"* && "${{ matrix.arch }}" == *"arm64"* ]]; then
SUFFIX_PLAT_NAME="macosx_11_0_arm64"
elif [[ "${{ matrix.os }}" == *"windows"* ]]; then
SUFFIX_PLAT_NAME="win_amd64"
else
echo " Unsupported OS: ${{ matrix.os }} (${{ matrix.arch }})"
exit 1
fi
echo "SUFFIX_PLAT_NAME=$SUFFIX_PLAT_NAME" >> $GITHUB_ENV
# --------------------------- 打包整个程序 ---------------------
- name: Package the binary
run: |
PACK_NAME=pyfmm_kit-${{ github.ref_name }}-${{ env.SUFFIX_PLAT_NAME }}
echo "PACK_NAME=$PACK_NAME" >> $GITHUB_ENV
FILE_CONTENT=$(ls -A)
mkdir -p $PACK_NAME
cp -r ${FILE_CONTENT} $PACK_NAME/
tar -czvf $PACK_NAME.tar.gz $PACK_NAME
rm -rf $PACK_NAME
# -------------------- upload artifacts -----------------------
- name: Upload artifact (*.tar.gz)
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.arch }}_tar
path: ${{ env.PACK_NAME }}.tar.gz
# =======================================================================================
test_project: # 在全新系统上测试程序,不安装其它依赖,看能否运行
runs-on: ${{ matrix.os }}
needs: build
strategy:
matrix:
include:
- os: windows-2022
arch: x86_64 # windows x86_6
- os: ubuntu-22.04
arch: x86_64 # Ubuntu x86_64
- os: macos-13
arch: x86_64 # macOS Intel
- os: macos-14
arch: arm64 # macOS Apple Silicon
fail-fast: true
defaults:
run:
shell: bash
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.arch }}_tar
path: artifacts
- name: Display structure of downloaded files, and Uncompress
run: |
ls -R artifacts
echo "------------------- tar output -----------------------------"
tar -xzvf artifacts/*.tar.gz
echo "------------------------------------------------------------"
# 获得压缩包解压出来的文件夹名
PACK_NAME=$(ls | grep pyfmm_kit)
echo "PACK_NAME=$PACK_NAME" >> $GITHUB_ENV
# 从解压出的文件夹命名来推断${{ env.SUFFIX_PLAT_NAME }}
SUFFIX_PLAT_NAME=$(echo $PACK_NAME | sed 's/.*-\(.*\)/\1/')
echo "SUFFIX_PLAT_NAME=$SUFFIX_PLAT_NAME" >> $GITHUB_ENV
echo $PACK_NAME
echo $SUFFIX_PLAT_NAME
# --------------------------- 安装依赖 ------------------------------------------
# 实际使用时可能需要安装libomp
# - name: Install libomp (Ubuntu)
# if: contains(matrix.os, 'ubuntu')
# run: |
# sudo apt install -y libomp-dev
# - name: Set alias (MacOS)
# if: contains(matrix.os, 'macos')
# run: |
# brew install coreutils
# echo "alias timeout=gtimeout" >> ~/.bashrc
# --------------------搭建python环境,开始测试,并制作wheel文件 ------------------------------
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
working-directory: ${{ env.PACK_NAME }}
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools wheel build
pip install -v .
- name: Clean up build and egg-info directories
working-directory: ${{ env.PACK_NAME }}
run: |
# 清理临时文件
rm -rf build/
rm -rf pyfmm_kit.egg-info/
- name: Test
working-directory: ${{ env.PACK_NAME }}/.github/tests
run: |
python uniform.py
# --------------------------- 制作wheels ---------------------
# - name: Build the Python Wheel
# working-directory: ${{ env.PACK_NAME }}
# run: |
# python setup.py bdist_wheel --plat-name=${{ env.SUFFIX_PLAT_NAME }} # 只制作wheel,这里不打包源码
# - name: Upload artifact (*.whl)
# uses: actions/upload-artifact@v4
# with:
# name: ${{ env.PACK_NAME }}_whl
# path: ${{ env.PACK_NAME }}/dist/*.whl