From 8a86f38bca61ab67dcc137c4966f32b3dc2251d9 Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Wed, 7 Aug 2024 20:14:45 -0700 Subject: [PATCH] Fix is_maintenance_branch heuristic This was broken because Nix language's version comparison does not know how to deal with versions like -rc1 and considers them newer, which is in this case not desirable. That in turn led to not tagging 2.90.0 docker images as "latest" since the heuristic was wrong. This commit also adds some more cross-checking and failsafes in case the person running releng does not have a local main branch that is up to date. Fixes: https://git.lix.systems/lix-project/lix/issues/443 Change-Id: I537103ebab58ae978c00e06972abe14432dd9c80 --- package.nix | 1 + releng/gitutils.xsh | 37 ++++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/package.nix b/package.nix index be2f0010d..c32539303 100644 --- a/package.nix +++ b/package.nix @@ -423,6 +423,7 @@ stdenv.mkDerivation (finalAttrs: { p.python-frontmatter p.requests p.xdg-base-dirs + p.packaging (p.toPythonModule xonsh.passthru.unwrapped) ] ); diff --git a/releng/gitutils.xsh b/releng/gitutils.xsh index e18b4da5f..d3b3774c0 100644 --- a/releng/gitutils.xsh +++ b/releng/gitutils.xsh @@ -1,11 +1,24 @@ import subprocess -import json +from packaging.version import Version from .version import VERSION +def remote_is_plausible(url: str) -> bool: + return ('git.lix.systems' in url and 'lix-project/lix' in url) or ('gerrit.lix.systems' in url and url.endswith('lix')) + + def version_compare(v1: str, v2: str): - return json.loads($(nix-instantiate --eval --json --argstr v1 @(v1) --argstr v2 @(v2) --expr '{v1, v2}: builtins.compareVersions v1 v2')) + v1 = Version(v1) + v2 = Version(v2) + if v1 < v2: + return -1 + elif v1 > v2: + return 1 + elif v1 == v2: + return 0 + else: + raise ValueError('these versions are beyond each others celestial plane') def latest_tag_on_branch(branch: str) -> str: @@ -13,16 +26,18 @@ def latest_tag_on_branch(branch: str) -> str: def is_maintenance_branch(branch: str) -> bool: - try: - main_tag = latest_tag_on_branch('main') - current_tag = latest_tag_on_branch(branch) + """ + Returns whether the given branch is probably a maintenance branch. - return version_compare(current_tag, main_tag) < 0 - except subprocess.CalledProcessError: - # This is the case before Lix releases 2.90, since main *has* no - # release tag on it. - # FIXME: delete this case after 2.91 - return False + This uses a heuristic: `main` should have a newer tag than a given + maintenance branch if there has been a major release since that maintenance + branch. + """ + assert remote_is_plausible($(git remote get-url origin).strip()) + main_tag = latest_tag_on_branch('origin/main') + current_tag = latest_tag_on_branch(branch) + + return version_compare(current_tag, main_tag) < 0 def verify_are_on_tag():