blob: 7c029049502b7e05a03c50137172bb69ea735a0f (
plain) (
blame)
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
|
#!/usr/bin/env python3
from decimal import Decimal, ROUND_HALF_UP
import get_current_build_size
import get_main_build_size
import humanize
import os
# Форматирование числа
def format_number(num):
return humanize.intcomma(num).replace(",", " ")
def bytes_to_human_iec(num):
return humanize.naturalsize(num, binary=True)
def main():
yellow_treshold = int(os.environ.get("yellow_treshold"))
red_treshold = int(os.environ.get("red_treshold"))
branch = os.environ.get("branch_to_compare")
current_pr_commit_sha = os.environ.get("commit_git_sha")
current_sizes_result = get_current_build_size.get_build_size()
main_sizes_result = get_main_build_size.get_build_size()
if main_sizes_result and current_sizes_result:
main_github_sha = main_sizes_result["github_sha"]
main_size_bytes = int(main_sizes_result["size_bytes"])
main_size_stripped_bytes = int(main_sizes_result["size_stripped_bytes"])
current_size_bytes = int(current_sizes_result["size_bytes"])
current_size_stripped_bytes = int(current_sizes_result["size_stripped_bytes"])
bytes_diff = current_size_bytes - main_size_bytes
stripped_bytes_diff = current_size_stripped_bytes - main_size_stripped_bytes
diff_perc = Decimal(bytes_diff * 100 / main_size_bytes).quantize(
Decimal(".001"), rounding=ROUND_HALF_UP
)
stripped_diff_perc = Decimal(
stripped_bytes_diff * 100 / main_size_stripped_bytes
).quantize(Decimal(".001"), rounding=ROUND_HALF_UP)
human_readable_size = bytes_to_human_iec(current_size_bytes)
human_readable_size_diff = bytes_to_human_iec(bytes_diff)
human_readable_stripped_size_diff = bytes_to_human_iec(stripped_bytes_diff)
if bytes_diff > 0:
sign = "+"
if bytes_diff >= red_treshold:
color = "red"
summary_core = f" >= {bytes_to_human_iec(red_treshold)} vs {branch}: **Alert**"
elif bytes_diff >= yellow_treshold:
color = "yellow"
summary_core = f" >= {bytes_to_human_iec(yellow_treshold)} vs {branch}: **Warning**"
else:
color = "green"
summary_core = f" < {bytes_to_human_iec(yellow_treshold)} vs {branch}: **OK**"
else:
sign = ""
color = "green"
summary_core = f" <= 0 Bytes vs {branch}: **OK**"
if stripped_diff_perc > 0:
stripped_sign = "+"
else:
stripped_sign = ""
summary_start = f"ydbd size **{human_readable_size}** changed by **{sign}{human_readable_size_diff}**, which is"
summary = f"{summary_start}{summary_core}"
comment = (
f"{summary}\n"
f"|[ydbd size dash](https://datalens.yandex/cu6hzmpaki700)|{branch}: {main_github_sha} |merge: {current_pr_commit_sha} |diff | diff %%|\n"
f"|:--- | ---: | ---: | ---: | ---: |\n"
f"|ydbd size|**{format_number(main_size_bytes)}** Bytes |**{format_number(current_size_bytes)}** Bytes|**{sign}{human_readable_size_diff}**|**{sign}{diff_perc}%%**|\n"
f"|ydbd stripped size|**{format_number(main_size_stripped_bytes)}** Bytes|**{format_number(current_size_stripped_bytes)}** Bytes|**{stripped_sign}{human_readable_stripped_size_diff}**|**{stripped_sign}{stripped_diff_perc}%%**|\n\n"
)
print(f"{color};;;{comment}")
else:
print(
f"Error: Cant get build data: {branch}_sizes_result = {main_sizes_result}, current_sizes_result = {current_sizes_result}"
)
if __name__ == "__main__":
main()
|