def main():
    global send_reminder_chat
    global lag_reminder_modules
    update_lang_version()

    updated_readme = get_updated_readme()

    # Write to local README file
    f = open(README_FILE, 'w')
    f.write(updated_readme)
    f.close()

    try:
        update_readme, commit = utils.commit_file(
            'ballerina-release', README_FILE, updated_readme,
            constants.DASHBOARD_UPDATE_BRANCH,
            '[Automated] Update extension dependency dashboard')
    except GithubException as e:
        print('Error occurred while committing README.md', e)
        sys.exit(1)

    try:
        image = Image.open(constants.PIE_CHART_IMAGE, mode='r')
        img_byte_arr = io.BytesIO()
        image.save(img_byte_arr, format='JPEG')

        if update_readme:
            utils.commit_image_file('ballerina-release',
                                    constants.PIE_CHART_IMAGE,
                                    img_byte_arr.getvalue(),
                                    constants.DASHBOARD_UPDATE_BRANCH,
                                    '[Automated] Update status pie chart')

    except GithubException as e:
        print('Error occurred while committing status pie chart', e)
        sys.exit(1)

    if update_readme:
        utils.open_pr_and_merge(
            'ballerina-release',
            '[Automated] Update Extension Dependency Dashboard',
            'Update extension dependency dashboard',
            constants.DASHBOARD_UPDATE_BRANCH)
        if send_reminder_chat == 'true' and len(lag_reminder_modules) > 0:
            chat_message = distribution_lag_statement.replace(
                '<code>ballerina-distribution</code>',
                '*ballerina-distribution*') + ".\n\n"
            chat_message += "*Reminder* on the following modules\' dependency update..." + "\n"
            for module in lag_reminder_modules:
                lag_status_link = module[MODULE_PULL_REQUEST]
                if lag_status_link == "":
                    lag_status_link = constants.BALLERINA_ORG_URL + module[
                        MODULE_NAME]
                chat_message += utils.get_module_message(
                    module, lag_status_link)
            print("\n" + utils.get_sanitised_chat_message(chat_message))
            notify_chat.send_message(chat_message)
    else:
        print('No changes to ' + README_FILE + ' file')
예제 #2
0
def wait_for_current_level_build(level, is_stdlib_module):
    global MAX_WAIT_CYCLES
    global send_notification
    global status_completed_modules

    print("[Info] Waiting for level '" + str(level) + "' module build.")
    total_modules = len(current_level_modules)

    if level == 5:
        # In level 5 http takes around 30 min for PR build and build each
        # Changes timeout to 80 minutes
        MAX_WAIT_CYCLES = 140

    if level == 6:
        # In level 6 c2c takes around 52 min for PR build and build each
        # Changes timeout to 140 minutes
        MAX_WAIT_CYCLES = 280

    wait_cycles = 0
    status_completed_modules = 0

    while status_completed_modules != total_modules:
        for idx, module in enumerate(current_level_modules):
            if module[MODULE_STATUS] == MODULE_STATUS_IN_PROGRESS:
                if module[MODULE_CONCLUSION] == MODULE_CONCLUSION_PR_PENDING:
                    check_pending_pr_checks(idx)
                else:
                    # Build checks test
                    check_pending_build_checks(idx)

        if wait_cycles < MAX_WAIT_CYCLES:
            time.sleep(SLEEP_INTERVAL)
            wait_cycles = wait_cycles + 1
        else:
            # Force stop script with all in progress modules printed
            print(
                'Dependency update script timed out. Following modules are in pending state'
            )
            for module in current_level_modules:
                if module[MODULE_STATUS] == MODULE_STATUS_IN_PROGRESS:
                    print(module['name'])
            sys.exit(1)

    module_release_failure = False
    chat_message_send = False
    chat_message = "Dependency update to lang version *" + lang_version + "*\n\n"
    print()
    pr_checks_failed_modules = list(
        filter(
            lambda s: s[MODULE_CONCLUSION] ==
            MODULE_CONCLUSION_PR_CHECK_FAILURE, current_level_modules))
    if len(pr_checks_failed_modules) != 0:
        module_release_failure = True
        pr_failed_message = 'Following modules\' Automated Dependency Update PRs have failed checks...'
        send_chat, partial_chat_message = get_chat_message(
            pr_checks_failed_modules, pr_failed_message, True)
        chat_message_send = chat_message_send or send_chat
        chat_message += partial_chat_message

    pr_merged_failed_modules = list(
        filter(
            lambda s: s[MODULE_CONCLUSION] ==
            MODULE_CONCLUSION_PR_MERGE_FAILURE, current_level_modules))
    if len(pr_merged_failed_modules) != 0:
        module_release_failure = True
        pr_merged_failed_message = 'Following modules\' Automated Dependency Update PRs could not be merged...'
        send_chat, partial_chat_message = get_chat_message(
            pr_merged_failed_modules, pr_merged_failed_message, True)
        chat_message_send = chat_message_send or send_chat
        chat_message += partial_chat_message

    build_checks_failed_modules = list(
        filter(
            lambda s: s[MODULE_CONCLUSION] == MODULE_CONCLUSION_BUILD_FAILURE,
            current_level_modules))
    if len(build_checks_failed_modules) != 0:
        module_release_failure = True
        build_checks_failed_message = 'Following modules\' Timestamped Build checks have failed...'
        send_chat, partial_chat_message = get_chat_message(
            build_checks_failed_modules, build_checks_failed_message, False)
        chat_message_send = chat_message_send or send_chat
        chat_message += partial_chat_message

    build_version_failed_modules = list(
        filter(
            lambda s: s[MODULE_CONCLUSION
                        ] == MODULE_CONCLUSION_VERSION_CANNOT_BE_IDENTIFIED,
            current_level_modules))
    if len(build_version_failed_modules) != 0:
        module_release_failure = True
        build_version_failed_message = 'Following modules\' latest Timestamped Build Version cannot be identified...'
        send_chat, partial_chat_message = get_chat_message(
            build_version_failed_modules, build_version_failed_message, False)
        chat_message_send = chat_message_send or send_chat
        chat_message += partial_chat_message

    if is_stdlib_module:
        chat_message += "After following up on the above, trigger the <" + \
                        "https://github.com/ballerina-platform/ballerina-release/actions/workflows/update_dependency_version.yml" + \
                        "|Dependency Update Workflow>"

    if send_notification == 'true' and chat_message_send:
        print('Failing modules that is being notified:')
        print(utils.get_sanitised_chat_message(chat_message))
        notify_chat.send_message(chat_message)
    elif chat_message_send:
        print('Failing modules that is NOT being notified:')
        print(utils.get_sanitised_chat_message(chat_message))

    if module_release_failure:
        sys.exit(1)