def update_module(idx: int, current_level):
    module = current_level_modules[idx]
    repo = github.get_repo(constants.BALLERINA_ORG_NAME + '/' + module['name'])
    properties_file = repo.get_contents(constants.GRADLE_PROPERTIES_FILE)

    properties_file = properties_file.decoded_content.decode(
        constants.ENCODING)
    updated_properties_file = get_updated_properties_file(
        module['name'], current_level, properties_file)

    update = utils.commit_file(module['name'],
                               constants.GRADLE_PROPERTIES_FILE,
                               updated_properties_file,
                               constants.DEPENDENCY_UPDATE_BRANCH,
                               COMMIT_MESSAGE)[0]

    if update:
        print("[Info] Update lang dependency in module '" + module['name'] +
              "'")
        create_pull_request(idx, repo)
    else:
        current_level_modules[idx][MODULE_STATUS] = MODULE_STATUS_IN_PROGRESS
        current_level_modules[idx][
            MODULE_CONCLUSION] = MODULE_CONCLUSION_BUILD_SUCCESS
        current_level_modules[idx][MODULE_CREATED_PR] = None

        pulls = repo.get_pulls(state='closed')
        sha_of_lang = lang_version.split('-')[-1]

        for pull in pulls:
            if sha_of_lang in pull.title:
                current_level_modules[idx][MODULE_CREATED_PR] = pull
                break
def update_connector(index: int):
    global connectors

    connector = connectors[index]
    repo = github.get_repo(constants.BALLERINA_ORG_NAME + '/' + connector['name'])

    properties_file = repo.get_contents(constants.GRADLE_PROPERTIES_FILE)
    properties_file = properties_file.decoded_content.decode(constants.ENCODING)

    updated_properties_file = ''
    for line in properties_file.splitlines():
        if line.startswith(constants.LANG_VERSION_KEY):
            updated_properties_file += constants.LANG_VERSION_KEY + '=' + ballerina_version + '\n'
        else:
            updated_properties_file += line + '\n'

    update = utils.commit_file(connector['name'], constants.GRADLE_PROPERTIES_FILE, updated_properties_file,
                               constants.DEPENDENCY_UPDATE_BRANCH,
                               COMMIT_MESSAGE_PREFIX + ballerina_version)[0]

    if update:
        print("[Info] Update lang dependency in connector '" + connector['name'] + "'")
        pr = create_pull_request(index, repo)
        connectors[index][CONNECTOR_STATUS] = CONNECTOR_STATUS_IN_PROGRESS
        connectors[index][CONNECTOR_CREATED_PR] = pr
    else:
        connectors[index][CONNECTOR_STATUS] = CONNECTOR_STATUS_COMPLETED
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')
Example #4
0
def commit_notify_work():
    with open('file_to_commit.csv', 'r') as enc_file:
        updated_file_content = enc_file.read()
    update = utils.commit_file(
        'ballerina-release', 'dependabot/resources/github_users_encrypted.csv',
        updated_file_content, constants.USERID_UPDATE_BRANCH,
        "[Automated] Update userid file")[0]
    return update
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':
            notify_chat.send_reminder(lag_reminder_modules)

    else:
        print('No changes to ' + README_FILE + ' file')
def main():
    module_name_list = sort_module_name_list()
    print('Fetched module name list')
    module_details_json = initialize_module_details(module_name_list)
    print('Initialized module details')
    module_details_json = get_immediate_dependents(module_name_list,
                                                   module_details_json)
    print('Fetched immediate dependents of each module')
    module_details_json = calculate_levels(module_name_list,
                                           module_details_json)
    print('Generated module dependency graph and updated module levels')
    module_details_json['modules'].sort(key=lambda s: s['level'])
    module_details_json = remove_modules_not_included_in_distribution(
        module_details_json)
    print('Removed central only modules and updated the list')

    try:
        utils.write_json_file(constants.EXTENSIONS_FILE, module_details_json)
    except Exception as e:
        print('Failed to write to extensions.json', e)
        sys.exit()

    print('Updated module details successfully')

    try:
        updated_file_content = open(constants.EXTENSIONS_FILE, 'r').read()
        update = utils.commit_file(
            'ballerina-release', constants.EXTENSIONS_FILE,
            updated_file_content, constants.EXTENSIONS_UPDATE_BRANCH,
            '[Automated] Update Extensions Dependencies')[0]
        if update:
            utils.open_pr_and_merge(
                'ballerina-release',
                '[Automated] Update Extensions Dependencies',
                'Update dependencies in extensions.json',
                constants.EXTENSIONS_UPDATE_BRANCH)
        else:
            print('No changes to ' + constants.EXTENSIONS_FILE + ' file')
    except GithubException as e:
        print('Error occurred while committing extensions.json', e)
        sys.exit(1)
    print("Updated module details in 'ballerina-release' successfully")
Example #7
0
def main():
    global dependencies
    global stdlib_modules_by_level
    global stdlib_modules_json_file

    read_stdlib_modules()
    if dependencies:
        create_graph(stdlib_modules_by_level, dependencies)

    updated_file_content = open(graph_file_path, 'r').read()
    update = utils.commit_file('ballerina-release', graph_file_path,
                               updated_file_content,
                               constants.EXTENSIONS_UPDATE_BRANCH,
                               '[Automated] Update Stdlib Dependency Graph')[0]
    if update:
        utils.open_pr_and_merge('ballerina-release',
                                '[Automated] Update Stdlib Dependency Graph',
                                'Update dependency graph in stdlib_graph.gv',
                                constants.EXTENSIONS_UPDATE_BRANCH)
    else:
        print('No changes to ' + graph_file_path + ' file')
def main():
    update_lang_version()

    updated_readme = get_updated_readme()

    try:
        update, commit = utils.commit_file(
            'ballerina-release', README_FILE, updated_readme,
            constants.DASHBOARD_UPDATE_BRANCH,
            '[Automated] Update extension dependency dashboard')
        if update:
            utils.open_pr_and_merge(
                'ballerina-release',
                '[Automated] Update Extension Dependency Dashboard',
                'Update extension dependency dashboard',
                constants.DASHBOARD_UPDATE_BRANCH)
            notify_chat.notify_lag_update(commit)
        else:
            print('No changes to ' + README_FILE + ' file')
    except GithubException as e:
        print('Error occurred while committing README.md', e)
        sys.exit(1)
def main():
    global lang_version
    global extensions_file
    global all_modules
    global current_level_modules

    try:
        extensions_file = utils.read_json_file(constants.EXTENSIONS_FILE)
    except Exception as e:
        print('[Error] Error while loading modules list ', e)
        sys.exit(1)

    print("Workflow invoked of type '" + event_type + "'")
    if event_type == 'schedule' and not extensions_file['auto_bump']:
        print(
            "Schedule workflow invoked, exiting script as 'auto_bump' flag in modules_list.json is false."
        )
        return

    if override_ballerina_version != '':
        lang_version = override_ballerina_version
    else:
        lang_version = utils.get_latest_lang_version()

    bal_version = {'version': lang_version}
    try:
        utils.write_json_file(constants.LANG_VERSION_FILE, bal_version)
    except Exception as e:
        print('Failed to write to file latest_ballerina_lang_version.json', e)
        sys.exit()

    try:
        updated_file_content = open(constants.LANG_VERSION_FILE, 'r').read()
        update = utils.commit_file(
            'ballerina-release', constants.LANG_VERSION_FILE,
            updated_file_content, constants.EXTENSIONS_UPDATE_BRANCH,
            '[Automated] Update Workflow Lang Version')[0]
        if update:
            utils.open_pr_and_merge(
                'ballerina-release',
                '[Automated] Update Dependency Bump Workflow Triggered Version',
                'Update bumped ballerina lang version',
                constants.EXTENSIONS_UPDATE_BRANCH)
        else:
            print('No changes to ' + constants.LANG_VERSION_FILE + ' file')
    except GithubException as e:
        print(
            'Error occurred while committing latest_ballerinalang_version.md',
            e)
        sys.exit(1)

    print('Workflow started with Ballerina Lang version : ' + lang_version)

    all_modules = extensions_file['modules']

    last_level = all_modules[-1]['level']

    print(
        'Start dependency bump to extensions packed in ballerina-distribution')
    for i in range(last_level):
        current_level = i + 1
        current_level_modules = list(
            filter(lambda s: s['level'] == current_level, all_modules))

        for idx, module in enumerate(current_level_modules):
            print("[Info] Check lang dependency in module '" + module['name'] +
                  "'")
            update_module(idx, current_level)

        if auto_merge_pull_requests.lower() == 'true':
            wait_for_current_level_build(current_level)
    print(
        'Successfully bumped dependencies in extensions packed in ballerina-distribution'
    )

    central_module_level = extensions_file['central_modules'][-1]['level']

    print('Start dependency bump to extensions available only in central')
    for j in range(last_level, central_module_level):
        current_level = j + 1
        current_level_modules = list(
            filter(lambda s: s['level'] == current_level,
                   extensions_file['central_modules']))

        for idx, module in enumerate(current_level_modules):
            print("[Info] Check lang dependency in module '" + module['name'] +
                  "'")
            update_module(idx, current_level)

        if auto_merge_pull_requests.lower() == 'true':
            wait_for_current_level_build(current_level)
    print(
        'Successfully bumped dependencies in extensions available in central')