// SPDX-License-Identifier: MIT #pragma once #include "openpu/http.hpp" #include #include #include namespace openpu { /// MAJOR.MINOR.PATCH, ordered numerically. struct SemVer { unsigned major = 0; unsigned minor = 0; unsigned patch = 0; /// Accepts "1.2.3" and "v1.2.3"; build metadata ("+3.gabc") is ignored. Pre-releases are rejected. static std::optional parse(std::string_view text); std::string toString() const; friend bool operator<(const SemVer& a, const SemVer& b) { if (a.major != b.major) return a.major < b.major; if (a.minor != b.minor) return a.minor < b.minor; return a.patch < b.patch; } friend bool operator==(const SemVer& a, const SemVer& b) { return a.major == b.major && a.minor == b.minor && a.patch == b.patch; } }; /// Where new OpenPU versions are published: the GitHub releases of the project. /// A Gitea/GitHub `/tags` list is understood too (OPENPU_RELEASES_URL may point to one). struct AppUpdateConfig { std::string releasesUrl = "https://api.github.com/repos/yann64/openpu/releases"; /// Page opened in the browser when the answer gives none; "{tag}" is replaced by the tag name. std::string pageUrl = "https://github.com/yann64/openpu/releases/tag/{tag}"; /// Defaults overridden by OPENPU_RELEASES_URL and OPENPU_RELEASE_PAGE_URL when set. static AppUpdateConfig fromEnvironment(); }; struct AppRelease { SemVer version; std::string tag; std::string pageUrl; std::string notes; ///< release notes (or annotated tag message) }; /// Highest vX.Y.Z release of a GitHub/Gitea `/releases` list (drafts and pre-releases skipped) or /// of a `/tags` list (nullopt if none). Throws ParseError. std::optional latestRelease(std::string_view json, const AppUpdateConfig& config); /// Newest published release if it is newer than `currentVersion`, nullopt when up to date. /// Throws NetworkError, or std::runtime_error for an unexpected answer. std::optional checkForNewerRelease(Transport& transport, const AppUpdateConfig& config, std::string_view currentVersion); } // namespace openpu