11
11
import subprocess
12
12
import tempfile
13
13
import git
14
+ import packaging
14
15
import redis
16
+ from packaging import version
15
17
16
18
# logging settings
17
19
from redisbench_admin .cli import populate_with_poetry_data
@@ -65,7 +67,24 @@ def main():
65
67
)
66
68
parser .add_argument ("--redis_repo" , type = str , default = None )
67
69
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
+ )
69
88
args = parser .parse_args ()
70
89
redisDirPath = args .redis_repo
71
90
cleanUp = False
@@ -96,19 +115,57 @@ def main():
96
115
)
97
116
)
98
117
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"
108
167
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 )
112
169
)
113
170
114
171
if args .dry_run is False :
@@ -120,7 +177,7 @@ def main():
120
177
decode_responses = False ,
121
178
)
122
179
for rep in range (0 , 1 ):
123
- for commit in Commits :
180
+ for cdict in commits :
124
181
(
125
182
result ,
126
183
error_msg ,
@@ -129,16 +186,16 @@ def main():
129
186
binary_key ,
130
187
binary_value ,
131
188
) = 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
133
190
)
134
191
binary_exp_secs = 24 * 7 * 60 * 60
135
192
if result is True :
136
193
result , reply_fields , error_msg = request_build_from_commit_info (
137
194
conn , commit_dict , {}, binary_key , binary_value , binary_exp_secs
138
195
)
139
196
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" ]
142
199
)
143
200
)
144
201
else :
0 commit comments