-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathout
executable file
·78 lines (64 loc) · 2.38 KB
/
out
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
#!/usr/bin/python3
# This file is part of concourse-lp-livefs-resource
#
# Copyright 2023 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License version 3, as published by
# the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import json
import lputils
import time
payload = json.load(sys.stdin)
src = payload["source"]
params = payload.get("params", {})
livefs = src.get("livefs")
arch = src.get("arch", "amd64")
oauth_consumer_key = src.get("oauth_consumer_key")
oauth_token = src.get("oauth_token")
oauth_token_secret = src.get("oauth_token_secret")
ppa = params.get("ppa")
pocket = params.get("pocket", "Release")
metadata = params.get("metadata", {})
owner, _, distro, series, name = livefs.split("/")
if owner.startswith("~"):
owner = owner[1:]
lp, auth = lputils.login_with_oauth(oauth_consumer_key, oauth_token, oauth_token_secret)
distro = lp.distributions[distro]
if ppa:
archive = lp.archives.getByReference(reference=ppa)
else:
archive = distro.main_archive
series = distro.getSeries(name_or_version=series)
das = series.getDistroArchSeries(archtag=arch)
f = lp.livefses.getByName(distro_series=series, owner=lp.people[owner], name=name)
build = f.requestBuild(
archive=archive,
distro_arch_series=das,
pocket=pocket.title(),
metadata_override=metadata,
)
print(f"weblink: {build.web_link}", file=sys.stderr)
while not build.datebuilt or build.buildstate == "Uploading build":
print(f"buildstate: {build.buildstate}", file=sys.stderr)
time.sleep(60)
build = lp.load(str(build)) # reload a resource
if build.buildstate != "Successfully built":
print(f"ERROR: build {build.web_link} finished with \"{build.buildstate}\"", file=sys.stderr)
exit(1)
print(f"build {build.web_link} finished", file=sys.stderr)
result = {
"version": {"ref": str(build)},
"metadata": [{"name": "link", "value": build.web_link}],
}
json.dump(result, sys.stdout)
print()