Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit eb151fc

Browse files
authored
Add nightly build for cortex to pull latest nightly of cortex.llamacpp (#698)
Co-authored-by: Hien To <tominhhien97@gmail.com>
1 parent 480f1a0 commit eb151fc

File tree

2 files changed

+396
-0
lines changed

2 files changed

+396
-0
lines changed
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
name: CI Cortex CPP
2+
3+
on:
4+
push:
5+
tags: ["v[0-9]+.[0-9]+.[0-9]+-[0-9]+.[0-9]+.[0-9]+"]
6+
paths:
7+
[
8+
"cortex-cpp/**",
9+
]
10+
workflow_dispatch:
11+
12+
env:
13+
LLM_MODEL_URL: https://delta.jan.ai/tinyllama-1.1b-chat-v0.3.Q2_K.gguf
14+
EMBEDDING_MODEL_URL: https://catalog.jan.ai/dist/models/embeds/nomic-embed-text-v1.5.f16.gguf
15+
16+
jobs:
17+
create-draft-release:
18+
runs-on: ubuntu-latest
19+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
20+
outputs:
21+
upload_url: ${{ steps.create_release.outputs.upload_url }}
22+
version: ${{ steps.get_version.outputs.version }}
23+
permissions:
24+
contents: write
25+
steps:
26+
- name: Extract tag name without v prefix
27+
id: get_version
28+
run: |
29+
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV && echo "::set-output name=version::${GITHUB_REF#refs/tags/v}"
30+
env:
31+
GITHUB_REF: ${{ github.ref }}
32+
- name: Create Draft Release
33+
id: create_release
34+
uses: softprops/action-gh-release@v2
35+
with:
36+
tag_name: ${{ github.ref_name }}
37+
token: ${{ secrets.GITHUB_TOKEN }}
38+
name: "${{ env.VERSION }}"
39+
draft: false
40+
generate_release_notes: true
41+
prerelease: true
42+
43+
build-and-test:
44+
runs-on: ${{ matrix.runs-on }}
45+
needs: [create-draft-release]
46+
timeout-minutes: 40
47+
strategy:
48+
fail-fast: false
49+
matrix:
50+
include:
51+
- os: "linux"
52+
name: "amd64-avx2"
53+
runs-on: "ubuntu-18-04"
54+
cmake-flags: "-DLLAMA_AVX2=ON -DLLAMA_NATIVE=OFF"
55+
run-e2e: true
56+
57+
- os: "linux"
58+
name: "amd64-avx"
59+
runs-on: "ubuntu-18-04"
60+
cmake-flags: "-DLLAMA_AVX2=OFF -DLLAMA_NATIVE=OFF"
61+
run-e2e: false
62+
63+
- os: "linux"
64+
name: "amd64-avx512"
65+
runs-on: "ubuntu-18-04"
66+
cmake-flags: "-DLLAMA_AVX512=ON -DLLAMA_NATIVE=OFF"
67+
run-e2e: false
68+
69+
- os: "linux"
70+
name: "amd64-vulkan"
71+
runs-on: "ubuntu-18-04-cuda-11-7"
72+
cmake-flags: "-DLLAMA_VULKAN=ON -DLLAMA_NATIVE=OFF"
73+
run-e2e: false
74+
75+
- os: "linux"
76+
name: "amd64-cuda-11-7"
77+
runs-on: "ubuntu-18-04-cuda-11-7"
78+
cmake-flags: "-DCUDA_11_7=ON -DLLAMA_NATIVE=OFF -DLLAMA_CUDA=ON"
79+
run-e2e: false
80+
81+
- os: "linux"
82+
name: "amd64-cuda-12-0"
83+
runs-on: "ubuntu-18-04-cuda-12-0"
84+
cmake-flags: "-DCUDA_12_0=ON -DLLAMA_NATIVE=OFF -DLLAMA_CUDA=ON"
85+
run-e2e: false
86+
87+
- os: "mac"
88+
name: "amd64"
89+
runs-on: "macos-13"
90+
cmake-flags: ""
91+
run-e2e: true
92+
93+
- os: "mac"
94+
name: "arm64"
95+
runs-on: "macos-latest"
96+
cmake-flags: "-DMAC_ARM64=ON"
97+
run-e2e: false
98+
99+
- os: "windows"
100+
name: "amd64-avx2"
101+
runs-on: "windows-cuda-12-0"
102+
cmake-flags: "-DLLAMA_AVX2=ON -DLLAMA_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DLLAMA_BLAS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE"
103+
run-e2e: true
104+
105+
- os: "windows"
106+
name: "amd64-avx"
107+
runs-on: "windows-cuda-12-0"
108+
cmake-flags: "-DLLAMA_AVX2=OFF -DLLAMA_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DLLAMA_BLAS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE"
109+
run-e2e: false
110+
111+
- os: "windows"
112+
name: "amd64-avx512"
113+
runs-on: "windows-cuda-12-0"
114+
cmake-flags: "-DLLAMA_AVX512=ON -DLLAMA_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DLLAMA_BLAS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE"
115+
run-e2e: false
116+
117+
- os: "windows"
118+
name: "amd64-vulkan"
119+
runs-on: "windows-cuda-12-0"
120+
cmake-flags: "-DLLAMA_VULKAN=ON -DLLAMA_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE"
121+
run-e2e: false
122+
123+
- os: "windows"
124+
name: "amd64-avx2-cuda-12-0"
125+
runs-on: "windows-cuda-12-0"
126+
cmake-flags: "-DLLAMA_AVX2=ON -DLLAMA_NATIVE=OFF -DCUDA_12_0=ON -DLLAMA_BUILD_SERVER=ON -DLLAMA_CUDA=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE"
127+
run-e2e: false
128+
129+
- os: "windows"
130+
name: "amd64-avx-cuda-12-0"
131+
runs-on: "windows-cuda-12-0"
132+
cmake-flags: "-DLLAMA_AVX2=OFF -DLLAMA_NATIVE=OFF -DCUDA_12_0=ON -DLLAMA_BUILD_SERVER=ON -DLLAMA_CUDA=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE"
133+
run-e2e: false
134+
135+
- os: "windows"
136+
name: "amd64-avx512-cuda-12-0"
137+
runs-on: "windows-cuda-12-0"
138+
cmake-flags: "-DLLAMA_AVX512=ON -DLLAMA_NATIVE=OFF -DCUDA_12_0=ON -DLLAMA_BUILD_SERVER=ON -DLLAMA_CUDA=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE"
139+
run-e2e: false
140+
141+
- os: "windows"
142+
name: "amd64-avx2-cuda-11-7"
143+
runs-on: "windows-cuda-11-7"
144+
cmake-flags: "-DLLAMA_AVX2=ON -DLLAMA_NATIVE=OFF -DCUDA_11_7=ON -DLLAMA_BUILD_SERVER=ON -DLLAMA_CUDA=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE"
145+
run-e2e: false
146+
147+
- os: "windows"
148+
name: "amd64-avx-cuda-11-7"
149+
runs-on: "windows-cuda-11-7"
150+
cmake-flags: "-DLLAMA_AVX2=OFF -DLLAMA_NATIVE=OFF -DCUDA_11_7=ON -DLLAMA_BUILD_SERVER=ON -DLLAMA_CUDA=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE"
151+
run-e2e: false
152+
- os: "windows"
153+
name: "amd64-avx512-cuda-11-7"
154+
runs-on: "windows-cuda-11-7"
155+
cmake-flags: "-DLLAMA_AVX512=ON -DLLAMA_NATIVE=OFF -DCUDA_11_7=ON -DLLAMA_BUILD_SERVER=ON -DLLAMA_CUDA=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE"
156+
run-e2e: false
157+
158+
steps:
159+
- name: Clone
160+
id: checkout
161+
uses: actions/checkout@v3
162+
with:
163+
submodules: recursive
164+
165+
- uses: actions/setup-dotnet@v3
166+
if: runner.os == 'Windows'
167+
with:
168+
dotnet-version: "8.0.x"
169+
170+
- name: Install choco on Windows
171+
if: runner.os == 'Windows'
172+
run: |
173+
choco install make -y
174+
175+
- name: Get Cer for code signing
176+
if: runner.os == 'macOS'
177+
run: base64 -d <<< "$CODE_SIGN_P12_BASE64" > /tmp/codesign.p12
178+
shell: bash
179+
env:
180+
CODE_SIGN_P12_BASE64: ${{ secrets.CODE_SIGN_P12_BASE64 }}
181+
182+
- uses: apple-actions/import-codesign-certs@v2
183+
if: runner.os == 'macOS'
184+
with:
185+
p12-file-base64: ${{ secrets.CODE_SIGN_P12_BASE64 }}
186+
p12-password: ${{ secrets.CODE_SIGN_P12_PASSWORD }}
187+
188+
- name: Build
189+
run: |
190+
cd cortex-cpp
191+
make build CMAKE_EXTRA_FLAGS="${{ matrix.cmake-flags }}"
192+
193+
- name: Pre-package
194+
run: |
195+
cd cortex-cpp
196+
make pre-package
197+
198+
- name: Code Signing macOS
199+
if: runner.os == 'macOS'
200+
run: |
201+
cd cortex-cpp
202+
make codesign CODE_SIGN=true DEVELOPER_ID="${{ secrets.DEVELOPER_ID }}"
203+
204+
- name: Code Signing Windows
205+
if: runner.os == 'Windows'
206+
shell: cmd
207+
run: |
208+
cd cortex-cpp
209+
set PATH=%PATH%;%USERPROFILE%\.dotnet\tools
210+
make codesign CODE_SIGN=true AZURE_KEY_VAULT_URI="${{ secrets.AZURE_KEY_VAULT_URI }}" AZURE_CLIENT_ID="${{ secrets.AZURE_CLIENT_ID }}" AZURE_TENANT_ID="${{ secrets.AZURE_TENANT_ID }}" AZURE_CLIENT_SECRET="${{ secrets.AZURE_CLIENT_SECRET }}" AZURE_CERT_NAME="${{ secrets.AZURE_CERT_NAME }}"
211+
212+
213+
- name: Package
214+
run: |
215+
cd cortex-cpp
216+
make package
217+
218+
- name: Run e2e testing
219+
if: ${{ matrix.run-e2e }}
220+
run: |
221+
cd cortex-cpp
222+
make run-e2e-test RUN_TESTS=true LLM_MODEL_URL=${{ env.LLM_MODEL_URL }} EMBEDDING_MODEL_URL=${{ env.EMBEDDING_MODEL_URL }}
223+
224+
- name: Upload Artifact
225+
uses: actions/upload-artifact@v2
226+
with:
227+
name: cortex-cpp-${{ matrix.os }}-${{ matrix.name }}
228+
path: ./cortex-cpp/cortex-cpp
229+
230+
- uses: actions/upload-release-asset@v1.0.1
231+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
232+
env:
233+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
234+
with:
235+
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
236+
asset_path: ./cortex-cpp/cortex-cpp.tar.gz
237+
asset_name: cortex-cpp-${{ needs.create-draft-release.outputs.version }}-${{ matrix.os }}-${{ matrix.name }}.tar.gz
238+
asset_content_type: application/gzip

.github/workflows/nightly.yml

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
name: Nightly Update cortex.llamacpp
2+
3+
on:
4+
schedule:
5+
- cron: '30 18 * * 1-5' # At 01:30 on every day-of-week from Monday through Friday UTC +7
6+
workflow_dispatch:
7+
8+
jobs:
9+
update-submodule:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
actions: write
15+
16+
outputs:
17+
pr_number: ${{ steps.check-update.outputs.pr_number }}
18+
pr_created: ${{ steps.check-update.outputs.pr_created }}
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v3
23+
with:
24+
submodules: recursive
25+
ref: dev
26+
fetch-depth: 0
27+
token: ${{ secrets.PAT_SERVICE_ACCOUNT }}
28+
29+
- name: Configure Git
30+
run: |
31+
git config --global user.name 'github-actions[bot]'
32+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
33+
34+
- name: Update submodule to latest release
35+
id: check-update
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
38+
run: |
39+
cd cortex-cpp
40+
latest_prerelease_name=$(curl -s https://api.github.com/repos/janhq/cortex.llamacpp/releases | jq -r '.[] | select(.prerelease) | .name' | head -n 1)
41+
42+
engine_cmake_path="engines/cortex.llamacpp/engine.cmake"
43+
current_version=$(grep -oP 'set\(VERSION \K[^\)]+' "$engine_cmake_path")
44+
45+
if [ "$current_version" = "$latest_prerelease_name" ]; then
46+
echo "cortex.llamacpp remote repo doesn't have update today, skip nightly build"
47+
echo "::set-output name=pr_created::false"
48+
exit 0
49+
fi
50+
sed -i "s/set(VERSION $current_version)/set(VERSION $latest_prerelease_name)/" "$engine_cmake_path"
51+
echo "Updated version from $current_version to $latest_prerelease_name."
52+
echo "::set-output name=pr_created::true"
53+
cd -
54+
git add $engine_cmake_path
55+
git commit -m "Update cortex.llamacpp nightly to version $latest_prerelease_name"
56+
branch_name="update-nightly-$(date +'%Y-%m-%d-%H-%M')"
57+
git checkout -b $branch_name
58+
git push origin $branch_name
59+
60+
pr_title="Update cortex.llamacpp nightly to version $latest_prerelease_name"
61+
pr_body="This PR updates the Update cortex.llamacpp nightly to version $latest_prerelease_name"
62+
63+
gh pr create --title "$pr_title" --body "$pr_body" --head $branch_name --base dev --reviewer vansangpfiev
64+
65+
pr_number=$(gh pr list --head $branch_name --json number --jq '.[0].number')
66+
echo "::set-output name=pr_number::$pr_number"
67+
68+
check-and-merge-pr:
69+
needs: update-submodule
70+
if: needs.update-submodule.outputs.pr_created == 'true'
71+
runs-on: ubuntu-latest
72+
permissions:
73+
contents: write
74+
pull-requests: write
75+
76+
steps:
77+
- name: Checkout repository
78+
uses: actions/checkout@v3
79+
with:
80+
submodules: recursive
81+
fetch-depth: 0
82+
token: ${{ secrets.PAT_SERVICE_ACCOUNT }}
83+
84+
- name: Wait for CI to pass
85+
env:
86+
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
87+
run: |
88+
pr_number=${{ needs.update-submodule.outputs.pr_number }}
89+
while true; do
90+
ci_completed=$(gh pr checks $pr_number --json completedAt --jq '.[].completedAt')
91+
if echo "$ci_completed" | grep -q "0001-01-01T00:00:00Z"; then
92+
echo "CI is still running, waiting..."
93+
sleep 60
94+
else
95+
echo "CI has completed, checking states..."
96+
ci_states=$(gh pr checks $pr_number --json state --jq '.[].state')
97+
if echo "$ci_states" | grep -vqE "SUCCESS|SKIPPED"; then
98+
echo "CI failed, exiting..."
99+
exit 1
100+
else
101+
echo "CI passed, merging PR..."
102+
break
103+
fi
104+
fi
105+
done
106+
107+
- name: Merge the PR
108+
env:
109+
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
110+
run: |
111+
pr_number=${{ needs.update-submodule.outputs.pr_number }}
112+
gh pr merge $pr_number --merge --admin
113+
114+
create-tag:
115+
needs: [update-submodule, check-and-merge-pr]
116+
if: needs.update-submodule.outputs.pr_created == 'true'
117+
runs-on: ubuntu-latest
118+
steps:
119+
- name: Checkout repository
120+
uses: actions/checkout@v3
121+
with:
122+
submodules: recursive
123+
ref: dev
124+
fetch-depth: 0
125+
token: ${{ secrets.PAT_SERVICE_ACCOUNT }}
126+
127+
- name: Configure Git
128+
run: |
129+
git config --global user.name 'github-actions[bot]'
130+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
131+
132+
- name: Create and push a new tag
133+
run: |
134+
# Function to get the latest release tag
135+
get_latest_tag() {
136+
local retries=0
137+
local max_retries=3
138+
local tag
139+
while [ $retries -lt $max_retries ]; do
140+
tag=$(curl -s https://api.github.com/repos/janhq/cortex/releases/latest | jq -r .tag_name)
141+
if [ -n "$tag" ] && [ "$tag" != "null" ]; then
142+
echo $tag
143+
return
144+
else
145+
let retries++
146+
echo "Retrying... ($retries/$max_retries)"
147+
sleep 2
148+
fi
149+
done
150+
echo "Failed to fetch latest tag after $max_retries attempts."
151+
exit 1
152+
}
153+
154+
LATEST_TAG=$(get_latest_tag)
155+
date_suffix=$(date +'%d.%m.%y')
156+
new_tag="${LATEST_TAG}-${date_suffix}"
157+
git tag $new_tag
158+
git push origin $new_tag

0 commit comments

Comments
 (0)