-
-
Notifications
You must be signed in to change notification settings - Fork 10
305 lines (276 loc) · 11.1 KB
/
build.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
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
name: Build And Publish
on:
workflow_dispatch:
inputs:
build-shared-libs:
description: 'Build shared libraries'
required: false
default: true
type: boolean
build-static-libs:
description: 'Build static libraries'
required: false
default: true
type: boolean
build-wheels:
description: 'Build wheels'
required: false
default: false
type: boolean
linux-build:
description: 'Build for Linux'
required: false
default: true
type: boolean
linux-arm64-build:
description: 'Build for Linux ARM64'
required: false
default: true
type: boolean
macos-build:
description: 'Build for macOS'
required: false
default: false
type: boolean
windows-build:
description: 'Build for Windows'
required: false
default: false
type: boolean
android-build:
description: 'Build for Android'
required: false
default: false
type: boolean
publish:
description: 'Publish the library'
required: false
default: true
type: boolean
jobs:
setup:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Set matrix
id: set-matrix
run: |
build_list=""
if [[ "${{ github.event.inputs.linux-build }}" == "true" ]]; then
build_list+=",{\"os\":\"ubuntu-latest\",\"cibw_archs\":\"native\",\"shared_name\":\"linux-x86_64\",\"cibw_os_build\":\"manylinux_\",\"image_arch\":\"x86_64\"}"
fi
if [[ "${{ github.event.inputs.linux-arm64-build }}" == "true" ]]; then
build_list+=",{\"os\":\"arm64-server\",\"cibw_archs\":\"aarch64\",\"shared_name\":\"linux-arm64\",\"cibw_os_build\":\"manylinux_\",\"image_arch\":\"arm64\"}"
fi
if [[ "${{ github.event.inputs.macos-build }}" == "true" ]]; then
build_list+=",{\"os\":\"macos-15\",\"cibw_archs\":\"native\",\"shared_name\":\"macos-arm64\",\"cibw_os_build\":\"macosx_\"}"
fi
if [[ "${{ github.event.inputs.windows-build }}" == "true" ]]; then
build_list+=",{\"os\":\"windows-2022\",\"cibw_archs\":\"native\",\"shared_name\":\"windows-x86_64\"}"
fi
if [[ -n "$build_list" ]]; then
build_list="${build_list:1}"
fi
matrix=$(echo "{\"include\":[$build_list]}")
echo "matrix=$matrix" >> $GITHUB_OUTPUT
build:
if: github.event.inputs.build-wheels == 'true' || github.event.inputs.build-shared-libs == 'true' || github.event.inputs.build-static-libs == 'true'
needs: setup
runs-on: ${{ matrix.os }}
strategy:
matrix: ${{fromJson(needs.setup.outputs.matrix)}}
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Python
uses: actions/setup-python@v5
if: matrix.cibw_archs != 'aarch64'
id: python
with:
python-version: "3.9 - 3.13"
update-environment: false
- name: Set up Python (ARM64)
if: matrix.cibw_archs == 'aarch64'
id: python-arm64
run: echo "python-path=python3.12" >> $GITHUB_OUTPUT
- name: Install Python Requirements
if: matrix.shared_name != 'linux-x86_64' && matrix.shared_name != 'linux-arm64'
run: |
"${{ steps.python.outputs.python-path || steps.python-arm64.outputs.python-path }}" -m pip install setuptools
shell: bash
- name: Set up QEMU
if: matrix.cibw_archs == 'aarch64'
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Build Shared Libs
if: matrix.shared_name != 'linux-x86_64' && matrix.shared_name != 'linux-arm64' && github.event.inputs.build-shared-libs == 'true'
run: |
${{ steps.python.outputs.python-path }} setup.py build_lib
- name: Build Static Libs
if: matrix.shared_name != 'linux-x86_64' && matrix.shared_name != 'linux-arm64' && github.event.inputs.build-static-libs == 'true'
run: |
${{ steps.python.outputs.python-path }} setup.py build_lib --static
- name: Build Shared Libs (Linux)
if: (matrix.shared_name == 'linux-x86_64' || matrix.shared_name == 'linux-arm64') && github.event.inputs.build-shared-libs == 'true'
run: |
docker run -v $(pwd):/app -w /app ghcr.io/pytgcalls/ntgcalls/${{ matrix.image_arch }}:latest bash -c "
python3.12 -m pip install setuptools
python3.12 setup.py build_lib"
- name: Build Static Libs (Linux)
if: (matrix.shared_name == 'linux-x86_64' || matrix.shared_name == 'linux-arm64') && github.event.inputs.build-static-libs == 'true'
run: |
docker run -v $(pwd):/app -w /app ghcr.io/pytgcalls/ntgcalls/${{ matrix.image_arch }}:latest bash -c "
python3.12 -m pip install setuptools
python3.12 setup.py build_lib --static"
- name: Upload Shared Libs for ${{ matrix.shared_name }}
uses: actions/upload-artifact@v4
if: github.event.inputs.build-shared-libs == 'true'
with:
name: ntgcalls.${{ matrix.shared_name }}-shared_libs
path: ./shared-output/*
if-no-files-found: error
- name: Upload Static Libs for ${{ matrix.shared_name }}
uses: actions/upload-artifact@v4
if: github.event.inputs.build-static-libs == 'true'
with:
name: ntgcalls.${{ matrix.shared_name }}-static_libs
path: ./static-output/*
if-no-files-found: error
- name: Build wheels
uses: ./.github/cibuildwheel
if: github.event.inputs.build-wheels == 'true'
with:
python-path: ${{ steps.python.outputs.python-path || steps.python-arm64.outputs.python-path }}
env:
CIBW_ARCHS: ${{ matrix.cibw_archs }}
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.9"
CIBW_BUILD: cp3*-${{ matrix.cibw_os_build }}*
CIBW_SKIP: cp36-* cp37-*
CIBW_BUILD_VERBOSITY: 3
CIBW_TEST_SKIP: "cp38-macosx_arm64 *-manylinux_aarch64"
CIBW_TEST_COMMAND: python -c "from ntgcalls import NTgCalls; NTgCalls().ping()"
CIBW_MANYLINUX_AARCH64_IMAGE: ghcr.io/pytgcalls/ntgcalls/arm64:latest
CIBW_MANYLINUX_X86_64_IMAGE: ghcr.io/pytgcalls/ntgcalls/x86_64:latest
- uses: actions/upload-artifact@v4
if: github.event.inputs.build-wheels == 'true'
with:
name: ntgcalls-${{ matrix.shared_name }}-wheels
path: ./wheelhouse/*.whl
if-no-files-found: error
build-android:
needs: setup
runs-on: ubuntu-latest
if: github.event.inputs.android-build == 'true'
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Python
uses: actions/setup-python@v5
id: python
with:
python-version: "3.12"
update-environment: false
- name: Install Python Requirements
run: |
"${{ steps.python.outputs.python-path }}" -m pip install setuptools
"${{ steps.python.outputs.python-path }}" -m pip install pipx
shell: bash
- name: Build JNI Libraries
run: |
${{ steps.python.outputs.python-path }} setup.py build_lib --android
shell: bash
- name: Set up Maven Central Repository
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
server-id: central
- name: Publish Library to Maven Central
run: bash ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.CENTRAL_TOKEN_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}
shell: bash
working-directory: android/
publish:
runs-on: ubuntu-latest
needs: [ build ]
if: github.event.inputs.publish == 'true'
permissions:
id-token: write
contents: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
submodules: recursive
- name: Get library Version
id: get-library-version
run: |
VERSION=$(grep -oP -m 1 'ntgcalls VERSION \K[A-Za-z0-9.]+' CMakeLists.txt)
echo "Library Version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Patch version number
id: patch-version
run: |
version="${{ steps.get-library-version.outputs.version }}"
if [[ "$version" == *.*.*.* ]]; then
echo "Version contains three dots"
major=$(echo "$version" | cut -d. -f1)
minor=$(echo "$version" | cut -d. -f2)
patch=$(echo "$version" | cut -d. -f3)
tweak=$(echo "$version" | cut -d. -f4)
new_version="${major}.${minor}.${patch}.dev${tweak}"
echo $new_version
echo "new_version=$new_version" >> $GITHUB_OUTPUT
echo "is_dev=true" >> $GITHUB_OUTPUT
else
echo "Version does not contain three dots"
echo "new_version=${{ steps.get-library-version.outputs.version }}" >> $GITHUB_OUTPUT
echo "is_dev=false" >> $GITHUB_OUTPUT
fi
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: tmp/
- name: Prepare source distribution
if: github.event.inputs.build-wheels == 'true'
run: |
python3 -m pip install --upgrade setuptools
python3 setup.py sdist
- name: Zip releases
run: |
mkdir releases
for dir in tmp/*_libs; do
if [ -d "$dir" ]; then
echo "$dir"
folder_name=$(basename "$dir" .zip)
(cd $dir && zip -r "../../releases/${folder_name}.zip" *)
fi
done
- name: Create Release
id: create-new-release
uses: softprops/action-gh-release@v2
with:
files: |
./releases/*
tag_name: "v${{ steps.patch-version.outputs.new_version }}"
name: "NTgCalls auto build v${{ steps.patch-version.outputs.new_version }}"
body: "These are the build files for the commit [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}).\nThese files were built during [this workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})."
prerelease: ${{ steps.patch-version.outputs.is_dev }}
- name: Extract artifacts
run: find tmp -type f -name "*.whl" | xargs -I {} mv {} dist
- name: Publish a Python distribution to PyPI.
if: github.event.inputs.build-wheels == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
packages-dir: dist/