From 90cc962802a5909e0692d5a6f84ac6808803fc28 Mon Sep 17 00:00:00 2001 From: powerjungle Date: Sat, 14 Nov 2020 11:51:53 +0200 Subject: [PATCH 1/3] feat(logging): check if current code is tagged This commit adds a new define called "GIT_DESCRIBE_EXACT" through cmake. It is checked with a regex in "updatecheck.cpp" for a version number after the check for new updates. If there is no version number, a warning is output to log. The reason for the new define is to avoid doing too much regex on "GET_DESCRIBE", since "GIT_DESCRIBE_EXACT" will not contain a version number if the code is not tagged. --- cmake/Dependencies.cmake | 18 ++++++++++++++++++ src/net/updatecheck.cpp | 20 +++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 71e7929a6..fd402eba9 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -214,6 +214,24 @@ add_definitions( -DGIT_VERSION="${GIT_VERSION}" ) +if (NOT GIT_DESCRIBE_EXACT) + execute_process( + COMMAND git describe --exact-match --tags HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_DESCRIBE_EXACT + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + if(NOT GIT_DESCRIBE_EXACT) + set(GIT_DESCRIBE_EXACT "Nightly") + endif() +endif() + +add_definitions( + -DGIT_DESCRIBE_EXACT="${GIT_DESCRIBE_EXACT}" +) + set(APPLE_EXT False) if (FOUNDATION_FOUND AND IOKIT_FOUND) set(APPLE_EXT True) diff --git a/src/net/updatecheck.cpp b/src/net/updatecheck.cpp index e95182d86..16e6dd816 100644 --- a/src/net/updatecheck.cpp +++ b/src/net/updatecheck.cpp @@ -29,6 +29,8 @@ #include #include +#define VERSION_REGEX_STRING "v([0-9]+)\\.([0-9]+)\\.([0-9]+)" + namespace { const QString versionUrl{QStringLiteral("https://api.github.com/repos/qTox/qTox/releases/latest")}; @@ -41,7 +43,7 @@ struct Version { Version tagToVersion(QString tagName) { // capture tag name to avoid showing update available on dev builds which include hash as part of describe - QRegularExpression versionFormat{QStringLiteral("v([0-9]+)\\.([0-9]+)\\.([0-9]+)")}; + QRegularExpression versionFormat{QStringLiteral(VERSION_REGEX_STRING)}; auto matches = versionFormat.match(tagName); assert(matches.lastCapturedIndex() == 3); @@ -85,6 +87,17 @@ bool isUpdateAvailable(Version current, Version available) return false; } +bool isCurrentVersionStable() +{ + QRegularExpression versionRegex{QStringLiteral(VERSION_REGEX_STRING)}; + auto currentVer = versionRegex.match(GIT_DESCRIBE_EXACT); + if (currentVer.hasMatch()){ + return true; + } else { + return false; + } +} + } // namespace UpdateCheck::UpdateCheck(const Settings& settings) @@ -143,5 +156,10 @@ void UpdateCheck::handleResponse(QNetworkReply* reply) qInfo() << "qTox is up to date"; emit upToDate(); } + + if (isCurrentVersionStable() == false) { + qWarning() << "qTox is running an unstable version"; + } + reply->deleteLater(); } From 0ee37a7a099aec6cd86d3361ca5e5065b8b4f501 Mon Sep 17 00:00:00 2001 From: powerjungle Date: Sun, 15 Nov 2020 15:23:50 +0200 Subject: [PATCH 2/3] fix(logging): check if version is stable before other checks Because the other checks will exit the function before it reaches that if. --- src/net/updatecheck.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/net/updatecheck.cpp b/src/net/updatecheck.cpp index 16e6dd816..245be4f97 100644 --- a/src/net/updatecheck.cpp +++ b/src/net/updatecheck.cpp @@ -121,6 +121,10 @@ void UpdateCheck::checkForUpdate() void UpdateCheck::handleResponse(QNetworkReply* reply) { + if (isCurrentVersionStable() == false) { + qWarning() << "qTox is running an unstable version"; + } + assert(reply != nullptr); if (reply == nullptr) { qWarning() << "Update check returned null reply, ignoring"; @@ -157,9 +161,5 @@ void UpdateCheck::handleResponse(QNetworkReply* reply) emit upToDate(); } - if (isCurrentVersionStable() == false) { - qWarning() << "qTox is running an unstable version"; - } - reply->deleteLater(); } From 54d8c35b823514c550cf6577df6f2a398f4fd44a Mon Sep 17 00:00:00 2001 From: powerjungle Date: Sun, 15 Nov 2020 15:44:37 +0200 Subject: [PATCH 3/3] refactor(logging): change VERSION_REGEX_STRING to a const --- src/net/updatecheck.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/net/updatecheck.cpp b/src/net/updatecheck.cpp index 245be4f97..49a34b671 100644 --- a/src/net/updatecheck.cpp +++ b/src/net/updatecheck.cpp @@ -29,10 +29,9 @@ #include #include -#define VERSION_REGEX_STRING "v([0-9]+)\\.([0-9]+)\\.([0-9]+)" - namespace { const QString versionUrl{QStringLiteral("https://api.github.com/repos/qTox/qTox/releases/latest")}; +const QString versionRegexString{QStringLiteral("v([0-9]+)\\.([0-9]+)\\.([0-9]+)")}; struct Version { int major; @@ -43,7 +42,7 @@ struct Version { Version tagToVersion(QString tagName) { // capture tag name to avoid showing update available on dev builds which include hash as part of describe - QRegularExpression versionFormat{QStringLiteral(VERSION_REGEX_STRING)}; + QRegularExpression versionFormat(versionRegexString); auto matches = versionFormat.match(tagName); assert(matches.lastCapturedIndex() == 3); @@ -89,7 +88,7 @@ bool isUpdateAvailable(Version current, Version available) bool isCurrentVersionStable() { - QRegularExpression versionRegex{QStringLiteral(VERSION_REGEX_STRING)}; + QRegularExpression versionRegex(versionRegexString); auto currentVer = versionRegex.match(GIT_DESCRIBE_EXACT); if (currentVer.hasMatch()){ return true;