smeserver-koji/plugins/tag2distrepo/tag2distrepo.py

80 lines
2.7 KiB
Python
Raw Normal View History

2024-09-27 10:19:51 +02:00
# Koji tag2distrepo hub plugin
# Copyright (c) 2019 Red Hat, Inc.
# This callback automatically schedules distrepo tasks based on a tags config
#
# Authors:
# Patrick Uiterwijk <puiterwijk@redhat.com>
from __future__ import absolute_import
from koji.plugin import callback
from kojihub import dist_repo_init, make_task, readTaggedRPMS, write_signed_rpm
import logging
@callback('postTag')
def tag2distrepo(cbtype, tag, build, user, force=False):
logger = logging.getLogger('koji.plugin.tag2distrepo')
if not tag['extra'].get("tag2distrepo.enabled"):
logger.debug("No tag2distrepo enabled for tag %s" % tag['name'])
return
if not tag['arches']:
raise ValueError("Tag %s has no arches configured but tag2distrepo is enabled" % tag['name'])
keys = tag['extra'].get("tag2distrepo.keys", '').split()
2024-10-01 03:19:34 +02:00
compfile = tag['extra'].get("tag2distrepo.comp", 'none')
inherit = tag['extra'].get("tag2distrepo.inherit", False)
latest = tag['extra'].get("tag2distrepo.latest", False)
split_debuginfo = tag['extra'].get("tag2distrepo.split_debuginfo", False)
2024-10-21 08:01:48 +02:00
skip_missing = tag['extra'].get("tag2distrepo.skip_missing_signatures", False)
2024-09-27 10:19:51 +02:00
if keys:
logger.debug("Ensuring signed RPMs are written out")
[rpms, _] = readTaggedRPMS(tag['id'], rpmsigs=True)
for rpm in rpms:
for key in keys:
if rpm['sigkey'] == key:
write_signed_rpm(rpm['id'], key, False)
2024-10-01 03:19:34 +02:00
if tag['extra'].get("tag2distrepo.allow_missing_signatures"):
task_opts = {
'arch': tag['arches'].split(),
'comp': compfile,
'delta': [],
'event': None,
'inherit': inherit,
'latest': latest,
'multilib': False,
'split_debuginfo': split_debuginfo,
'skip_missing_signatures': skip_missing,
'allow_missing_signatures': True,
}
else:
task_opts = {
'arch': tag['arches'].split(),
'comp': compfile,
'delta': [],
'event': None,
'inherit': inherit,
'latest': latest,
'multilib': False,
'split_debuginfo': split_debuginfo,
'skip_missing_signatures': skip_missing,
'allow_missing_signatures': not keys,
}
2024-09-27 10:19:51 +02:00
logging.debug(
"Scheduling distRepo for tag %s, keys %s",
tag['name'],
keys,
)
repo_id, event_id = dist_repo_init(tag['name'], keys, task_opts)
task_opts['event'] = event_id
task_id = make_task(
'distRepo',
[tag['name'], repo_id, keys, task_opts],
priority=15,
channel='createrepo',
)
logging.info("distRepo task %d scheduled for tag %s" % (task_id, tag['name']))