-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
88 lines (63 loc) · 2.04 KB
/
script.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
#!/usr/bin/env python3
import itertools
from packaging import version
import requests
import re
import yaml
import pprint
import os
RELS = {
"kubectl": {"1.13": ["v1.13.10"]}
}
def candidates(key: str, releases: list, match: list):
pattern = re.compile(match)
RELS.setdefault(key, [])
data = {}
for release in releases:
k = str(release["tag_name"])
ver = version.parse(k)
series = ver.base_version[0:3]
data.setdefault(series, [])
match = pattern.match(k)
if match is not None:
data[series].append((k, ver))
# Sort and select out latest 3 releases
for ver, items in data.items():
items.sort(key=lambda i: i[1])
latest = items[-3:]
candidates = list(map(lambda i: i[0], latest))
data[ver] = candidates
print("Latest %s" % list(candidates))
RELS[key] = data
def fetch_releases(repo):
user = os.environ.get("GITHUB_USER")
token = os.environ.get("GITHUB_TOKEN")
auth = None
if user and token:
auth=(user, token)
response = requests.get(
"https://api.github.com/repos/%s/releases" % repo,
auth=auth)
return response.json()
if __name__ == '__main__':
helm_rels = fetch_releases("helm/helm")
candidates("helm", helm_rels, "(v2.15|v3.\d+\.\d+(|-rc.\d)$)")
terraform_rels = fetch_releases("hashicorp/terraform")
candidates("terraform", terraform_rels, "v0.12.\d+$")
data = []
for t in ["helm", "kubectl", "terraform"]:
series = RELS[t]
releases = list(series.values())[0]
data.append(releases)
candidate_tuples = list(itertools.product(*data))
for candidate in candidate_tuples:
print(" ".join(candidate))
data = {
"helm-version": candidate[0],
"kubectl-version": candidate[1],
"tf-version": candidate[2][1:],
}
# print (data)
requests.post("http://el-docker-helm-kubectl-terraform-listener:8080", json=data)
# print(candidates)
# print(releases.keys())