// 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 struct CiProject; /** * Data describing one package to pull/build/etc. */ 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; std::filesystem::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 configurations void init_global(); // Load YAML configuration from a given path YAML::Node load_yaml_config(const std::filesystem::path &config_path); // Convert a YAML node to a CiProject structure CiProject yaml_to_project(const YAML::Node &pkg_node); bool pull_project(std::shared_ptr &proj, std::shared_ptr log = NULL); bool create_project_tarball(std::shared_ptr &proj, std::shared_ptr log = NULL); std::tuple> build_project(std::shared_ptr proj, std::shared_ptr log = NULL); bool upload_and_lint(std::shared_ptr &proj, const std::set changes_files, bool skip_dput, std::shared_ptr log = NULL); // Perform cleanup and summarize the build process void do_summary(bool skip_cleanup); // Process the entire pipeline for a given PackageConf ID void process_entire_pipeline(std::shared_ptr &proj, bool skip_dput, bool skip_cleanup); // Retrieve all PackageConf entries from the database 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 = ""); // Function to enqueue tasks void enqueue(std::function task); // Fetch logs for a specific PackageConf ID std::string get_logs_for_repo_conf(int package_conf_id); 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); 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); 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