mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-11-20 00:51:32 -08:00
Fix update version check
Handle -1 revisions correctly in the updater check version comparison and allow suffixes in the release-tool.
This commit is contained in:
1 parent
e091b3b53c
commit
f218280c07
4 files changed
+104
-76
No files matched your search
+16
-11
@@ -305,9 +305,12 @@ def _cleanup():
|
||||
|
||||
|
||||
def _split_version(version):
|
||||
if type(version) is not str or not re.match(r'^\d+\.\d+\.\d+$', version):
|
||||
if type(version) is not str:
|
||||
raise Error('No version set.')
|
||||
match = re.match(r'^((?:\d+\.){2}\d+)(?:-(alpha|beta|snapshot)?(\d+)?)?$', version)
|
||||
if not match:
|
||||
raise Error('Invalid version number: %s', version)
|
||||
return version.split('.')
|
||||
return match.group(1).split('.')
|
||||
|
||||
|
||||
def _capture_vs_env(arch='amd64'):
|
||||
@@ -466,7 +469,7 @@ class Check(Command):
|
||||
@classmethod
|
||||
def perform_version_checks(cls, version, src_dir, git_ref=None, version_exists=False, checkout=True):
|
||||
logger.info('Performing version checks...')
|
||||
major, minor, patch = _split_version(version)
|
||||
major, minor, _ = _split_version(version)
|
||||
cls.check_working_tree_clean(src_dir)
|
||||
if version_exists:
|
||||
git_ref = git_ref or version
|
||||
@@ -528,8 +531,10 @@ class Check(Command):
|
||||
minor = re.search(r'^set\(KEEPASSXC_VERSION_MINOR "(\d+)"\)$', cmakelists_text, re.MULTILINE).group(1)
|
||||
patch = re.search(r'^set\(KEEPASSXC_VERSION_PATCH "(\d+)"\)$', cmakelists_text, re.MULTILINE).group(1)
|
||||
cmake_version = '.'.join([major, minor, patch])
|
||||
if cmake_version != version:
|
||||
raise Error(f'Version number in {cmakelists} not updated! Expected: %s, found: %s.', version, cmake_version)
|
||||
expected_version = '.'.join(_split_version(version))
|
||||
if cmake_version != expected_version:
|
||||
raise Error(f'Version number in {cmakelists} not updated! Expected: %s, found: %s.',
|
||||
expected_version, cmake_version)
|
||||
|
||||
@staticmethod
|
||||
def check_version_in_vcpkg_manifest(version, cwd=None):
|
||||
@@ -548,8 +553,7 @@ class Check(Command):
|
||||
changelog = Path(cwd) / changelog
|
||||
if not changelog.is_file():
|
||||
raise Error('File not found: %s', changelog)
|
||||
major, minor, patch = _split_version(version)
|
||||
if not re.search(rf'^## {major}\.{minor}\.{patch} \(.+?\)\n+', changelog.read_text("UTF-8"), re.MULTILINE):
|
||||
if not re.search(rf'^## {re.escape(version)} \(.+?\)\n+', changelog.read_text("UTF-8"), re.MULTILINE):
|
||||
raise Error(f'{changelog} has not been updated to the "%s" release.', version)
|
||||
|
||||
@staticmethod
|
||||
@@ -568,7 +572,7 @@ class Check(Command):
|
||||
raise Error(f'{appstream} is not well-formed. Error: %s at line %s, column %s',
|
||||
e.getMessage(), e.getLineNumber(), e.getColumnNumber())
|
||||
|
||||
regex = re.compile(rf'^\s*<release version="{version}" date=".+?">')
|
||||
regex = re.compile(rf'^\s*<release version="{re.escape(version)}" date=".+?">')
|
||||
with appstream.open('r', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
if regex.search(line):
|
||||
@@ -614,7 +618,6 @@ class Tag(Command):
|
||||
|
||||
def run(self, version, src_dir, release_branch, tag_name, no_latest, sign_key, no_sign, yes,
|
||||
skip_translations, tx_resource, tx_min_perc):
|
||||
major, minor, patch = _split_version(version)
|
||||
Check.perform_basic_checks(src_dir)
|
||||
release_branch = Check.perform_version_checks(version, src_dir, release_branch)
|
||||
Check.check_gnupg()
|
||||
@@ -625,11 +628,13 @@ class Tag(Command):
|
||||
i18n = I18N(self._arg_parser)
|
||||
i18n.run_tx_pull(src_dir, tx_resource, tx_min_perc, commit=True, yes=yes)
|
||||
|
||||
changelog = re.search(rf'^## ({major}\.{minor}\.{patch} \(.*?\)\n\n+.+?)\n\n+## ',
|
||||
changelog = re.search(rf'^## ({re.escape(version)} \(.*?\)\n\n+.+?)\n\n+## ',
|
||||
(Path(src_dir) / 'CHANGELOG.md').read_text("UTF-8"), re.MULTILINE | re.DOTALL)
|
||||
if not changelog:
|
||||
raise Error(f'No changelog entry found for version {version}.')
|
||||
changelog = 'Release ' + changelog.group(1)
|
||||
# Git treats lines starting with # as comments
|
||||
changelog = re.sub(r'^#+[ \t]*', '', changelog.group(1), flags=re.MULTILINE)
|
||||
changelog = 'Release ' + changelog
|
||||
|
||||
tag_name = tag_name or version
|
||||
logger.info('Creating "%s" tag...', tag_name)
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QNetworkReply>
|
||||
#include <QRegularExpression>
|
||||
#include <QVersionNumber>
|
||||
|
||||
const QString UpdateChecker::ErrorVersion("error");
|
||||
UpdateChecker* UpdateChecker::m_instance(nullptr);
|
||||
@@ -118,51 +119,46 @@ bool UpdateChecker::compareVersions(const QString& localVersion, const QString&
|
||||
return false;
|
||||
}
|
||||
|
||||
QRegularExpression verRegex(R"(^((?:\d+\.){2}\d+)(?:-(\w+?)(\d+)?)?$)");
|
||||
QRegularExpression verRegex(R"(^((?:\d+\.)*\d+)(?:-(alpha|beta|snapshot)?(\d+)?)?$)",
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
|
||||
auto lmatch = verRegex.match(localVersion);
|
||||
auto rmatch = verRegex.match(remoteVersion);
|
||||
|
||||
auto lVersion = lmatch.captured(1).split(".");
|
||||
auto lSuffix = lmatch.captured(2);
|
||||
auto lBetaNum = lmatch.captured(3);
|
||||
auto lVersion = QVersionNumber::fromString(lmatch.captured(1)).normalized();
|
||||
auto lReleaseType = lmatch.captured(2).toLower();
|
||||
auto lRevNum = lmatch.captured(3).toInt();
|
||||
|
||||
auto rVersion = rmatch.captured(1).split(".");
|
||||
auto rSuffix = rmatch.captured(2);
|
||||
auto rBetaNum = rmatch.captured(3);
|
||||
auto rVersion = QVersionNumber::fromString(rmatch.captured(1)).normalized();
|
||||
auto rReleaseType = rmatch.captured(2).toLower();
|
||||
auto rRevNum = rmatch.captured(3).toInt();
|
||||
|
||||
if (!lVersion.isEmpty() && !rVersion.isEmpty()) {
|
||||
if (lSuffix.compare("snapshot", Qt::CaseInsensitive) == 0) {
|
||||
// Snapshots are not checked for version updates
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check "-beta[X]" versions
|
||||
if (lVersion == rVersion && !lSuffix.isEmpty()) {
|
||||
// Check if stable version has been released or new beta is available
|
||||
// otherwise the version numbers are equal
|
||||
return rSuffix.isEmpty() || lBetaNum.toInt() < rBetaNum.toInt();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int l = lVersion[i].toInt();
|
||||
int r = rVersion[i].toInt();
|
||||
|
||||
if (l == r) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (l > r) {
|
||||
return false; // Installed version is newer than release
|
||||
} else {
|
||||
return true; // Installed version is outdated
|
||||
}
|
||||
}
|
||||
|
||||
return false; // Installed version is the same
|
||||
// Invalid version string
|
||||
if (lVersion.isNull() || rVersion.isNull()) {
|
||||
return false;
|
||||
}
|
||||
// Snapshots are not checked for version updates
|
||||
if (lReleaseType == "snapshot") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false; // Invalid version string
|
||||
if (lVersion != rVersion) {
|
||||
return lVersion < rVersion;
|
||||
}
|
||||
|
||||
// -alpha[X] < -beta[X]
|
||||
if (lReleaseType == "alpha" && rReleaseType == "beta") {
|
||||
return true;
|
||||
}
|
||||
// -beta1 < -beta2, -1 < -2
|
||||
if (lReleaseType == rReleaseType) {
|
||||
return lRevNum < rRevNum;
|
||||
}
|
||||
// -beta1 < -1
|
||||
if (!lReleaseType.isEmpty() && rReleaseType.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
UpdateChecker* UpdateChecker::instance()
|
||||
|
||||
+54
-28
@@ -29,34 +29,60 @@ void TestUpdateCheck::initTestCase()
|
||||
QLocale::setDefault(QLocale::c());
|
||||
}
|
||||
|
||||
void TestUpdateCheck::testCompareVersion_data()
|
||||
{
|
||||
QTest::addColumn<QString>("localVersion");
|
||||
QTest::addColumn<QString>("remoteVersion");
|
||||
QTest::addColumn<bool>("newer");
|
||||
|
||||
// Every ordered pair is also checked in reverse and against itself.
|
||||
const auto addPair = [](const char* name, const QString& older, const QString& newer) {
|
||||
QTest::newRow(name) << older << newer << true;
|
||||
QTest::newRow(qPrintable(QString(name) + "-reverse")) << newer << older << false;
|
||||
QTest::newRow(qPrintable(QString(name) + "-equal")) << older << older << false;
|
||||
};
|
||||
addPair("major", "2.8.0", "3.0.0");
|
||||
addPair("minor", "2.8.0", "2.9.0");
|
||||
addPair("patch", "2.8.0", "2.8.1");
|
||||
addPair("two-components", "2.8", "3.0.0");
|
||||
addPair("four-components", "2.8.0", "2.8.0.1");
|
||||
addPair("four-component-value", "2.8.0.2", "2.8.0.10");
|
||||
addPair("shorter-but-newer", "2.8.99.99", "2.9");
|
||||
addPair("revision", "2.8.0", "2.8.0-1");
|
||||
addPair("revision-increment", "2.8.0-1", "2.8.0-2");
|
||||
addPair("revision-numeric", "2.8.0-2", "2.8.0-10");
|
||||
addPair("beta-to-stable", "2.8.0-beta1", "2.8.0");
|
||||
addPair("alpha-to-beta", "2.8.0-alpha1", "2.8.0-beta1");
|
||||
addPair("alpha-to-beta-rank", "2.8.0-alpha10", "2.8.0-beta1");
|
||||
addPair("alpha-to-stable", "2.8.0-alpha10", "2.8.0");
|
||||
addPair("beta-number", "2.8.0-beta2", "2.8.0-beta10");
|
||||
addPair("bare-beta", "2.8.0-beta", "2.8.0-beta1");
|
||||
addPair("bare-alpha", "2.8.0-alpha", "2.8.0-alpha1");
|
||||
addPair("case-insensitive", "2.8.0-ALPHA10", "2.8.0-BETA1");
|
||||
addPair("newer-prerelease", "2.8.0", "2.8.1-beta1");
|
||||
addPair("beta-to-revision", "2.8.0-beta10", "2.8.0-1");
|
||||
addPair("normalized-prerelease", "2.8-beta1", "2.8.0");
|
||||
|
||||
QTest::newRow("trailing-zero") << QString("2.8") << QString("2.8.0") << false;
|
||||
QTest::newRow("trailing-zero-reverse") << QString("2.8.0") << QString("2.8") << false;
|
||||
QTest::newRow("zero-revision") << QString("2.8.0") << QString("2.8.0-0") << false;
|
||||
QTest::newRow("zero-revision-reverse") << QString("2.8.0-0") << QString("2.8.0") << false;
|
||||
QTest::newRow("local-snapshot") << QString("0.0.0-snapshot") << QString("3.0.0") << false;
|
||||
QTest::newRow("snapshot-case") << QString("2.8.0-SNAPSHOT") << QString("3.0.0") << false;
|
||||
|
||||
for (const auto& invalid :
|
||||
{"", "invalid", "2..8", "2.8.0-", "2.8.0-garbage", "2.8.0-beta1junk", "2.8.0-18446744073709551616"}) {
|
||||
QTest::newRow(qPrintable(QString("invalid-remote-%1").arg(invalid)))
|
||||
<< QString("2.8.0") << QString(invalid) << false;
|
||||
QTest::newRow(qPrintable(QString("invalid-local-%1").arg(invalid)))
|
||||
<< QString(invalid) << QString("2.8.0") << false;
|
||||
}
|
||||
}
|
||||
|
||||
void TestUpdateCheck::testCompareVersion()
|
||||
{
|
||||
// No upgrade
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.3.0"), QString("2.3.0")), false);
|
||||
|
||||
// First digit upgrade
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.4.0"), QString("3.0.0")), true);
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("3.0.0"), QString("2.4.0")), false);
|
||||
|
||||
// Second digit upgrade
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.3.4"), QString("2.4.0")), true);
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.4.0"), QString("2.3.4")), false);
|
||||
|
||||
// Third digit upgrade
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.3.0"), QString("2.3.1")), true);
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.3.1"), QString("2.3.0")), false);
|
||||
|
||||
// Beta builds
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.3.0"), QString("2.3.0-beta1")), false);
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.3.0"), QString("2.3.1-beta1")), true);
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.3.0-beta1"), QString("2.3.0")), true);
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.3.0-beta"), QString("2.3.0-beta1")), true);
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.3.0-beta1"), QString("2.3.0-beta")), false);
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.3.0-beta1"), QString("2.3.0-beta2")), true);
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.3.0-beta2"), QString("2.3.0-beta1")), false);
|
||||
|
||||
// Snapshot and invalid data
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.3.4-snapshot"), QString("2.4.0")), false);
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.4.0"), QString("invalid")), false);
|
||||
QCOMPARE(UpdateChecker::compareVersions(QString("2.4.0"), QString("")), false);
|
||||
QFETCH(QString, localVersion);
|
||||
QFETCH(QString, remoteVersion);
|
||||
QFETCH(bool, newer);
|
||||
QCOMPARE(UpdateChecker::compareVersions(localVersion, remoteVersion), newer);
|
||||
}
|
||||
@@ -26,6 +26,7 @@ class TestUpdateCheck : public QObject
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void testCompareVersion_data();
|
||||
void testCompareVersion();
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user