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

Commit 23746ee

Browse files
feat: e2e test ci (#1238)
* feat: download pre-release * chore: add e2e test * feat: e2e test CI * fix: timeout * fix: exit code * fix: timeout None * fix: test * fix: clone exe * fix: cd * fix: temp comment * fix: windows and macos * fix: test * fix: windows * fix: readable * ci: e2e testing use GITHUB_TOKEN to increase github api rate limit * ci: enable e2e testing in quality gate new PR --------- Co-authored-by: Hien To <tominhhien97@gmail.com>
1 parent d67029b commit 23746ee

File tree

8 files changed

+117
-11
lines changed

8 files changed

+117
-11
lines changed

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

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CI Quality Gate Cortex CPP
22

33
on:
44
pull_request:
5-
types: [opened, synchronize, reopened]
5+
types: [opened, synchronize, reopened, ready_for_review]
66
paths:
77
[
88
"engine/**",
@@ -53,11 +53,10 @@ jobs:
5353
with:
5454
submodules: recursive
5555

56-
- name: use python for linux
57-
if: runner.os == 'Linux'
58-
uses: actions/setup-python@v4
56+
- name: use python
57+
uses: actions/setup-python@v5
5958
with:
60-
python-version: '3.9'
59+
python-version: '3.10'
6160

6261
- name: Install tools on Linux
6362
if: runner.os == 'Linux'
@@ -106,7 +105,38 @@ jobs:
106105
run: |
107106
cd engine
108107
make run-unit-tests
109-
108+
109+
- name: Run e2e tests
110+
if: runner.os != 'Windows' && github.event.pull_request.draft == false
111+
run: |
112+
cd engine
113+
cp build/cortex build/cortex-nightly
114+
cp build/cortex build/cortex-beta
115+
python -m pip install --upgrade pip
116+
python -m pip install pytest
117+
python -m pip install requests
118+
python e2e-test/main.py
119+
rm build/cortex-nightly
120+
rm build/cortex-beta
121+
env:
122+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123+
124+
125+
- name: Run e2e tests
126+
if: runner.os == 'Windows' && github.event.pull_request.draft == false
127+
run: |
128+
cd engine
129+
cp build/cortex.exe build/cortex-nightly.exe
130+
cp build/cortex.exe build/cortex-beta.exe
131+
python -m pip install --upgrade pip
132+
python -m pip install pytest
133+
python -m pip install requests
134+
python e2e-test/main.py
135+
rm build/cortex-nightly.exe
136+
rm build/cortex-beta.exe
137+
env:
138+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
139+
110140
- name: Pre-package
111141
run: |
112142
cd engine

.github/workflows/template-build-linux-x64.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,25 @@ jobs:
127127
run: |
128128
cd engine
129129
make build CMAKE_EXTRA_FLAGS="${{ inputs.cmake-flags }}" BUILD_DEPS_CMAKE_EXTRA_FLAGS="${{ inputs.build-deps-cmake-flags }}"
130+
131+
- name: Install Python
132+
uses: actions/setup-python@v4
133+
with:
134+
python-version: '3.10'
135+
136+
- name: Run e2e tests
137+
run: |
138+
cd engine
139+
cp build/cortex build/cortex-nightly
140+
cp build/cortex build/cortex-beta
141+
python -m pip install --upgrade pip
142+
python -m pip install pytest
143+
python -m pip install requests
144+
python e2e-test/main.py
145+
rm build/cortex-nightly
146+
rm build/cortex-beta
147+
env:
148+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
130149

131150
- name: Pre-package
132151
run: |

.github/workflows/template-build-macos.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,26 @@ jobs:
152152
run: |
153153
cd engine
154154
make build CMAKE_EXTRA_FLAGS="${{ inputs.cmake-flags }}" BUILD_DEPS_CMAKE_EXTRA_FLAGS="${{ inputs.build-deps-cmake-flags }}"
155-
155+
156+
- name: Install Python
157+
uses: actions/setup-python@v4
158+
with:
159+
python-version: '3.10'
160+
161+
- name: Run e2e tests
162+
run: |
163+
cd engine
164+
cp build/cortex build/cortex-nightly
165+
cp build/cortex build/cortex-beta
166+
python -m pip install --upgrade pip
167+
python -m pip install pytest
168+
python -m pip install requests
169+
python e2e-test/main.py
170+
rm build/cortex-nightly
171+
rm build/cortex-beta
172+
env:
173+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
174+
156175
- name: Pre-package
157176
run: |
158177
cd engine

.github/workflows/template-build-windows-x64.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,25 @@ jobs:
164164
cd engine
165165
make build CMAKE_EXTRA_FLAGS="${{ inputs.cmake-flags }}" BUILD_DEPS_CMAKE_EXTRA_FLAGS="${{ inputs.build-deps-cmake-flags }}"
166166
167+
- name: Install Python
168+
uses: actions/setup-python@v4
169+
with:
170+
python-version: '3.10'
171+
172+
- name: Run e2e tests
173+
run: |
174+
cd engine
175+
cp build/cortex.exe build/cortex-nightly.exe
176+
cp build/cortex.exe build/cortex-beta.exe
177+
python -m pip install --upgrade pip
178+
python -m pip install pytest
179+
python -m pip install requests
180+
python e2e-test/main.py
181+
rm build/cortex-nightly.exe
182+
rm build/cortex-beta.exe
183+
env:
184+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
185+
167186
- name: Pre-package
168187
run: |
169188
cd engine

engine/e2e-test/test_cli_engine_install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TestCliEngineInstall:
99

1010
def test_engines_install_llamacpp_should_be_successfully(self):
1111
exit_code, output, error = run(
12-
"Install Engine", ["engines", "install", "cortex.llamacpp"], timeout=600
12+
"Install Engine", ["engines", "install", "cortex.llamacpp"], timeout=None
1313
)
1414
assert "Start downloading" in output, "Should display downloading message"
1515
assert exit_code == 0, f"Install engine failed with error: {error}"

engine/e2e-test/test_create_log_folder.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ def setup_and_teardown(self):
2424

2525
def test_create_log_folder_run_successfully(self):
2626
root = Path.home()
27-
assert os.path.exists(root / "cortexcpp" / "logs")
27+
assert (
28+
os.path.exists(root / "cortexcpp" / "logs")
29+
or os.path.exists(root / "cortexcpp-beta" / "logs")
30+
or os.path.exists(root / "cortexcpp-nightly" / "logs")
31+
)

engine/e2e-test/test_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import List
88

99
# You might want to change the path of the executable based on your build directory
10-
executable_windows_path = "build\\Debug\\cortex.exe"
10+
executable_windows_path = "build\\cortex.exe"
1111
executable_unix_path = "build/cortex"
1212

1313
# Timeout

engine/services/engine_service.cc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ cpp::result<bool, std::string> EngineService::UninstallEngine(
217217

218218
cpp::result<bool, std::string> EngineService::DownloadEngine(
219219
const std::string& engine, const std::string& version) {
220+
221+
// Check if GITHUB_TOKEN env exist
222+
const char* github_token = std::getenv("GITHUB_TOKEN");
223+
220224
auto get_params = [&engine, &version]() -> std::vector<std::string> {
221225
if (version == "latest") {
222226
return {"repos", "janhq", engine, "releases", version};
@@ -232,7 +236,18 @@ cpp::result<bool, std::string> EngineService::DownloadEngine(
232236
};
233237

234238
httplib::Client cli(url_obj.GetProtocolAndHost());
235-
if (auto res = cli.Get(url_obj.GetPathAndQuery());
239+
240+
httplib::Headers headers;
241+
242+
if (github_token) {
243+
std::string auth_header = "token " + std::string(github_token);
244+
headers.insert({"Authorization", auth_header});
245+
CTL_INF("Using authentication with GitHub token.");
246+
} else {
247+
CTL_INF("No GitHub token found. Sending request without authentication.");
248+
}
249+
250+
if (auto res = cli.Get(url_obj.GetPathAndQuery(), headers);
236251
res->status == httplib::StatusCode::OK_200) {
237252
auto body = json::parse(res->body);
238253
auto get_data =

0 commit comments

Comments
 (0)