7
7
import argparse
8
8
import datetime
9
9
import logging
10
+ import re
10
11
import shutil
11
12
import subprocess
13
+ import sys
12
14
import tempfile
13
15
import git
14
16
import packaging
15
17
import redis
16
18
from packaging import version
17
19
18
- # logging settings
19
- from redisbench_admin .cli import populate_with_poetry_data
20
- from redisbench_admin .run .common import get_start_time_vars
21
20
21
+ from redis_benchmarks_specification .__cli__ .args import spec_cli_args
22
22
from redis_benchmarks_specification .__common__ .builder_schema import (
23
23
get_commit_dict_from_sha ,
24
24
request_build_from_commit_info ,
25
25
)
26
- from redis_benchmarks_specification .__common__ .env import (
27
- GH_REDIS_SERVER_HOST ,
28
- GH_REDIS_SERVER_AUTH ,
29
- GH_REDIS_SERVER_USER ,
30
- GH_REDIS_SERVER_PORT ,
31
- GH_TOKEN ,
26
+ from redis_benchmarks_specification .__common__ .env import REDIS_BINS_EXPIRE_SECS
27
+ from redis_benchmarks_specification .__common__ .package import (
28
+ get_version_string ,
29
+ populate_with_poetry_data ,
32
30
)
33
- from redis_benchmarks_specification .__common__ .package import get_version_string
34
31
32
+ # logging settings
35
33
logging .basicConfig (
36
34
format = "%(asctime)s %(levelname)-4s %(message)s" ,
37
35
level = logging .INFO ,
38
36
datefmt = "%Y-%m-%d %H:%M:%S" ,
39
37
)
40
38
41
- START_TIME_NOW_UTC , _ , _ = get_start_time_vars ()
42
- START_TIME_LAST_YEAR_UTC = START_TIME_NOW_UTC - datetime .timedelta (days = 7 )
43
-
44
39
45
40
def main ():
46
41
_ , _ , project_version = populate_with_poetry_data ()
@@ -49,43 +44,21 @@ def main():
49
44
description = get_version_string (project_name , project_version ),
50
45
formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
51
46
)
52
- parser .add_argument ("--redis_host" , type = str , default = GH_REDIS_SERVER_HOST )
53
- parser .add_argument ("--branch" , type = str , default = "unstable" )
54
- parser .add_argument ("--gh_token" , type = str , default = GH_TOKEN )
55
- parser .add_argument ("--redis_port" , type = int , default = GH_REDIS_SERVER_PORT )
56
- parser .add_argument ("--redis_pass" , type = str , default = GH_REDIS_SERVER_AUTH )
57
- parser .add_argument ("--redis_user" , type = str , default = GH_REDIS_SERVER_USER )
58
- parser .add_argument (
59
- "--from-date" ,
60
- type = lambda s : datetime .datetime .strptime (s , "%Y-%m-%d" ),
61
- default = START_TIME_LAST_YEAR_UTC ,
62
- )
63
- parser .add_argument (
64
- "--to-date" ,
65
- type = lambda s : datetime .datetime .strptime (s , "%Y-%m-%d" ),
66
- default = START_TIME_NOW_UTC ,
67
- )
68
- parser .add_argument ("--redis_repo" , type = str , default = None )
69
- parser .add_argument ("--trigger-unstable-commits" , type = bool , default = True )
70
- parser .add_argument (
71
- "--use-tags" ,
72
- default = False ,
73
- action = "store_true" ,
74
- help = "Iterate over the git tags." ,
75
- )
76
- parser .add_argument (
77
- "--use-commits" ,
78
- default = False ,
79
- action = "store_true" ,
80
- help = "Iterate over the git commits." ,
81
- )
82
- parser .add_argument (
83
- "--dry-run" ,
84
- default = False ,
85
- action = "store_true" ,
86
- help = "Only check how many benchmarks we would trigger. Don't request benchmark runs at the end." ,
87
- )
47
+ parser = spec_cli_args (parser )
88
48
args = parser .parse_args ()
49
+
50
+ cli_command_logic (args , project_name , project_version )
51
+
52
+
53
+ def cli_command_logic (args , project_name , project_version ):
54
+ logging .info (
55
+ "Using: {project_name} {project_version}" .format (
56
+ project_name = project_name , project_version = project_version
57
+ )
58
+ )
59
+ if args .use_branch is False and args .use_tags is False :
60
+ logging .error ("You must specify either --use-tags or --use-branch flag" )
61
+ sys .exit (1 )
89
62
redisDirPath = args .redis_repo
90
63
cleanUp = False
91
64
if redisDirPath is None :
@@ -115,9 +88,8 @@ def main():
115
88
)
116
89
)
117
90
repo = git .Repo (redisDirPath )
118
-
119
91
commits = []
120
- if args .use_commits :
92
+ if args .use_branch :
121
93
for commit in repo .iter_commits ():
122
94
if (
123
95
args .from_date
@@ -129,6 +101,17 @@ def main():
129
101
print (commit .summary )
130
102
commits .append ({"git_hash" : commit .hexsha , "git_branch" : args .branch })
131
103
if args .use_tags :
104
+ tags_regexp = args .tags_regexp
105
+ if tags_regexp == ".*" :
106
+ logging .info (
107
+ "Acception all tags that follow semver between the timeframe. If you need further filter specify a regular expression via --tags-regexp"
108
+ )
109
+ else :
110
+ logging .info (
111
+ "Filtering all tags via a regular expression: {}" .format (tags_regexp )
112
+ )
113
+ tags_regex_string = re .compile (tags_regexp )
114
+
132
115
tags = sorted (repo .tags , key = lambda t : t .commit .committed_datetime )
133
116
for tag in tags :
134
117
if (
@@ -141,33 +124,38 @@ def main():
141
124
142
125
try :
143
126
version .Version (tag .name )
144
- git_version = tag .name
145
- print (
146
- "Commit summary: {}. Extract semver: {}" .format (
147
- tag .commit .summary , git_version
127
+ match_obj = re .search (tags_regex_string , tag .name )
128
+ if match_obj is None :
129
+ logging .info (
130
+ "Skipping {} given it does not match regex {}" .format (
131
+ tag .name , tags_regexp
132
+ )
133
+ )
134
+ else :
135
+ git_version = tag .name
136
+ print (
137
+ "Commit summary: {}. Extract semver: {}" .format (
138
+ tag .commit .summary , git_version
139
+ )
140
+ )
141
+ commits .append (
142
+ {"git_hash" : tag .commit .hexsha , "git_version" : git_version }
148
143
)
149
- )
150
- # head = repo.lookup_reference(tag.commit).resolve()
151
- commits .append (
152
- {"git_hash" : tag .commit .hexsha , "git_version" : git_version }
153
- )
154
144
except packaging .version .InvalidVersion :
155
145
logging .info (
156
146
"Ignoring tag {} given we were not able to extract commit or version info from it." .format (
157
147
tag .name
158
148
)
159
149
)
160
150
pass
161
-
162
151
by_description = "n/a"
163
- if args .use_commits :
152
+ if args .use_branch :
164
153
by_description = "from branch {}" .format (args .branch )
165
154
if args .use_tags :
166
155
by_description = "by tags"
167
156
logging .info (
168
157
"Will trigger {} distinct tests {}." .format (len (commits ), by_description )
169
158
)
170
-
171
159
if args .dry_run is False :
172
160
conn = redis .StrictRedis (
173
161
host = args .redis_host ,
@@ -188,10 +176,14 @@ def main():
188
176
) = get_commit_dict_from_sha (
189
177
cdict ["git_hash" ], "redis" , "redis" , cdict , True , args .gh_token
190
178
)
191
- binary_exp_secs = 24 * 7 * 60 * 60
192
179
if result is True :
193
180
result , reply_fields , error_msg = request_build_from_commit_info (
194
- conn , commit_dict , {}, binary_key , binary_value , binary_exp_secs
181
+ conn ,
182
+ commit_dict ,
183
+ {},
184
+ binary_key ,
185
+ binary_value ,
186
+ REDIS_BINS_EXPIRE_SECS ,
195
187
)
196
188
logging .info (
197
189
"Successfully requested a build for commit: {}. Request stream id: {}." .format (
@@ -203,7 +195,6 @@ def main():
203
195
204
196
else :
205
197
logging .info ("Skipping actual work trigger ( dry-run )" )
206
-
207
198
if cleanUp is True :
208
199
logging .info ("Removing temporary redis dir {}." .format (redisDirPath ))
209
200
shutil .rmtree (redisDirPath )
0 commit comments