Skip to content

Commit 8776ec2

Browse files
ammaraskarinferno-chromium
authored andcommitted
[infra] Publish build badges on status page (#2513)
* [infra] Publish build badges on status page * Address feedback from github PR * Change success badge to 'fuzzing' and failing badge to 'build failing'
1 parent e4c5f42 commit 8776ec2

7 files changed

+47
-0
lines changed

infra/gcb/badge_images/building.png

2.95 KB
Loading

infra/gcb/badge_images/building.svg

+1
Loading
4.06 KB
Loading
Loading

infra/gcb/badge_images/failing.png

3.38 KB
Loading

infra/gcb/badge_images/failing.svg

+1
Loading

infra/gcb/builds_status.py

+44
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
STATUS_BUCKET = 'oss-fuzz-build-logs'
2222
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
23+
BADGE_DIR = 'badges/'
2324
RETRY_COUNT = 3
2425
RETRY_WAIT = 5
2526
MAX_BUILD_RESULTS = 2000
@@ -173,6 +174,45 @@ def update_build_status(
173174
upload_status(successes, failures, status_filename)
174175

175176

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+
176216
def main():
177217
if len(sys.argv) != 2:
178218
usage()
@@ -190,6 +230,10 @@ def main():
190230
build_and_run_coverage.COVERAGE_BUILD_TAG,
191231
status_filename='status-coverage.json')
192232

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+
193237

194238
if __name__ == '__main__':
195239
main()

0 commit comments

Comments
 (0)