Skip to content

Commit

Permalink
build(ci): add
Browse files Browse the repository at this point in the history
  • Loading branch information
ksqsf committed Dec 15, 2024
1 parent cbec733 commit 1754803
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/commit-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Commit CI

on:
push:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-24.04
steps:
- name: Checkout last commit
uses: actions/checkout@v4
- name: Install deps
run: sudo apt-get update && sudo apt-get -y install ninja-build libargparse-dev liblua5.4-dev librime-dev libyaml-cpp-dev
- name: Build
run: cmake -S. -Bbuild -GNinja -DCMAKE_INSTALL_PREFIX=./dist && cmake --build build && cmake --install build
- name: Upload
uses: actions/upload-artifact@v4
with:
name: mira-linux-x86_64
path: |
dist/**
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(PkgConfig REQUIRED)
pkg_check_modules(YamlCpp REQUIRED IMPORTED_TARGET yaml-cpp>=0.8.0)
pkg_check_modules(ArgParse REQUIRED IMPORTED_TARGET argparse>=3.1.0)
pkg_check_modules(YamlCpp REQUIRED IMPORTED_TARGET yaml-cpp>=0.8)
pkg_check_modules(ArgParse REQUIRED IMPORTED_TARGET argparse>=3.0)
pkg_check_modules(Lua REQUIRED IMPORTED_TARGET lua>=5.4)
pkg_check_modules(Rime REQUIRED IMPORTED_TARGET rime>=1.12)
pkg_check_modules(Rime REQUIRED IMPORTED_TARGET rime>=1.10)

add_subdirectory(include)
add_subdirectory(src)
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ deploy:
mira moran.test.yaml
```
如果方案存在多次部署,建議使用 `-C` / `--cache-dir` 參數緩存
如果涉及多次部署,建議使用 `-C` / `--cache-dir` 參數緩存產物以加速測試流程
## 構建
依賴如下外部庫:
- librime >= 1.12.0
- yaml-cpp >= 0.8.0
- argparse >= 3.1.0
- lua >= 5.4.7
- librime >= 1.10
- yaml-cpp >= 0.8
- argparse >= 3.0
- lua >= 5.4
27 changes: 16 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ main(int argc, char *argv[])
auto doc = YAML::LoadFile(spec_path);
auto schema_id = doc["schema"].as<std::string>();
auto source_dir = fs::path{ doc["source_dir"].as<std::string>() };
std::cout << "Select " << schema_id << " at " << source_dir << "\n";
std::cout << "SELECT " << schema_id << " from " << source_dir << "\n";

lua_State *L = luaL_newstate();
luaL_openlibs(L);
Expand All @@ -56,7 +56,7 @@ main(int argc, char *argv[])
for (auto pair : doc["deploy"]) {
auto name = pair.first.as<std::string>();
auto dspec = pair.second;
std::cout << "Deploy " << name << "\n";
std::cout << "DEPLOY " << name << "\n";

// Patch and Deploy
Rime rime(source_dir, schema_id, cache_dir);
Expand All @@ -70,32 +70,37 @@ main(int argc, char *argv[])
std::string test_id = schema_id + "::" + name + "::" + keys;

auto session = rime.create_session();

if (dspec["options"]) {
for (auto kv : doc["options"]) {
const auto& k = kv.first.as<std::string>();
const auto& v = kv.second.as<bool>();
session->set_option(k, v);
}
}

auto result = session->send_keys(keys);
std::cout << "[....] " << test_id;
if (!result) {
std::cout << "\r[FAIL]\n";
faillist.push_back(test_id);
continue;
}
bool pass = false;
if (!result)
goto done;

lua_setresult(L, *result);
bool pass = lua_eval(L, expr.c_str());
std::cout << "\r" << (pass ? "[PASS]" : "[FAIL]") << "\n";
pass = lua_eval(L, expr.c_str());

done:
std::cout << "\r[" << (pass ? "PASS" : "FAIL") << "]\n";
(pass ? passlist : faillist).push_back(test_id);
continue;
}
std::cout << "\n";
}
lua_close(L);

if (faillist.size()) {
std::cout << "\n\n" << faillist.size() << " tests failed:\n";
size_t n_fail = faillist.size(), n_pass = passlist.size();
if (n_fail) {
std::cout << "\n\n" << n_fail << "/" << (n_fail + n_pass)
<< " tests failed:\n";
for (const auto& id : faillist) {
std::cout << id << "\n";
}
Expand Down

0 comments on commit 1754803

Please sign in to comment.