mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
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.
This commit is contained in:
parent
aca94300c8
commit
90cc962802
|
@ -214,6 +214,24 @@ add_definitions(
|
||||||
-DGIT_VERSION="${GIT_VERSION}"
|
-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)
|
set(APPLE_EXT False)
|
||||||
if (FOUNDATION_FOUND AND IOKIT_FOUND)
|
if (FOUNDATION_FOUND AND IOKIT_FOUND)
|
||||||
set(APPLE_EXT True)
|
set(APPLE_EXT True)
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#define VERSION_REGEX_STRING "v([0-9]+)\\.([0-9]+)\\.([0-9]+)"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const QString versionUrl{QStringLiteral("https://api.github.com/repos/qTox/qTox/releases/latest")};
|
const QString versionUrl{QStringLiteral("https://api.github.com/repos/qTox/qTox/releases/latest")};
|
||||||
|
|
||||||
|
@ -41,7 +43,7 @@ struct Version {
|
||||||
Version tagToVersion(QString tagName)
|
Version tagToVersion(QString tagName)
|
||||||
{
|
{
|
||||||
// capture tag name to avoid showing update available on dev builds which include hash as part of describe
|
// 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);
|
auto matches = versionFormat.match(tagName);
|
||||||
assert(matches.lastCapturedIndex() == 3);
|
assert(matches.lastCapturedIndex() == 3);
|
||||||
|
|
||||||
|
@ -85,6 +87,17 @@ bool isUpdateAvailable(Version current, Version available)
|
||||||
return false;
|
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
|
} // namespace
|
||||||
|
|
||||||
UpdateCheck::UpdateCheck(const Settings& settings)
|
UpdateCheck::UpdateCheck(const Settings& settings)
|
||||||
|
@ -143,5 +156,10 @@ void UpdateCheck::handleResponse(QNetworkReply* reply)
|
||||||
qInfo() << "qTox is up to date";
|
qInfo() << "qTox is up to date";
|
||||||
emit upToDate();
|
emit upToDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isCurrentVersionStable() == false) {
|
||||||
|
qWarning() << "qTox is running an unstable version";
|
||||||
|
}
|
||||||
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user