-
Notifications
You must be signed in to change notification settings - Fork 1
/
check
executable file
·67 lines (53 loc) · 1.99 KB
/
check
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
#!/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
payload = json.load(sys.stdin)
cur_version = 0
src = payload["source"]
ver = payload.get("version")
if ver != None:
ref = ver["ref"]
cur_version = int(str(ref).split("/")[-1])
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")
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]
series = distro.getSeries(name_or_version=series)
f = lp.livefses.getByName(distro_series=series, owner=lp.people[owner], name=name)
result = [
{"ref": str(entry)}
for entry in f.completed_builds_collection
if entry.buildstate == "Successfully built"
and int(str(entry).split("/")[-1]) >= cur_version
]
if cur_version == 0:
# concourse ci doc:
# (version) will be omitted from the first request, in which case the
# resource should return the current version (not every version since the
# resource's inception).
result = result[0:1]
result.reverse() # the order is oldest first
json.dump(result, sys.stdout)
print()