diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 459d31e..485e9c3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,11 +1,45 @@ name: github-ci -on: [push] +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + + +permissions: + contents: read + # Needed for the 'trilom/file-changes-action' action + pull-requests: read + + +concurrency: + group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' + cancel-in-progress: true jobs: build: + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup + run: + echo "Setting up dependencies..." + + - name: Build + run: + echo -e "Building executable and libraries...\n$PWD" + bin/compile.sh + + - name: Tests + run: + echo "Running unit tests..." + bin/gdpm-tests + + - name: Package + run: + echo "Packaging binaries..." - - steps: - - uses: actions/checkout@v1 \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f7599d0..fe87204 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ stages: cache: paths: - - .cache + - tests before-script: diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..bddad6c --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,21 @@ +pipeline{ + agent any + + stages { + stage('Build'){ + steps{ + echo 'Building...' + } + } + stage('Test'){ + steps{ + echo 'Testing...' + } + } + stage('Deploy'){ + steps{ + echo 'Deploying...' + } + } + } +} \ No newline at end of file diff --git a/bin/compile.sh b/bin/compile.sh index c6b081c..c1932f7 100755 --- a/bin/compile.sh +++ b/bin/compile.sh @@ -8,9 +8,10 @@ # CMake/ninja build system mkdir -p build -cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -G Ninja +CXX="zig c++ -target aarch64-linux-gnu" cmake -B build -S . -D CMAKE_EXPORT_COMPILE_COMMANDS=1 -D CMAKE_BUILD_TYPE=Debug -G Ninja ninja -C build -j $(nproc) + # Create symlinks to executables in build folder if necessary if test -f "../build/gdpm"; then rm bin/gdpm diff --git a/include/error.hpp b/include/error.hpp index 93a7825..0cdba54 100644 --- a/include/error.hpp +++ b/include/error.hpp @@ -14,6 +14,7 @@ namespace gdpm{ int get_code() const { return m_code; } std::string get_message() const { return m_message; } + bool has_error() const { return m_code != 0; } private: int m_code; diff --git a/include/rest_api.hpp b/include/rest_api.hpp index 5ff481e..88d47f8 100644 --- a/include/rest_api.hpp +++ b/include/rest_api.hpp @@ -17,7 +17,7 @@ namespace gdpm::rest_api{ constexpr const char *GET_Asset = "/asset?"; constexpr const char *GET_AssetId = "/asset/{id}"; // ...find_replace constexpr const char *POST_AssetIdDelete = "/asset/{id}/delete"; - constexpr const char *POST_AssetIdUndelete = "/asset/{id}/delete"; + constexpr const char *POST_AssetIdUndelete = "/asset/{id}/undelete"; constexpr const char *POST_AssetSupportLevel = "/asset/{id}/support_level"; constexpr const char *POST_Asset = "/asset"; constexpr const char *POST_AssetId = "/asset/{id}"; @@ -33,7 +33,7 @@ namespace gdpm::rest_api{ enum support_e { all, official, community, testing }; enum sort_e { none, rating, cost, name, updated }; - struct rest_api_context{ + struct context{ type_e type; int category; support_e support; @@ -47,14 +47,14 @@ namespace gdpm::rest_api{ int verbose; }; - rest_api_context make_context(type_e type = GDPM_DEFAULT_ASSET_TYPE, int category = GDPM_DEFAULT_ASSET_CATEGORY, support_e support = GDPM_DEFAULT_ASSET_SUPPORT, const std::string& filter = GDPM_DEFAULT_ASSET_FILTER, const std::string& user = GDPM_DEFAULT_ASSET_USER, const std::string& godot_version = GDPM_DEFAULT_ASSET_GODOT_VERSION, int max_results = GDPM_DEFAULT_ASSET_MAX_RESULTS, int page = GDPM_DEFAULT_ASSET_PAGE, sort_e sort = GDPM_DEFAULT_ASSET_SORT, bool reverse = GDPM_DEFAULT_ASSET_REVERSE, int verbose = GDPM_DEFAULT_ASSET_VERBOSE); + context make_context(type_e type = GDPM_DEFAULT_ASSET_TYPE, int category = GDPM_DEFAULT_ASSET_CATEGORY, support_e support = GDPM_DEFAULT_ASSET_SUPPORT, const std::string& filter = GDPM_DEFAULT_ASSET_FILTER, const std::string& user = GDPM_DEFAULT_ASSET_USER, const std::string& godot_version = GDPM_DEFAULT_ASSET_GODOT_VERSION, int max_results = GDPM_DEFAULT_ASSET_MAX_RESULTS, int page = GDPM_DEFAULT_ASSET_PAGE, sort_e sort = GDPM_DEFAULT_ASSET_SORT, bool reverse = GDPM_DEFAULT_ASSET_REVERSE, int verbose = GDPM_DEFAULT_ASSET_VERBOSE); std::string to_string(type_e type); std::string to_string(support_e support); std::string to_string(sort_e sort); - void _print_params(const rest_api_context& params); + void _print_params(const context& params); rapidjson::Document _parse_json(const std::string& r, int verbose = 0); - std::string _prepare_request(const std::string& url, const rest_api_context& context); + std::string _prepare_request(const std::string& url, const context& context); bool register_account(const std::string& username, const std::string& password, const std::string& email); bool login(const std::string& username, const std::string& password); @@ -62,8 +62,8 @@ namespace gdpm::rest_api{ rapidjson::Document configure(const std::string& url = constants::HostUrl, type_e type = any, int verbose = 0); rapidjson::Document get_assets_list(const std::string& url = constants::HostUrl, type_e type = GDPM_DEFAULT_ASSET_TYPE, int category = GDPM_DEFAULT_ASSET_CATEGORY, support_e support = GDPM_DEFAULT_ASSET_SUPPORT, const std::string& filter = GDPM_DEFAULT_ASSET_FILTER, const std::string& user = GDPM_DEFAULT_ASSET_USER, const std::string& godot_version = GDPM_DEFAULT_ASSET_GODOT_VERSION, int max_results = GDPM_DEFAULT_ASSET_MAX_RESULTS, int page = GDPM_DEFAULT_ASSET_PAGE, sort_e sort = GDPM_DEFAULT_ASSET_SORT, bool reverse = GDPM_DEFAULT_ASSET_REVERSE, int verbose = GDPM_DEFAULT_ASSET_VERBOSE); - rapidjson::Document get_assets_list(const std::string& url, const rest_api_context& params = {}); - rapidjson::Document get_asset(const std::string& url, int asset_id, const rest_api_context& params = {}); + rapidjson::Document get_assets_list(const std::string& url, const context& params = {}); + rapidjson::Document get_asset(const std::string& url, int asset_id, const context& params = {}); bool delete_asset(int asset_id); // ...for moderators bool undelete_asset(int asset_id); // ...for moderators bool set_support_level(int asset_id); // ...for moderators diff --git a/meson.build b/meson.build index 1baf497..f575588 100644 --- a/meson.build +++ b/meson.build @@ -65,4 +65,4 @@ exe = executable( link_with: lib, cpp_args: cpp_args ) -test('unittests', exe) \ No newline at end of file +test('gdpm-tests', exe) \ No newline at end of file diff --git a/src/package_manager.cpp b/src/package_manager.cpp index f694049..8066c36 100644 --- a/src/package_manager.cpp +++ b/src/package_manager.cpp @@ -34,7 +34,7 @@ namespace gdpm::package_manager{ CURL *curl; CURLcode res; config::context config; - rest_api::rest_api_context params; + rest_api::context params; command_e command; std::vector packages; std::vector opts; @@ -102,7 +102,6 @@ namespace gdpm::package_manager{ if(config.enable_sync){ if(p_cache.empty()){ p_cache = synchronize_database(package_titles); - p_cache = cache::get_package_info_by_title(package_titles); } } diff --git a/src/rest_api.cpp b/src/rest_api.cpp index 943b96e..ef23e70 100644 --- a/src/rest_api.cpp +++ b/src/rest_api.cpp @@ -27,8 +27,8 @@ namespace gdpm::rest_api{ return false; } - rest_api_context make_context(type_e type, int category, support_e support, const std::string& filter, const std::string& user, const std::string& godot_version, int max_results, int page, sort_e sort, bool reverse, int verbose){ - rest_api_context params{ + context make_context(type_e type, int category, support_e support, const std::string& filter, const std::string& user, const std::string& godot_version, int max_results, int page, sort_e sort, bool reverse, int verbose){ + context params{ .type = type, .category = category, .support = support, @@ -91,7 +91,7 @@ namespace gdpm::rest_api{ return _s; } - std::string _prepare_request(const std::string &url, const rest_api_context &c){ + std::string _prepare_request(const std::string &url, const context &c){ std::string request_url{url}; request_url += to_string(c.type); request_url += (c.category <= 0) ? "&category=" : "&category="+fmt::to_string(c.category); @@ -105,7 +105,7 @@ namespace gdpm::rest_api{ return request_url; } - void _print_params(const rest_api_context& params){ + void _print_params(const context& params){ log::println("params: \n" "\ttype: {}\n" "\tcategory: {}\n" @@ -132,7 +132,7 @@ namespace gdpm::rest_api{ } rapidjson::Document get_assets_list(const std::string& url, type_e type, int category, support_e support, const std::string& filter,const std::string& user, const std::string& godot_version, int max_results, int page, sort_e sort, bool reverse, int verbose){ - rest_api_context c{ + context c{ .type = type, .category = category, .support = support, @@ -148,7 +148,7 @@ namespace gdpm::rest_api{ return get_assets_list(url, c); } - rapidjson::Document get_assets_list(const std::string& url, const rest_api_context& c){ + rapidjson::Document get_assets_list(const std::string& url, const context& c){ std::string request_url = _prepare_request(url, c); http::response r = http::request_get(request_url); if(c.verbose > 0) @@ -156,7 +156,7 @@ namespace gdpm::rest_api{ return _parse_json(r.body, c.verbose); } - rapidjson::Document get_asset(const std::string& url, int asset_id, const rest_api_context& params){ + rapidjson::Document get_asset(const std::string& url, int asset_id, const context& params){ std::string request_url = _prepare_request(url, params); utils::replace_all(request_url, "{id}", std::to_string(asset_id)); http::response r = http::request_get(request_url.c_str()); diff --git a/tests/basic.cpp b/tests/basic.cpp index 0d97e92..6b727e4 100644 --- a/tests/basic.cpp +++ b/tests/basic.cpp @@ -17,31 +17,50 @@ TEST_SUITE("Test database functions"){ TEST_SUITE("Package manager function"){ + using namespace gdpm; + std::vector packages{"ResolutionManagerPlugin","godot-hmac", "Godot"}; - gdpm::config::context config = gdpm::config::make_context(); + config::context config = config::make_context(); + + auto check_error = [](const error& error){ + if(error.has_error()){ + log::error(error.get_message()); + } + + CHECK(!error.has_error()); + }; + TEST_CASE("Test install packages"){ - gdpm::package_manager::install_packages(packages, true); + error error = package_manager::install_packages(packages, true); + check_error(error); } TEST_CASE("Test searching packages"){ - gdpm::package_manager::search_for_packages(packages, true); + error error = package_manager::search_for_packages(packages, true); + check_error(error); } TEST_CASE("Test remove packages"){ - gdpm::package_manager::remove_packages(packages, true); + error error = package_manager::remove_packages(packages, true); + check_error(error); } } TEST_CASE("Test configuration functions"){ - gdpm::config::context config = gdpm::config::make_context(); - config.path = gdpm::constants::TestPath + "/"; + using namespace gdpm; - std::string json = gdpm::config::to_json(config); - gdpm::error error_save = gdpm::config::save(config.path, config); - gdpm::error error_load = gdpm::config::load(config.path, config); + config::context config = config::make_context(); + config.path = constants::TestPath + "/"; + + std::string json = config::to_json(config); + error error_save = config::save(config.path, config); + CHECK(error_save.get_code() == 0); + + error error_load = config::load(config.path, config); + CHECK(error_load.get_code() == 0); } \ No newline at end of file