mirror of
https://github.com/davidallendj/gdpm.git
synced 2025-12-19 19:17:01 -07:00
Fixed small issues and updated GitHub CI
-Make package manager functions return error -Added Jenkensfile CI for testing purposes -Updated the github CI for testing purposes
This commit is contained in:
parent
5ffce72fa5
commit
072a118c9d
10 changed files with 107 additions and 32 deletions
40
.github/workflows/build.yml
vendored
40
.github/workflows/build.yml
vendored
|
|
@ -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
|
||||
|
|
@ -10,7 +10,7 @@ stages:
|
|||
|
||||
cache:
|
||||
paths:
|
||||
- .cache
|
||||
- tests
|
||||
|
||||
|
||||
before-script:
|
||||
|
|
|
|||
21
Jenkinsfile
vendored
Normal file
21
Jenkinsfile
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
pipeline{
|
||||
agent any
|
||||
|
||||
stages {
|
||||
stage('Build'){
|
||||
steps{
|
||||
echo 'Building...'
|
||||
}
|
||||
}
|
||||
stage('Test'){
|
||||
steps{
|
||||
echo 'Testing...'
|
||||
}
|
||||
}
|
||||
stage('Deploy'){
|
||||
steps{
|
||||
echo 'Deploying...'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -65,4 +65,4 @@ exe = executable(
|
|||
link_with: lib,
|
||||
cpp_args: cpp_args
|
||||
)
|
||||
test('unittests', exe)
|
||||
test('gdpm-tests', exe)
|
||||
|
|
@ -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<std::string> packages;
|
||||
std::vector<std::string> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -17,31 +17,50 @@ TEST_SUITE("Test database functions"){
|
|||
|
||||
|
||||
TEST_SUITE("Package manager function"){
|
||||
using namespace gdpm;
|
||||
|
||||
std::vector<std::string> 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue