-
Notifications
You must be signed in to change notification settings - Fork 1
/
zuul_rpm_publish.py
executable file
·90 lines (78 loc) · 3.45 KB
/
zuul_rpm_publish.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/env python
#
# Copyright 2017 Red Hat
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import argparse
import glob
import re
import os
import zuul_koji_lib
class ZuulRpmPublish(zuul_koji_lib.App):
def usage(self):
p = argparse.ArgumentParser(description='Zuul RPM publish')
p.add_argument("--project", default=os.environ.get("ZUUL_PROJECT"))
p.add_argument("--pipeline", default=os.environ.get("ZUUL_PIPELINE"))
p.add_argument("--testing-repo")
return p
def get_package_name(self, project):
oproject = None
if project.endswith("-distgit"):
oproject = project
project = project[:-8]
elif project.startswith("rpms/python-"):
return project.replace("rpms/python-", "python3-")
elif project.startswith("rpms/"):
return project.replace("rpms/", "")
for package in self.distro_info["packages"]:
package_name = None
if project == package["name"]:
package_name = os.path.basename(project)
if oproject == package.get("distgit", ""):
package_name = os.path.basename(project)
if package_name:
if package.get("scl"):
return "%s-%s" % (package["scl"], package_name)
return package_name
raise RuntimeError("Couln't find project %s in distro info" % project)
def main(self, args):
package_name = self.get_package_name(args.project)
if args.pipeline == "tag" or args.pipeline == "local":
# srpm has been built locally
srpms = glob.glob("zuul-rpm-build/*.src.rpm")
else:
srpms = zuul_koji_lib.get_srpms(args.testing_repo)
srpms = filter(lambda x: re.match(r"^%s-\d.*" % package_name, x),
srpms)
if len(srpms) != 1:
raise RuntimeError("Multiple package available... %s" % srpms)
srpm = srpms[0]
if not os.path.isfile(srpm):
srpm_url = "%s/%s" % (args.testing_repo, srpm)
zuul_koji_lib.download(self.log, srpm_url)
self.execute(["koji", "--authtype=ssl", "add-pkg", "--owner=sfci",
self.distro_info["koji-target"], package_name])
try:
self.execute(["koji", "--authtype=ssl", "build", "--noprogress",
"--wait", self.distro_info["koji-target"], srpm])
except RuntimeError:
# If the build task was unable to build the pkg for other reason
# that a "Build already exists" error then the following task will
# fail too.
print("Build failed but if it was because of NVR already built")
print("then try to add it to the tag.")
self.execute(["koji", "--authtype=ssl", "tag-build",
self.distro_info["koji-target"],
srpm.replace('.src.rpm', '')])
if __name__ == "__main__":
ZuulRpmPublish()