Add a small next_build script

This script queries for the number of build made with the latest
version in koji and change the release to either the number of
builds or do current_release+1 (for the situation where the current
release is higher than the number of builds made in koji).

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
This commit is contained in:
Pierre-Yves Chibon 2020-01-28 15:39:10 +01:00
parent 1758b94c5e
commit 7d07df40ce

68
next_build.py Normal file
View file

@ -0,0 +1,68 @@
#!/usr/bin/python3
import datetime
import logging
import os
import subprocess
import sys
import textwrap
import pygit2
_log = logging.getLogger(__name__)
def run_command(command, cwd=None):
""" Run the specified command in a specific working directory if one
is specified.
"""
output = None
try:
output = subprocess.check_output(
command, cwd=cwd, stderr=subprocess.PIPE
)
except subprocess.CalledProcessError as e:
_log.error(
"Command `{}` return code: `{}`".format(
" ".join(command), e.returncode
)
)
_log.error("stdout:\n-------\n{}".format(e.stdout))
_log.error("stderr:\n-------\n{}".format(e.stderr))
raise Exception("Command failed to run")
return output
def main(args):
""" Main method. """
package = args[0]
dist = args[1]
cmd = f"koji list-builds --package={package} --state=COMPLETE -r --quiet"
rows = run_command(cmd.split()).decode("utf-8")
builds = [row.strip().split()[0] for row in rows.split("\n") if row.strip()]
n_builds = 1
last_build = None
nv = None
for build in builds:
if dist in build:
if n_builds == 1:
last_build = build
nv = last_build.rsplit("-", 1)[0]
if build.startswith(nv):
n_builds += 1
print(f"Last build: {last_build}")
last_build = last_build.rsplit(f".{dist}", 1)[0]
rel = last_build.rsplit("-", 1)[-1]
try:
rel = int(rel)
n_builds = max([rel+1, n_builds])
except Exception:
pass
print(f"Next build: {nv}-{n_builds}.{dist}")
if __name__ == '__main__':
main(sys.argv[1:])