// Copyright (C) 2024-2025 Simon Quigley // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #ifndef CI_LOGIC_H #define CI_LOGIC_H #include "ci_database_objs.h" #include "task_queue.h" #include #include #include #include #include #include #include #include #include #include #include namespace fs = std::filesystem; struct CiProject { std::string name; std::string version; std::string time; std::string upload_target; std::string upstream_url; std::string packaging_url; std::optional packaging_branch; fs::path main_tarball; bool large = false; // These get populated during build: std::vector changes_files; std::vector devel_changes_files; }; class CiLogic { public: // Initialize global config and database void init_global(); // Load YAML config from a given path YAML::Node load_yaml_config(const fs::path &config_path); // Convert a YAML node to a CiProject CiProject yaml_to_project(const YAML::Node &pkg_node); // Pipeline functions bool pull_project(std::shared_ptr &proj, std::shared_ptr log = nullptr); bool create_project_tarball(std::shared_ptr &proj, std::shared_ptr log = nullptr); std::tuple> build_project(std::shared_ptr proj, std::shared_ptr log = nullptr); bool upload_and_lint(std::shared_ptr &proj, const std::set changes_files, bool skip_dput, std::shared_ptr log = nullptr); // Summary & cleanup void do_summary(bool skip_cleanup); // Orchestrate entire pipeline void process_entire_pipeline(std::shared_ptr &proj, bool skip_dput, bool skip_cleanup); // Retrieve PackageConf entries (with optional pagination/sorting) std::vector> get_config(const std::string &repo_name = "", int page = 0, int per_page = 0, const std::string &sort_by = "", const std::string &sort_order = ""); // Enqueue a task (wrapper) void enqueue(std::function task); // Job status and PackageConf getters std::shared_ptr>> get_job_statuses(); std::vector> get_packageconfs(); std::shared_ptr get_packageconf_by_id(int id); std::vector> get_packageconfs_by_ids(std::set ids); void set_packageconfs(std::vector> _pkgconfs); void sync(std::shared_ptr pkgconf); // Queue tasks std::string queue_pull_tarball(std::vector> repos, std::unique_ptr& task_queue, std::shared_ptr>> job_statuses); std::string queue_build_upload(std::vector> repos, std::unique_ptr& task_queue, std::shared_ptr>> job_statuses); // Get a task’s log std::string get_task_log(int task_id); std::vector> list_known_repos(int page = 0, int per_page = 0, const std::string &sort_by = "", const std::string &sort_order = ""); bool pull_repo_by_name(const std::string &repo_name, std::shared_ptr log = nullptr); bool create_project_tarball_by_name(const std::string &repo_name, std::shared_ptr log = nullptr); bool build_repo_by_name(const std::string &repo_name, std::shared_ptr log = nullptr); // These come from the config/DB std::vector releases; std::vector packages; std::vector branches; private: void debuild_package(const fs::path &packaging_dir, std::shared_ptr log); QSqlDatabase p_db; mutable std::mutex packageconfs_mutex_; std::vector> packageconfs; std::shared_ptr>> _cached_job_statuses; struct package_conf_item { std::shared_ptr first_pkgconf; std::shared_ptr first_pull_task = std::make_shared(); std::shared_ptr first_tarball_task = std::make_shared(); std::shared_ptr packaging_commit = std::make_shared(); std::shared_ptr upstream_commit = std::make_shared(); }; }; #endif // CI_LOGIC_H