-
Notifications
You must be signed in to change notification settings - Fork 22
/
update_config.py
80 lines (64 loc) · 2.78 KB
/
update_config.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
import copy
import json
import os
import sys
import urllib.parse
from pathlib import Path
import dateutil.parser
import git
from hammock import Hammock as hammock
from config_mgmt import save_config
token = sys.argv[1].strip()
config: dict = json.load(Path("Config/config.json").open())
plugins = json.load(Path("plugins.json").open())
# version 2 to 3
if config["_version"] == 2:
def add_author_date(name, version):
if version.get("date_authored", None):
return version
else:
organization = repo = None
for plugin in plugins["Plugins"]:
if name == "AppleSupportPkg" or name == "BT4LEContinuityFixup":
repo = name
organization = "acidanthera"
break
elif name == "NoTouchID":
repo = name
organization = "al3xtjames"
break
if plugin["Name"] == name:
organization, repo = plugin["URL"].strip().replace("https://github.com/", "").split("/")
break
if not repo:
print("Product " + name + " not found")
raise Exception
commit_date = dateutil.parser.parse(
json.loads(hammock("https://api.github.com").repos(organization, repo).commits(version["commit"]["sha"]).GET(auth=("github-actions", token)).text)["commit"]["author"]["date"]
)
version["date_authored"] = commit_date.isoformat()
return version
config = {i: v for i, v in config.items() if not i.startswith("_")}
for i in config:
for j, item in enumerate(config[i]["versions"]):
config[i]["versions"][j] = add_author_date(i, item)
print(f"Added {config[i]['versions'][j]['date_authored']} for {i} {config[i]['versions'][j]['commit']['sha']}")
for i in config:
for j, item in enumerate(config[i]["versions"]):
if not config[i]["versions"][j].get("date_committed"):
config[i]["versions"][j]["date_committed"] = config[i]["versions"][j].pop("datecommitted")
if not config[i]["versions"][j].get("date_built"):
config[i]["versions"][j]["date_built"] = config[i]["versions"][j].pop("dateadded")
config[i]["versions"].sort(key=lambda x: (x["date_committed"], x["date_authored"]), reverse=True)
config["_version"] = 3
# version 3 to 4
# nothing changed, but the other json files were added
if config["_version"] == 3:
config["_version"] = 4
save_config(config)
if os.environ.get("PROD", "false") == "true":
repo = git.Repo("Config")
if repo.is_dirty(untracked_files=True):
repo.git.add(all=True)
repo.git.commit(message="Deploying to builds")
repo.git.push()