3
0
Fork 0
forked from mirrors/nixpkgs

gitlab: update.py: properly sort version numbers, ignore invalid versions

This commit is contained in:
Florian Klink 2019-05-03 20:18:14 +02:00
parent c53b8aa77b
commit 847eb76cf8

View file

@ -9,6 +9,7 @@ import logging
import subprocess import subprocess
import json import json
import pathlib import pathlib
from distutils.version import LooseVersion
from typing import Iterable from typing import Iterable
import requests import requests
@ -18,6 +19,7 @@ logger = logging.getLogger(__name__)
class GitLabRepo: class GitLabRepo:
version_regex = re.compile(r"^v\d+\.\d+\.\d+(\-rc\d+)?(\-ee)?")
def __init__(self, owner: str, repo: str): def __init__(self, owner: str, repo: str):
self.owner = owner self.owner = owner
self.repo = repo self.repo = repo
@ -31,8 +33,13 @@ class GitLabRepo:
r = requests.get(self.url + "/tags?format=atom", stream=True) r = requests.get(self.url + "/tags?format=atom", stream=True)
tree = ElementTree.fromstring(r.content) tree = ElementTree.fromstring(r.content)
return sorted((e.text for e in tree.findall( versions = [e.text for e in tree.findall('{http://www.w3.org/2005/Atom}entry/{http://www.w3.org/2005/Atom}title')]
'{http://www.w3.org/2005/Atom}entry/{http://www.w3.org/2005/Atom}title')), reverse=True) # filter out versions not matching version_regex
versions = filter(self.version_regex.match, versions)
# sort, but ignore v and -ee for sorting comparisons
versions.sort(key=lambda x: LooseVersion(x.replace("v", "").replace("-ee", "")), reverse=True)
return versions
def get_git_hash(self, rev: str): def get_git_hash(self, rev: str):
out = subprocess.check_output(['nix-prefetch-git', self.url, rev]) out = subprocess.check_output(['nix-prefetch-git', self.url, rev])
@ -202,7 +209,6 @@ def update_gitaly():
click.echo(f"Please update gitaly/default.nix to version {gitaly_server_version} and hash {gitaly_hash}") click.echo(f"Please update gitaly/default.nix to version {gitaly_server_version} and hash {gitaly_hash}")
@cli.command('update-gitlab-shell') @cli.command('update-gitlab-shell')
def update_gitlab_shell(): def update_gitlab_shell():
"""Update gitlab-shell""" """Update gitlab-shell"""