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

Commit 96bc7c7

Browse files
authored
Feat cicd cortex js+ code signing for cortex cpp (#582)
Co-authored-by: Hien To <tominhhien97@gmail.com>
1 parent 6cefe1c commit 96bc7c7

File tree

6 files changed

+127
-31
lines changed

6 files changed

+127
-31
lines changed
Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: CI Cortex CPP
22

33
on:
44
push:
@@ -25,7 +25,8 @@ jobs:
2525
steps:
2626
- name: Extract tag name without v prefix
2727
id: get_version
28-
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV && echo "::set-output name=version::${GITHUB_REF#refs/tags/v}"
28+
run: |
29+
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV && echo "::set-output name=version::${GITHUB_REF#refs/tags/v}"
2930
env:
3031
GITHUB_REF: ${{ github.ref }}
3132
- name: Create Draft Release
@@ -91,7 +92,7 @@ jobs:
9192

9293
- os: "mac"
9394
name: "arm64"
94-
runs-on: "mac-silicon"
95+
runs-on: "macos-latest"
9596
cmake-flags: "-DMAC_ARM64=ON"
9697
run-e2e: true
9798

@@ -161,16 +162,44 @@ jobs:
161162
with:
162163
submodules: recursive
163164

165+
- uses: actions/setup-dotnet@v3
166+
if: runner.os == 'Windows'
167+
with:
168+
dotnet-version: "8.0.x"
169+
164170
- name: Install choco on Windows
165171
if: runner.os == 'Windows'
166172
run: |
167173
choco install make -y
168174
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+
169188
- name: Build
170189
run: |
171190
cd cortex-cpp
172191
make build CMAKE_EXTRA_FLAGS="${{ matrix.cmake-flags }}"
173192
193+
- name: Pre-package
194+
run: |
195+
cd cortex-cpp
196+
make pre-package
197+
198+
- name: Code Signing
199+
run: |
200+
cd cortex-cpp
201+
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 }}" DEVELOPER_ID="${{ secrets.DEVELOPER_ID }}"
202+
174203
- name: Package
175204
run: |
176205
cd cortex-cpp

.github/workflows/quality-gate.yml renamed to .github/workflows/cortex-cpp-quality-gate.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI Quality Gate
1+
name: CI Quality Gate Cortex CPP
22

33
on:
44
pull_request:
@@ -145,6 +145,11 @@ jobs:
145145
cd cortex-cpp
146146
make build CMAKE_EXTRA_FLAGS="${{ matrix.cmake-flags }}"
147147
148+
- name: Pre-package
149+
run: |
150+
cd cortex-cpp
151+
make pre-package
152+
148153
- name: Package
149154
run: |
150155
cd cortex-cpp

.github/workflows/cortex-js.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Publish cortex js Package to npmjs
2+
on:
3+
push:
4+
tags: ["v[0-9]+.[0-9]+.[0-9]+-cortex-js"]
5+
paths:
6+
[
7+
"cortex-js/**",
8+
]
9+
jobs:
10+
build-and-publish-plugins:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: "0"
16+
17+
- name: Install jq
18+
uses: dcarbone/install-jq-action@v2.0.1
19+
20+
- name: "Update version by tag"
21+
run: |
22+
cd cortex-js
23+
# Remove the v prefix
24+
tag_version=${GITHUB_REF#refs/tags/v}
25+
# Remove the -cortex-js suffix
26+
new_version=${tag_version%-cortex-js}
27+
28+
# Replace the old version with the new version in package.json
29+
jq --arg version "$new_version" '.version = $version' ./package.json > /tmp/package.json && mv /tmp/package.json ./package.json
30+
31+
# Print the new version
32+
echo "Updated package.json version to: $new_version"
33+
34+
# Setup .npmrc file to publish to npm
35+
- uses: actions/setup-node@v3
36+
with:
37+
node-version: "20.x"
38+
registry-url: "https://registry.npmjs.org"
39+
- run: yarn install && yarn build
40+
working-directory: ./cortex-js
41+
- run: npm publish --access public
42+
env:
43+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
44+
working-directory: ./cortex-js

cortex-cpp/Makefile

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ CMAKE_EXTRA_FLAGS ?= ""
66
RUN_TESTS ?= false
77
LLM_MODEL_URL ?= "https://delta.jan.ai/tinyllama-1.1b-chat-v0.3.Q2_K.gguf"
88
EMBEDDING_MODEL_URL ?= "https://catalog.jan.ai/dist/models/embeds/nomic-embed-text-v1.5.f16.gguf"
9+
CODE_SIGN ?= false
10+
AZURE_KEY_VAULT_URI ?= xxxx
11+
AZURE_CLIENT_ID ?= xxxx
12+
AZURE_TENANT_ID ?= xxxx
13+
AZURE_CLIENT_SECRET ?= xxxx
14+
AZURE_CERT_NAME ?= xxxx
15+
DEVELOPER_ID ?= xxxx
916

1017
# Default target, does nothing
1118
all:
@@ -29,24 +36,47 @@ else
2936
make -j4;
3037
endif
3138

32-
package:
39+
pre-package:
3340
ifeq ($(OS),Windows_NT)
3441
@powershell -Command "mkdir -p cortex-cpp\engines\cortex.llamacpp\; cp -r build\engines\cortex.llamacpp\engine.dll cortex-cpp\engines\cortex.llamacpp\;"
3542
@powershell -Command "cp -r build\Release\cortex-cpp.exe .\cortex-cpp\;"
3643
@powershell -Command "cp -r build-deps\_install\bin\zlib.dll .\cortex-cpp\;"
3744
@powershell -Command "cp -r ..\.github\patches\windows\msvcp140.dll .\cortex-cpp\;"
3845
@powershell -Command "cp -r ..\.github\patches\windows\vcruntime140_1.dll .\cortex-cpp\;"
3946
@powershell -Command "cp -r ..\.github\patches\windows\vcruntime140.dll .\cortex-cpp\;"
40-
@powershell -Command "7z a -ttar temp.tar cortex-cpp\*; 7z a -tgzip cortex-cpp.tar.gz temp.tar;"
4147
else ifeq ($(shell uname -s),Linux)
4248
@mkdir -p cortex-cpp/engines/cortex.llamacpp; \
4349
cp build/engines/cortex.llamacpp/libengine.so cortex-cpp/engines/cortex.llamacpp/; \
44-
cp build/cortex-cpp cortex-cpp/; \
45-
tar -czvf cortex-cpp.tar.gz cortex-cpp;
50+
cp build/cortex-cpp cortex-cpp/;
4651
else
4752
@mkdir -p cortex-cpp/engines/cortex.llamacpp; \
4853
cp build/engines/cortex.llamacpp/libengine.dylib cortex-cpp/engines/cortex.llamacpp/; \
49-
cp build/cortex-cpp cortex-cpp/; \
54+
cp build/cortex-cpp cortex-cpp/;
55+
endif
56+
57+
codesign:
58+
ifeq ($(CODE_SIGN),false)
59+
@echo "Skipping Code Sign"
60+
@exit 0
61+
endif
62+
63+
ifeq ($(OS),Windows_NT)
64+
@powershell -Command "dotnet tool install --global AzureSignTool;"
65+
@powershell -Command 'azuresigntool.exe sign -kvu "$(AZURE_KEY_VAULT_URI)" -kvi "$(AZURE_CLIENT_ID)" -kvt "$(AZURE_TENANT_ID)" -kvs "$(AZURE_CLIENT_SECRET)" -kvc "$(AZURE_CERT_NAME)" -tr http://timestamp.globalsign.com/tsa/r6advanced1 -v ".\cortex-cpp\cortex-cpp.exe";'
66+
@powershell -Command 'azuresigntool.exe sign -kvu "$(AZURE_KEY_VAULT_URI)" -kvi "$(AZURE_CLIENT_ID)" -kvt "$(AZURE_TENANT_ID)" -kvs "$(AZURE_CLIENT_SECRET)" -kvc "$(AZURE_CERT_NAME)" -tr http://timestamp.globalsign.com/tsa/r6advanced1 -v ".\cortex-cpp\engines\cortex.llamacpp\engine.dll";'
67+
else ifeq ($(shell uname -s),Linux)
68+
@echo "Skipping Code Sign for linux"
69+
@exit 0
70+
else
71+
find "cortex-cpp" -type f -exec codesign --force -s "$(DEVELOPER_ID)" --options=runtime {} \;
72+
endif
73+
74+
package:
75+
ifeq ($(OS),Windows_NT)
76+
@powershell -Command "7z a -ttar temp.tar cortex-cpp\*; 7z a -tgzip cortex-cpp.tar.gz temp.tar;"
77+
else ifeq ($(shell uname -s),Linux)
78+
tar -czvf cortex-cpp.tar.gz cortex-cpp;
79+
else
5080
tar -czvf cortex-cpp.tar.gz cortex-cpp;
5181
endif
5282

@@ -65,4 +95,13 @@ else
6595
@cd cortex-cpp; \
6696
chmod +x ../../.github/scripts/e2e-test-llama-linux-and-mac.sh && ../../.github/scripts/e2e-test-llama-linux-and-mac.sh ./cortex-cpp $(LLM_MODEL_URL) $(EMBEDDING_MODEL_URL); \
6797
rm -rf uploads/;
98+
endif
99+
100+
clean:
101+
ifeq ($(OS),Windows_NT)
102+
@powershell -Command "rm -rf build; rm -rf build-deps; rm -rf cortex-cpp; rm -rf cortex-cpp.tar.gz;"
103+
else ifeq ($(shell uname -s),Linux)
104+
@rm -rf build; rm -rf build-deps; rm -rf cortex-cpp; rm -rf cortex-cpp.tar.gz;
105+
else
106+
@rm -rf build; rm -rf build-deps; rm -rf cortex-cpp; rm -rf cortex-cpp.tar.gz;
68107
endif

cortex-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "cortex-js",
2+
"name": "@janhq/cortex",
33
"version": "0.0.1",
44
"description": "",
55
"author": "",

package.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)