From 17548036b828924d622598c8d756366709e27854 Mon Sep 17 00:00:00 2001 From: ksqsf Date: Sun, 15 Dec 2024 14:21:32 +0100 Subject: [PATCH] build(ci): add --- .github/workflows/commit-ci.yml | 25 +++++++++++++++++++++++++ CMakeLists.txt | 6 +++--- README.md | 10 +++++----- src/main.cpp | 27 ++++++++++++++++----------- 4 files changed, 49 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/commit-ci.yml diff --git a/.github/workflows/commit-ci.yml b/.github/workflows/commit-ci.yml new file mode 100644 index 0000000..f27c737 --- /dev/null +++ b/.github/workflows/commit-ci.yml @@ -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/** diff --git a/CMakeLists.txt b/CMakeLists.txt index a79aff4..8d1f886 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/README.md b/README.md index d2bd1ad..cd96266 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/main.cpp b/src/main.cpp index d943109..7f618e1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,7 +47,7 @@ main(int argc, char *argv[]) auto doc = YAML::LoadFile(spec_path); auto schema_id = doc["schema"].as(); auto source_dir = fs::path{ doc["source_dir"].as() }; - 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); @@ -56,7 +56,7 @@ main(int argc, char *argv[]) for (auto pair : doc["deploy"]) { auto name = pair.first.as(); 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); @@ -70,6 +70,7 @@ 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(); @@ -77,25 +78,29 @@ main(int argc, char *argv[]) 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"; }