-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathubiquity_buildsteps.py
147 lines (118 loc) · 6.9 KB
/
ubiquity_buildsteps.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/python3
import re
import time
from buildbot.plugins import *
from get_creds import creds
import aptly_steps
def set_deb_properties(name, distro, factory, arch, is_ros=False, ros_distro=""):
'''
This functions sets the dsc_path and deb_path buildbot properties for the build
For ROS packages this includes prepending 'ros-{ros_distro}'
'''
factory.addStep(steps.SetPropertyFromCommand(command="dpkg-parsechangelog --show-field Version",
property="deb_version", haltOnFailure=True))
# the Debian name has dashes instead of underscores
debian_name = "-".join(name.split("_"))
if is_ros:
factory.addStep(steps.SetProperty(property="deb_path",
value=util.Interpolate(f"/var/cache/pbuilder/result/{distro}/ros-{ros_distro}-{debian_name}_%(prop:deb_version)s_{arch}.deb")))
factory.addStep(steps.SetProperty(property="dsc_path",
value=util.Interpolate(f"../ros-{ros_distro}-{debian_name}_%(prop:deb_version)s.dsc")))
factory.addStep(steps.SetProperty(property="deb_package_name", value=f'ros-{ros_distro}-{debian_name}'))
else:
factory.addStep(steps.SetProperty(property="deb_path",
value=util.Interpolate(f"/var/cache/pbuilder/result/{distro}/{debian_name}_%(prop:deb_version)s_{arch}.deb")))
factory.addStep(steps.SetProperty(property="dsc_path",
value=util.Interpolate(f"../{debian_name}_%(prop:deb_version)s.dsc")))
factory.addStep(steps.SetProperty(property="deb_package_name", value=debian_name))
def cowbuilder_test_path(cow_config):
'''
Returns a path to a file, if that exists then the builder already exists
'''
envre = re.compile(r'''^([^\s=]+)=(?:[\s"']*)(.+?)(?:[\s"']*)$''')
result = {}
with open(cow_config) as ins:
for line in ins:
match = envre.match(line)
if match is not None:
result[match.group(1)] = match.group(2)
# Return a path to a file that would exist if the cowbuilder was already created
return result['BASEPATH'] + '/etc/os-release'
def cowbuilder(distro, arch, factory):
'''
Uses cowbuilder to build a dsc file into debs.
The dsc_path property must be set
'''
cow_config = f"cowbuilder/{distro}-cowbuilder-{arch}"
cow_test = cowbuilder_test_path(cow_config)
factory.addStep(steps.FileDownload(mastersrc=cow_config, workerdest=f"{distro}-cowbuilder-{arch}"))
factory.addStep(steps.FileDownload(mastersrc="cowbuilder/ros-archive-keyring.gpg", workerdest="ros-archive-keyring.gpg"))
factory.addStep(steps.FileDownload(mastersrc="cowbuilder/ubiquity-archive-keyring.gpg", workerdest="ubiquity-archive-keyring.gpg"))
# Short shell invocation to create the cowbuilder if it doesn't exist already
factory.addStep(steps.ShellCommand(
command=f"[ -f {cow_test} ] || sudo cowbuilder --create --config {distro}-cowbuilder-{arch}",
description="Create Cowbuilder"
))
factory.addStep(steps.ShellCommand(command=['sudo', 'cowbuilder', '--configfile',
f'{distro}-cowbuilder-{arch}', '--update'], description="Update Cowbuilder"))
factory.addStep(steps.ShellCommand(command=['sudo', 'cowbuilder', '--configfile',
f'{distro}-cowbuilder-{arch}', '--build', util.Property('dsc_path')], description="Build Deb"))
def single_ros_deb(name, release_repo, distro, ros_distro, arch, factory):
factory.addStep(steps.Git(repourl=release_repo,
branch=f'debian/{ros_distro}/{distro}/{name}', method='clobber', mode='full', alwaysUseLatest=True))
factory.addStep(steps.ShellCommand(command=['gbp', 'buildpackage', '-S', '-us', '-uc', '-d', '', '--git-ignore-new', '--git-ignore-branch'],
description="Generate Source Deb", haltOnFailure=True))
set_deb_properties(name, distro, factory, arch, is_ros=True, ros_distro=ros_distro)
cowbuilder(distro, arch, factory)
aptly(distro, name, factory)
def single_ros_backport_deb(name, release_repo, distro, ros_distro, arch, factory):
factory.addStep(steps.Git(repourl=release_repo,
branch=f'debian/{ros_distro}/{distro}/{name}', method='clobber', mode='full', alwaysUseLatest=True))
factory.addStep(steps.ShellCommand(command=['dch','--local','~tbpo','--distribution', distro,"Temp Backport"],
description="Bump to backport version", haltOnFailure=True))
factory.addStep(steps.ShellCommand(command=['gbp', 'buildpackage', '-S', '-us', '-uc', '-d', '', '--git-ignore-new', '--git-ignore-branch'],
description="Generate Source Deb", haltOnFailure=True))
set_deb_properties(name, distro, factory, arch, is_ros=True, ros_distro=ros_distro)
cowbuilder(distro, arch, factory)
aptly(distro, name, factory)
def metapackage_ros_deb(name, packages, release_repo, distro, ros_distro, arch, factory):
# TODO Topological sort, right now we assume that the packages are already in sorted order
for package in packages:
single_ros_deb(package, release_repo, distro, ros_distro, arch, factory)
def metapackage_ros_backport_deb(name, packages, release_repo, distro, ros_distro, arch, factory):
# TODO Topological sort, right now we assume that the packages are already in sorted order
for package in packages:
single_ros_backport_deb(package, release_repo, distro, ros_distro, arch, factory)
def aptly(distro, name, factory):
aptly_url = 'https://aptly.ubiquityrobotics.com/'
aptly_url_creds = 'https://' + creds.aptly[0] + ':' + creds.aptly[1] + '@aptly.ubiquityrobotics.com/'
building_repo = f"{distro}-main-building"
testing_repo = f"{distro}-main-testing"
# Due to a lack of foresight the xenial repos don't have the distro name
if distro == "xenial":
building_repo = "main-building"
testing_repo = "main-testing"
dir_name = f"{distro}__{name}"
factory.addStep(steps.ShellSequence(
commands = [
util.ShellArg(command=['curl', '-X', 'POST', '-F', util.Interpolate('file=@%(prop:deb_path)s'),
aptly_url_creds + 'api/files/' + dir_name
]),
util.ShellArg(command=['curl', '-X', 'POST', aptly_url_creds + f'api/repos/{building_repo}/file/' + dir_name])
],
description='Push deb to building',
descriptionDone='Pushed deb to building'
))
factory.addStep(aptly_steps.AptlyUpdatePublishStep(
aptly_url, creds.aptly,
f'filesystem:www:building/{distro}'
))
factory.addStep(aptly_steps.AptlyCopyPackageStep(
aptly_url, creds.aptly,
building_repo, testing_repo,
util.Interpolate('Name (=%(prop:deb_package_name)s), Version (=%(prop:deb_version)s)')
))
factory.addStep(aptly_steps.AptlyUpdatePublishStep(
aptly_url, creds.aptly,
f'filesystem:www:ubiquity-testing/{distro}'
))