1111import subprocess
1212import tempfile
1313import git
14+ import packaging
1415import redis
16+ from packaging import version
1517
1618# logging settings
1719from redisbench_admin .cli import populate_with_poetry_data
@@ -65,7 +67,24 @@ def main():
6567 )
6668 parser .add_argument ("--redis_repo" , type = str , default = None )
6769 parser .add_argument ("--trigger-unstable-commits" , type = bool , default = True )
68- parser .add_argument ("--dry-run" , type = bool , default = False )
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+ )
6988 args = parser .parse_args ()
7089 redisDirPath = args .redis_repo
7190 cleanUp = False
@@ -96,19 +115,57 @@ def main():
96115 )
97116 )
98117 repo = git .Repo (redisDirPath )
99- Commits = []
100- for commit in repo .iter_commits ():
101- if (
102- args .from_date
103- <= datetime .datetime .utcfromtimestamp (commit .committed_datetime .timestamp ())
104- <= args .to_date
105- ):
106- print (commit .summary )
107- Commits .append (commit )
118+
119+ commits = []
120+ if args .use_commits :
121+ for commit in repo .iter_commits ():
122+ if (
123+ args .from_date
124+ <= datetime .datetime .utcfromtimestamp (
125+ commit .committed_datetime .timestamp ()
126+ )
127+ <= args .to_date
128+ ):
129+ print (commit .summary )
130+ commits .append ({"git_hash" : commit .hexsha , "git_branch" : args .branch })
131+ if args .use_tags :
132+ tags = sorted (repo .tags , key = lambda t : t .commit .committed_datetime )
133+ for tag in tags :
134+ if (
135+ args .from_date
136+ <= datetime .datetime .utcfromtimestamp (
137+ tag .commit .committed_datetime .timestamp ()
138+ )
139+ <= args .to_date
140+ ):
141+
142+ try :
143+ version .Version (tag .name )
144+ git_version = tag .name
145+ print (
146+ "Commit summary: {}. Extract semver: {}" .format (
147+ tag .commit .summary , git_version
148+ )
149+ )
150+ # head = repo.lookup_reference(tag.commit).resolve()
151+ commits .append (
152+ {"git_hash" : tag .commit .hexsha , "git_version" : git_version }
153+ )
154+ except packaging .version .InvalidVersion :
155+ logging .info (
156+ "Ignoring tag {} given we were not able to extract commit or version info from it." .format (
157+ tag .name
158+ )
159+ )
160+ pass
161+
162+ by_description = "n/a"
163+ if args .use_commits :
164+ by_description = "from branch {}" .format (args .branch )
165+ if args .use_tags :
166+ by_description = "by tags"
108167 logging .info (
109- "Will trigger {} distinct {} branch commit tests." .format (
110- len (Commits ), args .branch
111- )
168+ "Will trigger {} distinct tests {}." .format (len (commits ), by_description )
112169 )
113170
114171 if args .dry_run is False :
@@ -120,7 +177,7 @@ def main():
120177 decode_responses = False ,
121178 )
122179 for rep in range (0 , 1 ):
123- for commit in Commits :
180+ for cdict in commits :
124181 (
125182 result ,
126183 error_msg ,
@@ -129,16 +186,16 @@ def main():
129186 binary_key ,
130187 binary_value ,
131188 ) = get_commit_dict_from_sha (
132- commit . hexsha , "redis" , "redis" , {} , True , args .gh_token
189+ cdict [ "git_hash" ] , "redis" , "redis" , cdict , True , args .gh_token
133190 )
134191 binary_exp_secs = 24 * 7 * 60 * 60
135192 if result is True :
136193 result , reply_fields , error_msg = request_build_from_commit_info (
137194 conn , commit_dict , {}, binary_key , binary_value , binary_exp_secs
138195 )
139196 logging .info (
140- "Successfully requested a build for commit: {}. Request stream id: {}. Commit summary: {} " .format (
141- commit . hexsha , reply_fields ["id" ], commit . summary
197+ "Successfully requested a build for commit: {}. Request stream id: {}." .format (
198+ cdict [ "git_hash" ] , reply_fields ["id" ]
142199 )
143200 )
144201 else :
0 commit comments