-
Notifications
You must be signed in to change notification settings - Fork 135
604 lines (547 loc) · 21.3 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
name: CI
on:
schedule:
- cron: "0 20 * * *" # At 8 PM UTC, which is 3 AM UTC+7
push:
branches:
- main
tags: ["v[0-9]+.[0-9]+.[0-9]+"]
paths:
[
".github/scripts/**",
".github/workflows/build.yml",
"**/CMakeLists.txt",
"**/Makefile",
"**/*.h",
"**/*.hpp",
"**/*.c",
"**/*.cpp",
"**/*.cu",
"**/*.cc",
"**/*.cxx",
"llama.cpp",
"!docs/**",
"!.gitignore",
"!README.md",
]
pull_request:
types: [opened, synchronize, reopened]
paths:
[
".github/scripts/**",
".github/workflows/build.yml",
"**/CMakeLists.txt",
"**/Makefile",
"**/*.h",
"**/*.hpp",
"**/*.c",
"**/*.cpp",
"**/*.cu",
"**/*.cc",
"**/*.cxx",
"llama.cpp",
"!docs/**",
"!.gitignore",
"!README.md",
]
workflow_dispatch:
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
MODEL_URL: https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v0.3-GGUF/resolve/main/tinyllama-1.1b-chat-v0.3.Q2_K.gguf
jobs:
create-draft-release:
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
version: ${{ steps.get_version.outputs.version }}
permissions:
contents: write
steps:
- name: Extract tag name without v prefix
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV && echo "::set-output name=version::${GITHUB_REF#refs/tags/v}"
env:
GITHUB_REF: ${{ github.ref }}
- name: Create Draft Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: "${{ env.VERSION }}"
draft: true
prerelease: false
# Get the latest version of the release
set-nitro-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version_update.outputs.new_version }}
steps:
- name: Get latest release
id: version_update
run: |
ldd --version
if [[ ${{ github.event_name }} == push && ${{ github.ref }} == refs/tags/* ]]; then
echo "VERSION=${GITHUB_REF#refs/tags/}"
NEW_VERSION="${VERSION#v}"
echo "::set-output name=new_version::$NEW_VERSION"
else
# Function to get the latest release tag
get_latest_tag() {
local retries=0
local max_retries=3
local tag
while [ $retries -lt $max_retries ]; do
tag=$(curl -s https://api.github.com/repos/janhq/nitro/releases/latest | jq -r .tag_name)
if [ -n "$tag" ] && [ "$tag" != "null" ]; then
echo $tag
return
else
let retries++
sleep 2
fi
done
echo "Failed to fetch latest tag after $max_retries attempts."
exit 1
}
# Get the latest release tag from GitHub API
LATEST_TAG=$(get_latest_tag)
# Remove the 'v' and append the build number to the version
NEW_VERSION="${LATEST_TAG#v}-${GITHUB_RUN_NUMBER}"
echo "New version: $NEW_VERSION"
echo "::set-output name=new_version::$NEW_VERSION"
fi
echo "Version: $NEW_VERSION"
ubuntu-amd64-build:
runs-on: ubuntu-18-04-cuda-11-7
needs: [create-draft-release, set-nitro-version]
if: always() && (needs.create-draft-release.result == 'success' || needs.create-draft-release.result == 'skipped') && needs.set-nitro-version.result == 'success'
permissions:
contents: write
steps:
- name: Clone
id: checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build
id: make_build
run: |
ldd --version
./install_deps.sh
mkdir build && cd build
cmake -DLLAMA_NATIVE=OFF -DNITRO_VERSION=${{ needs.set-nitro-version.outputs.version }} ..
make -j $(nproc)
ls -la
- name: Package
shell: bash
run: |
mkdir -p nitro
cp build/nitro nitro/
tar -czvf nitro.tar.gz nitro
- name: Upload Artifact
uses: actions/upload-artifact@v2
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
with:
name: nitro-linux-amd64
path: ./nitro
- name: Run e2e testing
shell: bash
run: |
# run e2e testing
cd nitro
chmod +x ../.github/scripts/e2e-test-linux-and-mac.sh && ../.github/scripts/e2e-test-linux-and-mac.sh ./nitro ${{ env.MODEL_URL }}
- uses: actions/[email protected]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
asset_path: ./nitro.tar.gz
asset_name: nitro-${{ needs.create-draft-release.outputs.version }}-linux-amd64.tar.gz
asset_content_type: application/gzip
ubuntu-amd64-cuda-build:
runs-on: ubuntu-18-04-cuda-${{ matrix.cuda }}
needs: [create-draft-release, set-nitro-version]
if: always() && (needs.create-draft-release.result == 'success' || needs.create-draft-release.result == 'skipped') && needs.set-nitro-version.result == 'success'
permissions:
contents: write
strategy:
matrix:
cuda: ["12-0", "11-7"]
steps:
- name: Clone
id: checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build
id: make_build
run: |
./install_deps.sh
mkdir build && cd build
cmake -DLLAMA_CUBLAS=ON -DLLAMA_NATIVE=OFF -DNITRO_VERSION=${{ needs.set-nitro-version.outputs.version }} ..
make -j $(nproc)
ls -la
- name: Package
shell: bash
run: |
mkdir -p nitro
cp build/nitro nitro/
tar -czvf nitro.tar.gz nitro
- name: Upload Artifact
uses: actions/upload-artifact@v2
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
with:
name: nitro-linux-amd64-cuda-${{ matrix.cuda }}
path: ./nitro
# - name: Run e2e testing
# shell: bash
# run: |
# # run e2e testing
# cd nitro
# chmod +x ../.github/scripts/e2e-test-linux-and-mac.sh && ../.github/scripts/e2e-test-linux-and-mac.sh ./nitro ${{ env.MODEL_URL }}
- uses: actions/[email protected]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
asset_path: ./nitro.tar.gz
asset_name: nitro-${{ needs.create-draft-release.outputs.version }}-linux-amd64-cuda-${{ matrix.cuda }}.tar.gz
asset_content_type: application/gzip
macOS-M-build:
runs-on: mac-silicon
needs: [create-draft-release, set-nitro-version]
if: always() && (needs.create-draft-release.result == 'success' || needs.create-draft-release.result == 'skipped') && needs.set-nitro-version.result == 'success'
permissions:
contents: write
steps:
- name: Clone
id: checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Dependencies
id: depends
continue-on-error: true
run: |
brew update
brew install cmake
- name: Build
id: cmake_build
run: |
./install_deps.sh
mkdir build && cd build
cmake -DNITRO_VERSION=${{ needs.set-nitro-version.outputs.version }} ..
CC=gcc-8 make -j $(sysctl -n hw.ncp)
ls -la
- name: Package
shell: bash
run: |
mkdir -p nitro
cp llama.cpp/ggml-metal.metal nitro/
cp build/nitro nitro/
tar -czvf nitro.tar.gz nitro
- name: Upload Artifact
uses: actions/upload-artifact@v2
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
with:
name: nitro-mac-arm64
path: ./nitro
- name: Run e2e testing
shell: bash
run: |
# run e2e testing
cd nitro
chmod +x ../.github/scripts/e2e-test-linux-and-mac.sh && ../.github/scripts/e2e-test-linux-and-mac.sh ./nitro ${{ env.MODEL_URL }}
- uses: actions/[email protected]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
asset_path: ./nitro.tar.gz
asset_name: nitro-${{ needs.create-draft-release.outputs.version }}-mac-arm64.tar.gz
asset_content_type: application/gzip
macOS-Intel-build:
runs-on: macos-latest
needs: [create-draft-release, set-nitro-version]
if: always() && (needs.create-draft-release.result == 'success' || needs.create-draft-release.result == 'skipped') && needs.set-nitro-version.result == 'success'
permissions:
contents: write
steps:
- name: Clone
id: checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Dependencies
id: depends
continue-on-error: true
run: |
brew update
- name: Build
id: cmake_build
run: |
./install_deps.sh
mkdir build && cd build
cmake -DNITRO_VERSION=${{ needs.set-nitro-version.outputs.version }} -DLLAMA_METAL=OFF ..
CC=gcc-8 make -j $(sysctl -n hw.ncp)
ls -la
- name: Package
shell: bash
run: |
mkdir -p nitro
cp build/nitro nitro/
tar -czvf nitro.tar.gz nitro
- name: Upload Artifact
uses: actions/upload-artifact@v2
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
with:
name: nitro-mac-amd64
path: ./nitro
- name: Run e2e testing
shell: bash
run: |
# run e2e testing
cd nitro
chmod +x ../.github/scripts/e2e-test-linux-and-mac.sh && ../.github/scripts/e2e-test-linux-and-mac.sh ./nitro ${{ env.MODEL_URL }}
- uses: actions/[email protected]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
asset_path: ./nitro.tar.gz
asset_name: nitro-${{ needs.create-draft-release.outputs.version }}-mac-amd64.tar.gz
asset_content_type: application/gzip
windows-amd64-build:
runs-on: windows-latest
needs: [create-draft-release, set-nitro-version]
if: always() && (needs.create-draft-release.result == 'success' || needs.create-draft-release.result == 'skipped') && needs.set-nitro-version.result == 'success'
permissions:
contents: write
steps:
- name: Clone
id: checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup VSWhere.exe
uses: warrenbuckley/Setup-VSWhere@v1
with:
version: latest
silent: true
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: actions-setup-cmake
uses: jwlawson/[email protected]
- name: Build
id: cmake_build
shell: cmd
run: |
cmake -S ./nitro_deps -B ./build_deps/nitro_deps
cmake --build ./build_deps/nitro_deps --config Release
mkdir -p build
cd build
cmake .. -DLLAMA_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DLLAMA_BLAS=ON -DBUILD_SHARED_LIBS=ON -DNITRO_VERSION=${{ needs.set-nitro-version.outputs.version }}
cmake --build . --config Release -j "%NUMBER_OF_PROCESSORS%"
- name: Pack artifacts
id: pack_artifacts
shell: cmd
run: |
robocopy build_deps\_install\bin\ .\build\Release\ zlib.dll
robocopy build\bin\Release\ .\build\Release\ llama.dll
dotnet tool install --global AzureSignTool
azuresigntool.exe sign -kvu "${{ secrets.AZURE_KEY_VAULT_URI }}" -kvi "${{ secrets.AZURE_CLIENT_ID }}" -kvt "${{ secrets.AZURE_TENANT_ID }}" -kvs "${{ secrets.AZURE_CLIENT_SECRET }}" -kvc ${{ secrets.AZURE_CERT_NAME }} -tr http://timestamp.globalsign.com/tsa/r6advanced1 -v ".\build\Release\nitro.exe"
7z a -ttar temp.tar .\build\Release\*
7z a -tgzip nitro.tar.gz temp.tar
- name: Upload Artifact
uses: actions/upload-artifact@v2
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
with:
name: nitro-win-amd64
path: ./build/Release
# - name: Run e2e testing
# shell: cmd
# run: |
# cd .\build\Release
# ..\..\.github\scripts\e2e-test-windows.bat .\nitro.exe ${{ env.MODEL_URL }}
- uses: actions/[email protected]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
asset_path: ./nitro.tar.gz
asset_name: nitro-${{ needs.create-draft-release.outputs.version }}-win-amd64.tar.gz
asset_content_type: application/gzip
windows-amd64-cuda-build:
runs-on: windows-cuda-${{ matrix.cuda }}
needs: [create-draft-release, set-nitro-version]
if: always() && (needs.create-draft-release.result == 'success' || needs.create-draft-release.result == 'skipped') && needs.set-nitro-version.result == 'success'
permissions:
contents: write
strategy:
matrix:
cuda: ["12-0", "11-7"]
steps:
- name: Setup VSWhere.exe
uses: warrenbuckley/Setup-VSWhere@v1
with:
version: latest
silent: true
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: actions-setup-cmake
uses: jwlawson/[email protected]
- name: Clone
id: checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup VSWhere.exe
uses: warrenbuckley/Setup-VSWhere@v1
with:
version: latest
silent: true
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "6.0.x"
- name: Build
id: cmake_build
shell: cmd
run: |
cmake -S ./nitro_deps -B ./build_deps/nitro_deps
cmake --build ./build_deps/nitro_deps --config Release
mkdir -p build
cd build
cmake .. -DLLAMA_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DLLAMA_CUBLAS=ON -DBUILD_SHARED_LIBS=ON -DNITRO_VERSION=${{ needs.set-nitro-version.outputs.version }}
cmake --build . --config Release -j "%NUMBER_OF_PROCESSORS%"
- name: Pack artifacts
id: pack_artifacts
shell: cmd
run: |
set PATH=%PATH%;C:\Program Files\7-Zip\
robocopy build_deps\_install\bin\ .\build\Release\ zlib.dll
robocopy build\bin\Release\ .\build\Release\ llama.dll
dotnet tool install --global AzureSignTool
%USERPROFILE%\.dotnet\tools\azuresigntool.exe sign -kvu "${{ secrets.AZURE_KEY_VAULT_URI }}" -kvi "${{ secrets.AZURE_CLIENT_ID }}" -kvt "${{ secrets.AZURE_TENANT_ID }}" -kvs "${{ secrets.AZURE_CLIENT_SECRET }}" -kvc ${{ secrets.AZURE_CERT_NAME }} -tr http://timestamp.globalsign.com/tsa/r6advanced1 -v ".\build\Release\nitro.exe"
7z a -ttar temp.tar .\build\Release\*
7z a -tgzip nitro.tar.gz temp.tar
- name: Upload Artifact
uses: actions/upload-artifact@v2
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
with:
name: nitro-win-amd64-cuda-${{ matrix.cuda }}
path: ./build/Release
# - name: run e2e testing
# shell: cmd
# run: |
# cd .\build\Release
# ..\..\.github\scripts\e2e-test-windows.bat .\nitro.exe ${{ env.MODEL_URL }}
- uses: actions/[email protected]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
asset_path: ./nitro.tar.gz
asset_name: nitro-${{ needs.create-draft-release.outputs.version }}-win-amd64-cuda-${{ matrix.cuda }}.tar.gz
asset_content_type: application/gzip
update_release_draft:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
needs:
[
ubuntu-amd64-build,
ubuntu-amd64-cuda-build,
macOS-M-build,
macOS-Intel-build,
windows-amd64-build,
windows-amd64-cuda-build,
]
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
noti-discord-nightly:
if: always() && github.event_name == 'schedule' && (needs.create-draft-release.result == 'success' || needs.create-draft-release.result == 'skipped') && needs.ubuntu-amd64-build.result == 'success' && needs.ubuntu-amd64-cuda-build.result == 'success' && needs.macOS-M-build.result == 'success' && needs.macOS-Intel-build.result == 'success' && needs.windows-amd64-build.result == 'success' && needs.windows-amd64-cuda-build.result == 'success'
needs:
[
create-draft-release,
ubuntu-amd64-build,
ubuntu-amd64-cuda-build,
macOS-M-build,
macOS-Intel-build,
windows-amd64-build,
windows-amd64-cuda-build,
]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: "0"
token: ${{ secrets.PAT_SERVICE_ACCOUNT }}
- name: Notify Discord
uses: Ilshidur/action-discord@master
with:
args: "Nightly build artifact: https://github.com/janhq/nitro/actions/runs/{{ GITHUB_RUN_ID }}"
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
- name: Update README.md with artifact URL
run: |
sed -i "s|<a href='https://github.com/janhq/nitro/actions/runs/.*'>|<a href='https://github.com/janhq/nitro/actions/runs/${GITHUB_RUN_ID}'>|" README.md
git config --global user.email "[email protected]"
git config --global user.name "Service Account"
git add README.md
git commit -m "${GITHUB_REPOSITORY}: Update README.md with nightly build artifact URL"
git -c http.extraheader="AUTHORIZATION: bearer ${{ secrets.PAT_SERVICE_ACCOUNT }}" push origin HEAD:main
env:
GITHUB_RUN_ID: ${{ github.run_id }}
noti-discord-manual:
if: always() && github.event_name == 'workflow_dispatch' && (needs.create-draft-release.result == 'success' || needs.create-draft-release.result == 'skipped') && needs.ubuntu-amd64-build.result == 'success' && needs.ubuntu-amd64-cuda-build.result == 'success' && needs.macOS-M-build.result == 'success' && needs.macOS-Intel-build.result == 'success' && needs.windows-amd64-build.result == 'success' && needs.windows-amd64-cuda-build.result == 'success'
needs:
[
create-draft-release,
ubuntu-amd64-build,
ubuntu-amd64-cuda-build,
macOS-M-build,
macOS-Intel-build,
windows-amd64-build,
windows-amd64-cuda-build,
]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: "0"
token: ${{ secrets.PAT_SERVICE_ACCOUNT }}
- name: Notify Discord
uses: Ilshidur/action-discord@master
with:
args: "Manual build artifact: https://github.com/janhq/nitro/actions/runs/{{ GITHUB_RUN_ID }}"
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
# Update README.md with artifact URL if manual build from main branch
- name: Update README.md with artifact URL
if: github.ref == 'refs/heads/main'
run: |
sed -i "s|<a href='https://github.com/janhq/nitro/actions/runs/.*'>|<a href='https://github.com/janhq/nitro/actions/runs/${GITHUB_RUN_ID}'>|" README.md
git config --global user.email "[email protected]"
git config --global user.name "Service Account"
git add README.md
git commit -m "${GITHUB_REPOSITORY}: Update README.md with nightly build artifact URL"
git -c http.extraheader="AUTHORIZATION: bearer ${{ secrets.PAT_SERVICE_ACCOUNT }}" push origin HEAD:main
env:
GITHUB_RUN_ID: ${{ github.run_id }}