-
-
Notifications
You must be signed in to change notification settings - Fork 93
838 lines (748 loc) · 28.5 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
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
name: Build
on:
push:
branches:
- master
- beta
pull_request:
workflow_dispatch:
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install modules
run: npm ci
- name: Build
run: npm run build
- name: Download latest llama.cpp release
env:
CI: true
run: node ./dist/cli/cli.js source download --release latest --skipBuild --noBundle --noUsageExample --updateBinariesReleaseMetadataAndSaveGitBundle
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: "build"
path: "dist"
- name: Upload packed templates artifact
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: "build-templates"
path: "templates/packed"
- name: Upload llama.cpp artifact
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: "llama.cpp"
path: |
llama/binariesGithubRelease.json
llama/llama.cpp.info.json
llama/llama.cpp
llama/gitRelease.bundle
build-binaries:
name: Build binaries - ${{ matrix.config.name }}
needs:
- build
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- name: "Windows for x64"
os: windows-2019
artifact: "win-x64"
- name: "Windows for Arm"
os: windows-2022
artifact: "win-arm"
- name: "Ubuntu"
os: ubuntu-22.04
artifact: "linux"
- name: "macOS"
os: macos-13
artifact: "mac"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build
path: dist
- name: Download llama.cpp artifact
uses: actions/download-artifact@v4
with:
name: llama.cpp
path: llama
- name: Install dependencies on Windows
if: startsWith(matrix.config.os, 'windows')
run: |
choco install ninja cmake
- name: Install dependencies on Ubuntu
if: matrix.config.name == 'Ubuntu'
run: |
sudo apt-get update
sudo apt-get install ninja-build cmake libtbb-dev g++-aarch64-linux-gnu gcc-aarch64-linux-gnu g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf
which aarch64-linux-gnu-gcc
which aarch64-linux-gnu-g++
which arm-linux-gnueabihf-gcc
which arm-linux-gnueabihf-g++
- name: Install Cuda on Windows for x64
if: matrix.config.name == 'Windows for x64'
uses: Jimver/cuda-toolkit@v0.2.15
with:
cuda: '12.2.0'
method: 'network'
sub-packages: '["nvcc", "cudart", "cublas", "cublas_dev", "thrust", "visual_studio_integration"]'
use-local-cache: false
- name: Install Cuda on Ubuntu
if: matrix.config.name == 'Ubuntu'
uses: Jimver/cuda-toolkit@v0.2.15
with:
cuda: '12.2.0'
method: 'network'
- name: Install Vulkan SDK on Windows for x64
if: matrix.config.name == 'Windows for x64'
shell: powershell
env:
VULKAN_VERSION: 1.3.261.1
run: |
curl.exe -o $env:RUNNER_TEMP/VulkanSDK-Installer.exe -L "https://sdk.lunarg.com/sdk/download/${env:VULKAN_VERSION}/windows/VulkanSDK-${env:VULKAN_VERSION}-Installer.exe"
& "$env:RUNNER_TEMP\VulkanSDK-Installer.exe" --accept-licenses --default-answer --confirm-command install
Add-Content $env:GITHUB_ENV "VULKAN_SDK=C:\VulkanSDK\${env:VULKAN_VERSION}"
Add-Content $env:GITHUB_PATH "C:\VulkanSDK\${env:VULKAN_VERSION}\bin"
- name: Install Vulkan SDK on Ubuntu
if: matrix.config.name == 'Ubuntu'
run: |
wget -qO- https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo tee /etc/apt/trusted.gpg.d/lunarg.asc
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list https://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list
sudo apt update
sudo apt install vulkan-sdk
- name: Install dependencies on macOS
if: matrix.config.name == 'macOS'
run: |
brew install cmake ninja
alias make=cmake
- name: Setup & Build
id: build
shell: bash
timeout-minutes: 200
env:
ARTIFACT_NAME: ${{ matrix.config.artifact }}
run: |
npm ci
npx zx -y <<'EOF'
async function getLatestNodeVersions(maxDate) {
const res = await fetch("https://nodejs.org/dist/index.json");
const data = await res.json();
const versions = new Map();
let latestVersion = null;
for (const version of data) {
const majorVersion = Number(version.version.split(".")[0].slice("v".length));
const versionDate = new Date(version.date);
if (maxDate != null && versionDate.getTime() > maxDate)
continue;
if (!versions.has(majorVersion)) {
versions.set(majorVersion, version.version);
}
if (latestVersion === null || majorVersion > latestVersion) {
latestVersion = majorVersion;
}
}
return {versions, latestVersion};
}
const {versions: latestNodeVersions} = await getLatestNodeVersions(Date.now() - 1000 * 60 * 60 * 24 * 14);
const nodeVersion = latestNodeVersions.get(18);
const windowsOnArmNodeVersion = latestNodeVersions.get(20);
if (nodeVersion == null || windowsOnArmNodeVersion == null) {
throw new Error("Could not find node versions");
}
$.verbose = true;
await $`mkdir -p bins`;
async function buildBinary(arch, flags = [], nodeTarget = nodeVersion) {
console.log(`Building ${arch} for node ${nodeTarget} with flags`, flags);
await $`node ./dist/cli/cli.js source build --ciMode --noUsageExample --arch ${arch} --nodeTarget ${nodeVersion} ${flags}`;
}
// build binaries
if (process.env.ARTIFACT_NAME === "win-x64") {
await buildBinary("x64", ["--gpu", "false"]);
await buildBinary("x64", ["--gpu", "cuda"]);
await buildBinary("x64", ["--gpu", "vulkan"]);
} else if (process.env.ARTIFACT_NAME === "win-arm") {
await buildBinary("arm64", ["--gpu", "false"], windowsOnArmNodeVersion);
} else if (process.env.ARTIFACT_NAME === "linux") {
await buildBinary("x64", ["--gpu", "false"]);
await buildBinary("x64", ["--gpu", "cuda"]);
await buildBinary("x64", ["--gpu", "vulkan"]);
await buildBinary("arm64", ["--gpu", "false"]);
await buildBinary("armv7l", ["--gpu", "false"]);
} else if (process.env.ARTIFACT_NAME === "mac") {
await buildBinary("arm64", ["--gpu", "metal"]);
await buildBinary("x64", ["--gpu", "false"]);
}
// move binaries to bins
const localBuildsDirectoryPath = path.join(process.cwd(), "llama", "localBuilds");
const llamaBinsDirectoryPath = path.join(process.cwd(), "bins");
for (const folderName of await fs.readdir(localBuildsDirectoryPath)) {
await fs.move(
path.join(localBuildsDirectoryPath, folderName, "Release"),
path.join(llamaBinsDirectoryPath, folderName)
);
}
await $`echo "Built binaries:"`;
await $`ls bins`;
EOF
# - name: Cache UPX
# id: cache-upx
# uses: actions/cache@v4
# with:
# path: "upxInstallations/**"
# key: cache-upx-${{ runner.os }}-${{ github.workflow }}
# - name: Compress CUDA binary on Windows
# if: matrix.config.name == 'Windows for x64'
# shell: bash
# env:
# UPX_VERSION: 4.2.4
# run: |
# mkdir -p upxInstallations
#
# if [ ! -f "./upxInstallations/upx-${UPX_VERSION}-win64.zip" ]; then
# pushd upxInstallations
# curl -OL "https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-win64.zip"
# popd
# fi
#
# mkdir -p upx
# unzip -d ./upx "./upxInstallations/upx-${UPX_VERSION}-win64.zip"
# mv "./upx/upx-${UPX_VERSION}-win64" ./upx/upx
#
# ./upx/upx/upx.exe --best ./bins/win-x64-cuda/Release/ggml.dll
# - name: Compress CUDA binary on Ubuntu
# if: matrix.config.name == 'Ubuntu'
# env:
# UPX_VERSION: 4.2.4
# run: |
# mkdir -p upxInstallations
#
# if [ ! -f "./upxInstallations/upx-${UPX_VERSION}-amd64_linux.tar.xz" ]; then
# pushd upxInstallations
# curl -OL "https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-amd64_linux.tar.xz"
# popd
# fi
#
# mkdir -p upx
# tar -xvf "./upxInstallations/upx-${UPX_VERSION}-amd64_linux.tar.xz" -C ./upx
# mv "./upx/upx-${UPX_VERSION}-amd64_linux" ./upx/upx
#
# chmod +x ./bins/linux-x64-cuda/llama-addon.node
# ./upx/upx/upx --best ./bins/linux-x64-cuda/libggml.so
# chmod -x ./bins/linux-x64-cuda/llama-addon.node
- name: Publish artifact
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: "bins-${{ matrix.config.artifact }}"
path: "bins/*"
resolve-next-release:
name: Resolve next release
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/beta')
runs-on: ubuntu-latest
needs:
- build
permissions:
pages: read
id-token: write
contents: read
issues: read
pull-requests: read
discussions: read
outputs:
next-version: ${{ steps.save-next-version.outputs.next-version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install modules
run: npm ci
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build
path: dist
- name: Download llama.cpp artifact
uses: actions/download-artifact@v4
with:
name: llama.cpp
path: llama
- name: Apply fix patch on semantic-release, to not check for push permission on dry run
run: |
git apply --ignore-whitespace ./scripts/patches/semantic-release+24.1.1.patch
git apply --ignore-whitespace ./scripts/patches/@semantic-release+npm+12.0.1.patch
- name: Resolve next release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx --no vite-node ./scripts/resolveNextReleaseVersion.ts --saveReleaseToFile ./semanticReleaseDryRunReleaseResult.json --saveVersionToFile ./resolvedNextVersion.txt
- name: Save next version output
id: save-next-version
run: echo "next-version=$(cat ./resolvedNextVersion.txt)" >> $GITHUB_OUTPUT
- name: Update job summary
run: |
if [ "$(cat ./resolvedNextVersion.txt)" == "false" ]; then
echo "Next release version: \`N/A\`" >> $GITHUB_STEP_SUMMARY
else
echo "Next release version: \`$(cat ./resolvedNextVersion.txt)\`" >> $GITHUB_STEP_SUMMARY
fi
- name: Upload resolved release artifact
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: "resolved-next-release"
path: "./semanticReleaseDryRunReleaseResult.json"
standalone-tests:
name: Standalone tests
runs-on: ubuntu-22.04
needs:
- build
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build
path: dist
- name: Download llama.cpp artifact
uses: actions/download-artifact@v4
with:
name: llama.cpp
path: llama
- name: Install dependencies on ubuntu
run: |
sudo apt-get update
sudo apt-get install ninja-build cmake
- name: Install modules
run: npm ci
- name: Build binary
run: node ./dist/cli/cli.js source build --noUsageExample
- name: Run standalone tests
run: npm run test:standalone
model-dependent-tests:
name: Model dependent tests
runs-on: macos-13
env:
NODE_LLAMA_CPP_GPU: false
needs:
- build
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build
path: dist
- name: Download llama.cpp artifact
uses: actions/download-artifact@v4
with:
name: llama.cpp
path: llama
- name: Install dependencies on macOS
run: |
brew install cmake ninja
alias make=cmake
- name: Install modules
run: npm ci
- name: Build binary
run: node ./dist/cli/cli.js source build --noUsageExample
- name: Cache models
id: cache-test-models
uses: actions/cache@v4
with:
path: "test/.models/**.gguf"
key: cache-test-models-${{ runner.os }}-${{ github.workflow }}
- name: Download models or ensure all models are downloaded
run: npm run dev:setup:downloadAllTestModels
- name: Run model dependent tests
run: npm run test:modelDependent
release:
name: Release
if: needs.resolve-next-release.outputs.next-version != '' && needs.resolve-next-release.outputs.next-version != 'false'
runs-on: ubuntu-latest
concurrency: release-${{ github.ref }}
environment:
name: npm
url: ${{ steps.set-npm-url.outputs.npm-url }}
permissions:
id-token: write
contents: write
issues: write
pull-requests: write
discussions: write
needs:
- resolve-next-release
- build
- build-binaries
outputs:
package-version: ${{ steps.set-package-version.outputs.package-version }}
steps:
- uses: actions/checkout@v4
with:
lfs: true
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install modules
run: npm ci
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: Move artifacts
run: |
mkdir -p bins
mv artifacts/bins-*/* bins/
mv artifacts/build dist/
cp -r artifacts/llama.cpp/llama.cpp/grammars llama/grammars
rm -f ./llama/binariesGithubRelease.json
mv artifacts/llama.cpp/binariesGithubRelease.json ./llama/binariesGithubRelease.json
rm -f ./llama/llama.cpp.info.json
mv artifacts/llama.cpp/llama.cpp.info.json ./llama/llama.cpp.info.json
rm -f ./llama/gitRelease.bundle
mv artifacts/llama.cpp/gitRelease.bundle ./llama/gitRelease.bundle
mv artifacts/build-templates templates/packed/
rm -f ./templates/package.json
rm -f ./templates/package-lock.json
echo "Built binaries:"
ls bins
- name: Move binaries to standalone prebuilt binary modules
run: npx --no vite-node ./scripts/movePrebuiltBinariesToStandaloneModules.ts
- name: Prepare standalone prebuilt binary modules
run: npx --no vite-node ./scripts/prepareStandalonePrebuiltBinaryModules.ts
- name: Add "postinstall" script to package.json
run: npm run addPostinstallScript
- name: Move semanticReleaseDryRunReleaseResult.json artifact
run: mv artifacts/resolved-next-release/semanticReleaseDryRunReleaseResult.json ./semanticReleaseDryRunReleaseResult.json
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GH_RELEASE_REF: ${{ github.ref }}
run: |
echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > ~/.npmrc
export DRY_RUN_RESULT_FILE_PATH="$(pwd)/semanticReleaseDryRunReleaseResult.json"
git apply --ignore-whitespace ./scripts/patches/@semantic-release+github+11.0.0.patch
npx semantic-release
- name: Set npm package url to GITHUB_OUTPUT
id: set-npm-url
run: |
if [ -f .semanticRelease.npmPackage.deployedVersion.txt ]; then
echo "npm-url=https://www.npmjs.com/package/node-llama-cpp/v/$(cat .semanticRelease.npmPackage.deployedVersion.txt)" >> $GITHUB_OUTPUT
fi
- name: Set package version to GITHUB_OUTPUT
id: set-package-version
run: |
if [ -f .semanticRelease.npmPackage.deployedVersion.txt ]; then
echo "package-version=$(cat .semanticRelease.npmPackage.deployedVersion.txt)" >> $GITHUB_OUTPUT
fi
- name: Prepare `create-node-llama-cpp` module
if: steps.set-npm-url.outputs.npm-url != ''
run: |
export DEPLOYED_PACKAGE_VERSION=$(cat .semanticRelease.npmPackage.deployedVersion.txt)
pushd packages/create-node-llama-cpp
npm ci --ignore-scripts
popd
npx --no vite-node ./scripts/prepareCreateNodeLlamaCppModuleForPublish.ts --packageVersion "$DEPLOYED_PACKAGE_VERSION"
pushd packages/create-node-llama-cpp
npm run build
- name: Release `create-node-llama-cpp` module
if: steps.set-npm-url.outputs.npm-url != ''
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GH_RELEASE_REF: ${{ github.ref }}
run: |
cd packages/create-node-llama-cpp
echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > ~/.npmrc
if [ "$GH_RELEASE_REF" == "refs/heads/beta" ]; then
npm publish --tag beta
else
npm publish
fi
auto-approve-documentation-website-deployment:
name: Auto-approve documentation website deployment
runs-on: ubuntu-latest
continue-on-error: true
needs:
- release
steps:
- name: Approve documentation website deployment
uses: activescott/automate-environment-deployment-approval@v1.0.6
with:
github_token: ${{ secrets.AUTO_APPROVAL_GITHUB_TOKEN }}
environment_allow_list: "Documentation website"
actor_allow_list: giladgd
build-electron-example:
name: Build & release Electron app example - ${{ matrix.config.name }}
needs:
- release
if: needs.release.outputs.package-version != ''
runs-on: ${{ matrix.config.os }}
permissions:
contents: write
strategy:
fail-fast: false
matrix:
config:
- name: "Windows"
os: windows-2022
- name: "Ubuntu"
os: ubuntu-22.04
- name: "macOS"
os: macos-13
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies on Ubuntu
if: matrix.config.name == 'Ubuntu'
run: |
sudo apt-get update
sudo apt-get install libarchive-tools rpm
sudo snap install snapcraft --classic
- name: Install modules
run: npm ci
- name: Create Electron app project
shell: bash
env:
DEPLOYED_PACKAGE_VERSION: ${{ needs.release.outputs.package-version }}
NODE_LLAMA_CPP_SKIP_DOWNLOAD: true
run: |
npx --no vite-node ./scripts/scaffoldElectronExampleForCiBuild.ts --packageVersion "$DEPLOYED_PACKAGE_VERSION" --packageFolderPath ./electron-app-example
cd electron-app-example
npm install
- name: Build electron app
id: build
shell: bash
timeout-minutes: 480
run: |
cd electron-app-example
npm run build
ls ./release
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: "electron-app-example-${{ matrix.config.name }}"
path: "./electron-app-example/release"
- name: Add builds to current release
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: ${{ needs.release.outputs.package-version }}
run: |
shopt -s nullglob
for file in ./electron-app-example/release/*.{dmg,zip,exe,appx,AppImage,snap,assert,deb,tar.gz}; do
echo "Adding $file to release $RELEASE_TAG"
gh release upload "v$RELEASE_TAG" "$file"
done
shopt -u nullglob
update-documentation-website:
name: Update documentation website
if: |
always() &&
github.event_name == 'push' &&
github.ref == 'refs/heads/master' &&
needs.build.result == 'success' &&
needs.resolve-next-release.result == 'success' &&
needs.resolve-next-release.outputs.next-version != '' &&
needs.resolve-next-release.outputs.next-version != 'false' && (
needs.release.result == 'skipped' || (
needs.release.result == 'success' &&
needs.release.outputs.package-version != ''
)
)
runs-on: ubuntu-latest
concurrency: update-documentation-website-${{ github.ref }}
environment:
name: Documentation website
url: "https://node-llama-cpp.withcat.ai"
permissions:
pages: write
id-token: write
contents: read
needs:
- build
- resolve-next-release
- release
# All steps are copied to `update-documentation-website-no-release` job
# Can be replaced with YAML anchors when this will be supported by GitHub Actions:
# https://github.com/actions/runner/issues/1182#issuecomment-2317953582
steps:
- uses: actions/checkout@v4
with:
lfs: true
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install modules
run: npm ci
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: Move artifacts
run: |
mv artifacts/build dist/
cp -r artifacts/llama.cpp/llama.cpp llama/llama.cpp
rm -f ./llama/binariesGithubRelease.json
mv artifacts/llama.cpp/binariesGithubRelease.json ./llama/binariesGithubRelease.json
rm -f ./llama/llama.cpp.info.json
mv artifacts/llama.cpp/llama.cpp.info.json ./llama/llama.cpp.info.json
- name: Resolve docs version
env:
RELEASE_VERSION: ${{ needs.release.outputs.package-version || needs.resolve-next-release.outputs.next-version }}
run: |
if [ "$RELEASE_VERSION" == "false" ]; then
npx --no vite-node ./scripts/resolveLatestReleaseVersion.ts --saveVersionToFile ./docsVersion.txt
else
echo "$RELEASE_VERSION" > ./docsVersion.txt
fi
- name: Generate docs with updated version
env:
DOCS_URL_BASE: "/"
run: |
export DOCS_PACKAGE_VERSION="$(cat ./docsVersion.txt)"
echo "Package version: $DOCS_PACKAGE_VERSION"
git apply --ignore-whitespace ./scripts/patches/vitepress+1.3.4.patch
npm run docs:build
- name: Upload docs to GitHub Pages
uses: actions/upload-pages-artifact@v3
with:
name: pages-docs
path: docs-site
- name: Deploy docs to GitHub Pages
uses: actions/deploy-pages@v4
with:
artifact_name: pages-docs
- name: Update feed
run: |
curl -X POST "https://pubsubhubbub.appspot.com/" -H "Content-Type: application/x-www-form-urlencoded" --data-urlencode "hub.mode=publish" --data-urlencode "hub.url=https://node-llama-cpp.withcat.ai/blog/feed.atom"
update-documentation-website-no-release:
name: Update documentation website - no version release
if: |
always() &&
github.event_name == 'push' &&
github.ref == 'refs/heads/master' &&
needs.build.result == 'success' &&
needs.resolve-next-release.result == 'success' &&
needs.resolve-next-release.outputs.next-version == 'false'
runs-on: ubuntu-latest
concurrency: update-documentation-website-${{ github.ref }}
environment:
name: Documentation website
url: "https://node-llama-cpp.withcat.ai"
permissions:
pages: write
id-token: write
contents: read
needs:
- build
- resolve-next-release
# All steps are copied to `update-documentation-website` job
# Can be replaced with YAML anchors when this will be supported by GitHub Actions:
# https://github.com/actions/runner/issues/1182#issuecomment-2317953582
steps:
- uses: actions/checkout@v4
with:
lfs: true
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install modules
run: npm ci
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: Move artifacts
run: |
mv artifacts/build dist/
cp -r artifacts/llama.cpp/llama.cpp llama/llama.cpp
rm -f ./llama/binariesGithubRelease.json
mv artifacts/llama.cpp/binariesGithubRelease.json ./llama/binariesGithubRelease.json
rm -f ./llama/llama.cpp.info.json
mv artifacts/llama.cpp/llama.cpp.info.json ./llama/llama.cpp.info.json
- name: Resolve docs version
env:
RELEASE_VERSION: ${{ needs.release.outputs.package-version || needs.resolve-next-release.outputs.next-version }}
run: |
if [ "$RELEASE_VERSION" == "false" ]; then
npx --no vite-node ./scripts/resolveLatestReleaseVersion.ts --saveVersionToFile ./docsVersion.txt
else
echo "$RELEASE_VERSION" > ./docsVersion.txt
fi
- name: Generate docs with updated version
env:
DOCS_URL_BASE: "/"
run: |
export DOCS_PACKAGE_VERSION="$(cat ./docsVersion.txt)"
echo "Package version: $DOCS_PACKAGE_VERSION"
git apply --ignore-whitespace ./scripts/patches/vitepress+1.3.4.patch
npm run docs:build
- name: Upload docs to GitHub Pages
uses: actions/upload-pages-artifact@v3
with:
name: pages-docs
path: docs-site
- name: Deploy docs to GitHub Pages
uses: actions/deploy-pages@v4
with:
artifact_name: pages-docs
- name: Update feed
run: |
curl -X POST "https://pubsubhubbub.appspot.com/" -H "Content-Type: application/x-www-form-urlencoded" --data-urlencode "hub.mode=publish" --data-urlencode "hub.url=https://node-llama-cpp.withcat.ai/blog/feed.atom"
# fix-broken-github-release:
# name: Fix broken GitHub release
# if: github.event_name == 'pull_request' && github.head_ref == 'gilad/smallerLogoFile'
# runs-on: ubuntu-latest
# permissions:
# id-token: write
# actions: read
# contents: write
# issues: write
# pull-requests: write
# discussions: write
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v4
# with:
# node-version: "20"
# - name: Install modules
# run: npm ci
#
# - name: Pull artifact from broken release
# uses: actions/download-artifact@v4
# with:
# name: resolved-next-release
# github-token: ${{ secrets.GITHUB_TOKEN }}
# repository: "${{ github.repository }}"
# run-id: "<run id here>"
# path: scripts/resolved-next-release-artifact
#
# - name: Fix broken release
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: npx --no vite-node ./scripts/rerunSemanticReleaseGithubSuccess.ts