20
20
21
21
STATUS_BUCKET = 'oss-fuzz-build-logs'
22
22
SCRIPT_DIR = os .path .dirname (os .path .abspath (__file__ ))
23
+ BADGE_DIR = 'badges/'
23
24
RETRY_COUNT = 3
24
25
RETRY_WAIT = 5
25
26
MAX_BUILD_RESULTS = 2000
@@ -173,6 +174,45 @@ def update_build_status(
173
174
upload_status (successes , failures , status_filename )
174
175
175
176
177
+ def update_build_badges (builds , projects , build_tag , coverage_tag ):
178
+ for project in projects :
179
+ last_build = find_last_build (builds , project , build_tag )
180
+ last_coverage_build = find_last_build (builds , project , coverage_tag )
181
+ if not last_build or not last_coverage_build :
182
+ continue
183
+
184
+ badge = 'building'
185
+ if not is_build_successful (last_coverage_build ):
186
+ badge = 'coverage_failing'
187
+ if not is_build_successful (last_build ):
188
+ badge = 'failing'
189
+
190
+ print ("[badge] {}: {}" .format (project , badge ))
191
+
192
+ storage_client = storage .Client ()
193
+ status_bucket = storage_client .get_bucket (STATUS_BUCKET )
194
+
195
+ # Supported image types for badges
196
+ image_types = {
197
+ 'svg' : 'image/svg+xml' ,
198
+ 'png' : 'image/png'
199
+ }
200
+ for extension , mime_type in image_types .items ():
201
+ badge_name = '{badge}.{extension}' .format (
202
+ badge = badge , extension = extension )
203
+ # Retrieve the image relative to this script's location
204
+ badge_file = os .path .join (
205
+ SCRIPT_DIR , 'badge_images' , image_directory , badge_name )
206
+
207
+ # The uploaded blob name should look like `badges/project.png`
208
+ blob_name = '{badge_dir}{project_name}.{extension}' .format (
209
+ badge_dir = BADGE_DIR , project_name = project ,
210
+ extension = extension )
211
+
212
+ badge_blob = status_bucket .blob (blob_name )
213
+ badge_blob .upload_from_filename (badge_file , content_type = mime_type )
214
+
215
+
176
216
def main ():
177
217
if len (sys .argv ) != 2 :
178
218
usage ()
@@ -190,6 +230,10 @@ def main():
190
230
build_and_run_coverage .COVERAGE_BUILD_TAG ,
191
231
status_filename = 'status-coverage.json' )
192
232
233
+ update_build_badges (builds , projects ,
234
+ build_tag = build_project .FUZZING_BUILD_TAG ,
235
+ coverage_tag = build_and_run_coverage .COVERAGE_BUILD_TAG )
236
+
193
237
194
238
if __name__ == '__main__' :
195
239
main ()
0 commit comments