-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprepare-release.py
executable file
·134 lines (102 loc) · 3.64 KB
/
prepare-release.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
#!/usr/bin/env python3
import os
import github
from ruamel.yaml import YAML
yaml = YAML(typ="rt")
yaml.default_flow_style = False
yaml.explicit_start = True
yaml.preserve_quotes = True
gh = github.Github()
release = os.environ.get("RELEASE")
# required mapping files
mapping_files = ["collections", "other", "roles"]
mappings = {}
for mapping in mapping_files:
with open(f"etc/{mapping}.yml", "r") as fp:
mappings = {**yaml.load(fp), **mappings}
# prepare base
with open(f"{release}/base.yml", "r") as fp:
data = yaml.load(fp)
with open(f"{release}/ceph.yml", "r") as fp:
data_ceph = yaml.load(fp)
with open(f"{release}/openstack.yml", "r") as fp:
data_openstack = yaml.load(fp)
# ceph: defaults, generics, ...
for name in ["defaults", "generics", "playbooks"]:
repository = gh.get_repo(mappings[name])
if data_ceph[f"{name}_version"] in ["main", "master"]:
try:
branch = repository.get_branch(data_ceph[f"{name}_version"])
data_ceph[f"{name}_version"] = branch.commit.sha
except:
print(
"branch %s for repository %s not found"
% (data_ceph[f"{name}_version"], mappings[name])
)
# openstack: defaults, generics, ...
for name in ["defaults", "generics", "playbooks"]:
repository = gh.get_repo(mappings[name])
if data_openstack[f"{name}_version"] in ["main", "master"]:
try:
branch = repository.get_branch(data_openstack[f"{name}_version"])
data_openstack[f"{name}_version"] = branch.commit.sha
except:
print(
"branch %s for repository %s not found"
% (data_openstack[f"{name}_version"], mappings[name])
)
# base: operations, defaults, ...
for name in ["defaults", "generics", "operations", "playbooks"]:
repository = gh.get_repo(mappings[name])
if data[f"{name}_version"] in ["main", "master"]:
try:
branch = repository.get_branch(data[f"{name}_version"])
data[f"{name}_version"] = branch.commit.sha
except:
print(
"branch %s for repository %s not found"
% (data[f"{name}_version"], mappings[name])
)
# base: prepare roles
for role in data["ansible_roles"]:
if (
role not in mappings
or not mappings[role]
or data["ansible_roles"][role] not in ["main", "master"]
):
continue
repository = gh.get_repo(mappings[role])
try:
branch = repository.get_branch(data["ansible_roles"][role])
data["ansible_roles"][role] = branch.commit.sha
except:
print(
"branch %s for repository %s not found"
% (data["ansible_roles"][role], mappings[role])
)
# base: prepare collections
for collection in data["ansible_collections"]:
if (
collection not in mappings
or not mappings[collection]
or data["ansible_collections"][collection] not in ["main", "master"]
):
continue
repository = gh.get_repo(mappings[collection])
try:
branch = repository.get_branch(data["ansible_collections"][collection])
data["ansible_collections"][collection] = branch.commit.sha
except:
print(
"branch %s for repository %s not found"
% (data["ansible_collections"][collection], mappings[collection])
)
# base: other
data["manager_version"] = release
# save files
with open(f"{release}/base.yml", "w") as fp:
yaml.dump(data, fp)
with open(f"{release}/ceph.yml", "w") as fp:
yaml.dump(data_ceph, fp)
with open(f"{release}/openstack.yml", "w") as fp:
yaml.dump(data_openstack, fp)