Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[infra] Publish build badges on status page #2513

Merged
merged 3 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added infra/gcb/badge_images/building.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions infra/gcb/badge_images/building.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added infra/gcb/badge_images/coverage_failing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions infra/gcb/badge_images/coverage_failing.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added infra/gcb/badge_images/failing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions infra/gcb/badge_images/failing.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions infra/gcb/builds_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

STATUS_BUCKET = 'oss-fuzz-build-logs'
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
BADGE_DIR = 'badges/'
RETRY_COUNT = 3
RETRY_WAIT = 5
MAX_BUILD_RESULTS = 2000
Expand Down Expand Up @@ -173,6 +174,45 @@ def update_build_status(
upload_status(successes, failures, status_filename)


def update_build_badges(builds, projects, build_tag, coverage_tag):
for project in projects:
last_build = find_last_build(builds, project, build_tag)
last_coverage_build = find_last_build(builds, project, coverage_tag)
if not last_build or not last_coverage_build:
continue

badge = 'building'
if not is_build_successful(last_coverage_build):
badge = 'coverage_failing'
if not is_build_successful(last_build):
badge = 'failing'

print("[badge] {}: {}".format(project, badge))

storage_client = storage.Client()
status_bucket = storage_client.get_bucket(STATUS_BUCKET)

# Supported image types for badges
image_types = {
'svg': 'image/svg+xml',
'png': 'image/png'
}
for extension, mime_type in image_types.items():
badge_name = '{badge}.{extension}'.format(
badge=badge, extension=extension)
# Retrieve the image relative to this script's location
badge_file = os.path.join(
SCRIPT_DIR, 'badge_images', image_directory, badge_name)

# The uploaded blob name should look like `badges/project.png`
blob_name = '{badge_dir}{project_name}.{extension}'.format(
badge_dir=BADGE_DIR, project_name=project,
extension=extension)

badge_blob = status_bucket.blob(blob_name)
badge_blob.upload_from_filename(badge_file, content_type=mime_type)


def main():
if len(sys.argv) != 2:
usage()
Expand All @@ -190,6 +230,10 @@ def main():
build_and_run_coverage.COVERAGE_BUILD_TAG,
status_filename='status-coverage.json')

update_build_badges(builds, projects,
build_tag=build_project.FUZZING_BUILD_TAG,
coverage_tag=build_and_run_coverage.COVERAGE_BUILD_TAG)


if __name__ == '__main__':
main()