77import argparse
88import datetime
99import logging
10+ import re
1011import shutil
1112import subprocess
13+ import sys
1214import tempfile
1315import git
1416import packaging
1517import redis
1618from packaging import version
1719
18- # logging settings
19- from redisbench_admin .cli import populate_with_poetry_data
20- from redisbench_admin .run .common import get_start_time_vars
2120
21+ from redis_benchmarks_specification .__cli__ .args import spec_cli_args
2222from redis_benchmarks_specification .__common__ .builder_schema import (
2323 get_commit_dict_from_sha ,
2424 request_build_from_commit_info ,
2525)
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 ,
3230)
33- from redis_benchmarks_specification .__common__ .package import get_version_string
3431
32+ # logging settings
3533logging .basicConfig (
3634 format = "%(asctime)s %(levelname)-4s %(message)s" ,
3735 level = logging .INFO ,
3836 datefmt = "%Y-%m-%d %H:%M:%S" ,
3937)
4038
41- START_TIME_NOW_UTC , _ , _ = get_start_time_vars ()
42- START_TIME_LAST_YEAR_UTC = START_TIME_NOW_UTC - datetime .timedelta (days = 7 )
43-
4439
4540def main ():
4641 _ , _ , project_version = populate_with_poetry_data ()
@@ -49,43 +44,21 @@ def main():
4944 description = get_version_string (project_name , project_version ),
5045 formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
5146 )
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 )
8848 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 )
8962 redisDirPath = args .redis_repo
9063 cleanUp = False
9164 if redisDirPath is None :
@@ -115,9 +88,8 @@ def main():
11588 )
11689 )
11790 repo = git .Repo (redisDirPath )
118-
11991 commits = []
120- if args .use_commits :
92+ if args .use_branch :
12193 for commit in repo .iter_commits ():
12294 if (
12395 args .from_date
@@ -129,6 +101,17 @@ def main():
129101 print (commit .summary )
130102 commits .append ({"git_hash" : commit .hexsha , "git_branch" : args .branch })
131103 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+
132115 tags = sorted (repo .tags , key = lambda t : t .commit .committed_datetime )
133116 for tag in tags :
134117 if (
@@ -141,33 +124,38 @@ def main():
141124
142125 try :
143126 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 }
148143 )
149- )
150- # head = repo.lookup_reference(tag.commit).resolve()
151- commits .append (
152- {"git_hash" : tag .commit .hexsha , "git_version" : git_version }
153- )
154144 except packaging .version .InvalidVersion :
155145 logging .info (
156146 "Ignoring tag {} given we were not able to extract commit or version info from it." .format (
157147 tag .name
158148 )
159149 )
160150 pass
161-
162151 by_description = "n/a"
163- if args .use_commits :
152+ if args .use_branch :
164153 by_description = "from branch {}" .format (args .branch )
165154 if args .use_tags :
166155 by_description = "by tags"
167156 logging .info (
168157 "Will trigger {} distinct tests {}." .format (len (commits ), by_description )
169158 )
170-
171159 if args .dry_run is False :
172160 conn = redis .StrictRedis (
173161 host = args .redis_host ,
@@ -188,10 +176,14 @@ def main():
188176 ) = get_commit_dict_from_sha (
189177 cdict ["git_hash" ], "redis" , "redis" , cdict , True , args .gh_token
190178 )
191- binary_exp_secs = 24 * 7 * 60 * 60
192179 if result is True :
193180 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 ,
195187 )
196188 logging .info (
197189 "Successfully requested a build for commit: {}. Request stream id: {}." .format (
@@ -203,7 +195,6 @@ def main():
203195
204196 else :
205197 logging .info ("Skipping actual work trigger ( dry-run )" )
206-
207198 if cleanUp is True :
208199 logging .info ("Removing temporary redis dir {}." .format (redisDirPath ))
209200 shutil .rmtree (redisDirPath )
0 commit comments