コード例 #1
0
def regenerate_documentation(args, temp_dir, repositories):
    if args.badges_only is True or args.tags_only is True:
        return
    input(
        "About to regenerate documentation. Are you sure you want to continue? "
        + "(Press ENTER to continue)")
    update_doc_content_repository(repositories, temp_dir, args.token,
                                  args.no_push, args)
    write_msg('=> Preparing doc repo (too much dark magic in here urg)...')
    cleanup_doc_repo(temp_dir)
    write_msg('Done!')

    write_msg('=> Building docs...')
    for crate in args.crates:
        crate = crate['crate']
        if crate['crate'] == 'gtk-test':
            continue
        write_msg('-> Building docs for {}...'.format(crate['crate']))
        build_docs(crate['repository'], temp_dir, crate['path'],
                   crate.get('doc_name', crate['crate']))
    end_docs_build(temp_dir)
    write_msg('Done!')

    write_msg('=> Committing{} docs to the "{}" branch...'.format(
        " and pushing" if args.no_push is False else "",
        consts.CRATE_TMP_BRANCH))
    commit(consts.DOC_REPO, temp_dir, "Regen docs")
    if args.no_push is False:
        push(consts.DOC_REPO, temp_dir, consts.CRATE_TMP_BRANCH)
        create_pull_request(consts.DOC_REPO, consts.CRATE_TMP_BRANCH,
                            "gh-pages", args.token)
        write_msg("New pull request(s):\n\n{}\n".format(
            '\n'.join(PULL_REQUESTS)))
    write_msg('Done!')
コード例 #2
0
def update_crate_repositories_branches(args, temp_dir, repositories):
    write_msg('=> Merging "master" branches into "crate" branches...')
    for repo in repositories:
        merging_branches(repo, temp_dir, "master")
    write_msg('Done!')

    write_msg('=> Updating [crate] crates version...')
    for crate in args.crates:
        crate = crate['crate']
        if args.specified_crate is not None and crate[
                'crate'] != args.specified_crate:
            continue
        if update_crate_version(crate["repository"], crate["crate"],
                                crate["path"], temp_dir,
                                args.specified_crate) is False:
            write_error('The update for the "{}" crate failed...'.format(
                crate["crate"]))
            return False
    write_msg('Done!')

    write_msg('=> Committing{} to the "{}" branch...'.format(
        " and pushing" if args.no_push is False else "",
        consts.CRATE_TMP_BRANCH))
    for repo in repositories:
        commit(repo, temp_dir, "Update versions [ci skip]")
        if args.no_push is False:
            push(repo, temp_dir, consts.CRATE_TMP_BRANCH)
    write_msg('Done!')
    if args.no_push is False:
        write_msg('=> Creating PRs on crate branch...')
        for repo in repositories:
            create_pull_request(repo, consts.CRATE_TMP_BRANCH, "crate",
                                args.token)
        write_msg('Done!')
    return True
コード例 #3
0
def update_crates_versions(args, temp_dir, repositories):
    write_msg('=> Updating [master] crates version...')
    for crate in args.crates:
        update_type = crate['up-type']
        crate = crate['crate']
        if args.specified_crate is not None and crate[
                'crate'] != args.specified_crate:
            continue
        if update_repo_version(crate["repository"], crate["crate"],
                               crate["path"], temp_dir, update_type,
                               args.badges_only or args.tags_only) is False:
            write_error('The update for the "{}" crate failed...'.format(
                crate["crate"]))
            return False
    write_msg('Done!')
    if args.badges_only is False and args.tags_only is False:
        write_msg('=> Committing{} to the "{}" branch...'.format(
            " and pushing" if args.no_push is False else "",
            consts.MASTER_TMP_BRANCH))
        for repo in repositories:
            commit(repo, temp_dir, "Update versions [ci skip]")
            if args.no_push is False:
                push(repo, temp_dir, consts.MASTER_TMP_BRANCH)
        write_msg('Done!')

        if args.no_push is False:
            write_msg('=> Creating PRs on master branch...')
            for repo in repositories:
                create_pull_request(repo, consts.MASTER_TMP_BRANCH, "master",
                                    args.token)
            write_msg('Done!')
    return True
コード例 #4
0
def update_doc_content_repository(repositories, temp_dir, token, no_push,
                                  args):
    if clone_repo(consts.DOC_CONTENT_REPO, temp_dir) is False:
        input('Try to fix the problem then press ENTER to continue...')
    write_msg("Done!")
    repo_path = join(temp_dir, consts.DOC_CONTENT_REPO)
    write_msg("=> Generating documentation for crates...")
    for repo in repositories:
        current = None
        for crate in args.crates:
            crate = crate['crate']
            if crate['repository'] == repo:
                current = crate
                break
        if current is None:
            input(
                'No repository matches "{}", something is weird. (Press ENTER TO CONTINUE)'
            )
            continue
        if current.get("doc", True) is False:
            continue
        write_msg('==> Generating documentation for "{}"'.format(current))
        path = join(temp_dir, current['repository'])
        command = [
            'bash', '-c', 'cd {} && make doc && mv vendor.md {}'.format(
                path, join(repo_path, current['crate']))
        ]
        if not exec_command_and_print_error(command):
            input("Fix the error and then press ENTER")
    write_msg('Done!')
    write_msg('Committing "{}" changes...'.format(consts.DOC_CONTENT_REPO))
    commit(consts.DOC_CONTENT_REPO, temp_dir, "Update vendor files")
    if no_push is False:
        push(consts.DOC_CONTENT_REPO, temp_dir, consts.MASTER_TMP_BRANCH)

    # We always make minor releases in here, no need for a more important one considering we don't
    # change the API.
    if update_repo_version(consts.DOC_CONTENT_REPO, consts.DOC_CONTENT_REPO,
                           "", temp_dir, UpdateType.MINOR, False) is False:
        write_error('The update for the "{}" crate failed...'.format(
            consts.DOC_CONTENT_REPO))
        input('Fix the error and then press ENTER')
    commit(consts.DOC_CONTENT_REPO, temp_dir, "Update version")
    if no_push is False:
        push(consts.DOC_CONTENT_REPO, temp_dir, consts.MASTER_TMP_BRANCH)
        create_pull_request(consts.DOC_CONTENT_REPO, consts.MASTER_TMP_BRANCH,
                            "master", token, False)
        input((
            'All done with the "{}" update: please merge the PR then press ENTER so the '
            'publication can performed...').format(consts.DOC_CONTENT_REPO))
        publish_crate(consts.DOC_CONTENT_REPO,
                      "",
                      temp_dir,
                      consts.DOC_CONTENT_REPO,
                      checkout_branch='master')
        write_msg('Ok all done! We can move forward now!')
    else:
        write_msg((
            'All with "{}", you still need to publish a new version if you want the changes '
            'to be taken into account').format(consts.DOC_CONTENT_REPO))
コード例 #5
0
def update_gtk_rs_blog(args, temp_dir):
    if args.doc_only is True or args.tags_only is True:
        return
    write_msg('=> Updating blog...')
    if update_badges(consts.BLOG_REPO, temp_dir,
                     args.specified_crate) is False:
        write_error("Error when trying to update badges...")
    elif args.no_push is False:
        commit_and_push(consts.BLOG_REPO, temp_dir, "Update versions",
                        consts.MASTER_TMP_BRANCH)
        create_pull_request(consts.BLOG_REPO, consts.MASTER_TMP_BRANCH,
                            "master", args.token)
    write_msg('Done!')
def main() -> int:
    args = parse_arguments()

    operator_repository = args.operator_repository
    operator_name = args.operator_name
    operator_git_tag = args.operator_git_tag
    github_token = args.github_token
    operators_base_branch = args.operators_base_branch
    operators_repository = args.operators_repository
    git_user = args.git_user
    debug = args.debug

    operators_branch = automated_operators_repository_branch(
        operator_name, operator_git_tag)

    rc, stdout, stderr = get_git_version(debug)
    if rc != 0:
        log.error(
            f"Error getting git version:\nstdout:\n{stdout}\nstderr:\n{stderr}"
        )
        return rc
    git_version = stdout.strip()

    log.info(git_version)

    with tempfile.TemporaryDirectory(prefix="kudo_dev_") as base_directory:
        (
            rc,
            error_message,
            operators_directory,
            operator_directory,
        ) = prepare_git_repositories(
            base_directory,
            operators_repository,
            operators_base_branch,
            operators_branch,
            operator_repository,
            operator_git_tag,
            git_user,
            github_token,
            debug,
        )
        if rc != 0:
            log.error(error_message)
            return rc

        if args.git_commit_message:
            git_commit_message_subject = args.git_commit_message
            git_commit_message_body = ""
        else:
            (
                rc,
                git_commit_message_subject,
                git_commit_message_body,
                error_message,
            ) = automated_operators_repository_commit_message(
                operator_repository,
                operator_name,
                operator_directory,
                operator_git_tag,
                debug,
            )
            if rc != 0:
                log.error(error_message)
                return rc

        git_commit_message = (
            f"{git_commit_message_subject}\n\n{git_commit_message_body}"
        ).strip()

        rc, error_message = commit_copied_operator_files_and_push_branch(
            operators_directory,
            operators_repository,
            operators_branch,
            operator_directory,
            operator_name,
            operator_git_tag,
            git_commit_message,
            debug,
        )
        if rc != 0:
            log.error(error_message)
            return rc

        success, http_response = create_pull_request(
            operators_repository,
            operators_base_branch,
            operators_branch,
            git_commit_message_subject,
            git_commit_message_body,
            github_token,
            PROGRAM_NAME,
            debug,
        )
        if not success:
            log.error(f"Error creating pull request\n" +
                      f"response body: {http_response.read()}\n" +
                      f"response headers: {http_response.getheaders()}")
            return 1

        pull_request_url = json.loads(http_response.read())["html_url"]

        log.info(f"Successfully created PR: '{pull_request_url}'")

        return 0
コード例 #7
0
def create_example_repository_pull_request(args):
    write_msg('=> Creating PR for examples repository')
    create_pull_request("examples", "pending", "master", args.token)
    write_msg('Done!')