Exemplo n.º 1
0
def run(CONF):
    versions_repo = setup_versions_repository(CONF)

    version_milestone = read_version_and_milestone(versions_repo)

    packages_names = packages_manager.discover_packages()
    distro = distro_utils.get_distro(
        CONF.get('common').get('distro_name'),
        CONF.get('common').get('distro_version'),
        CONF.get('common').get('arch_and_endianness'))
    release_notes_repo_url = CONF.get('build_release_notes').get(
        'release_notes_repo_url')
    release_notes_repo_branch = CONF.get('build_release_notes').get(
        'release_notes_repo_branch')
    commit_updates = CONF.get('common').get('commit_updates')
    push_updates = CONF.get('common').get('push_updates')
    push_repo_url = CONF.get('build_release_notes').get('push_repo_url')
    push_repo_branch = CONF.get('build_release_notes').get('push_repo_branch')
    updater_name = CONF.get('common').get('updater_name')
    updater_email = CONF.get('common').get('updater_email')

    REQUIRED_PARAMETERS = [("common", "updater_name"),
                           ("common", "updater_email")]
    if push_updates:
        REQUIRED_PARAMETERS += [("build_release_notes", "push_repo_url"),
                                ("build_release_notes", "push_repo_branch")]
    for section, parameter in REQUIRED_PARAMETERS:
        if CONF.get(section).get(parameter) is None:
            raise exception.RequiredParameterMissing(parameter=parameter)

    LOG.info("Creating release notes with packages: {}".format(
        ", ".join(packages_names)))
    package_manager = packages_manager.PackagesManager(packages_names)
    package_manager.prepare_packages(packages_class=rpm_package.RPM_Package,
                                     download_source_code=False,
                                     distro=distro)

    repositories_dir_path = os.path.join(
        CONF.get('common').get('work_dir'), REPOSITORIES_DIR)
    website_repo = repository.get_git_repository(release_notes_repo_url,
                                                 repositories_dir_path)
    website_repo.checkout(release_notes_repo_branch)

    WEBSITE_POSTS_DIR = "_posts"
    release_date = datetime.today().date().isoformat()
    release_tag = "{version}-{date}".format(version=version_milestone,
                                            date=release_date)
    release_file_name = RELEASE_FILE_NAME_TEMPLATE.format(date=release_date)
    release_file_path = os.path.join(website_repo.working_tree_dir,
                                     WEBSITE_POSTS_DIR, release_file_name)
    write_version_info(release_tag, release_file_path, versions_repo,
                       package_manager.packages)

    if commit_updates:
        commit_release_notes(website_repo, release_date, updater_name,
                             updater_email)
        if push_updates:
            push_website_head_commit(website_repo, push_repo_url,
                                     push_repo_branch)
Exemplo n.º 2
0
def run(CONF):
    versions_repo = setup_versions_repository(CONF)
    packages_to_update = CONF.get('update_versions').get(
        'packages') or PACKAGES
    distro = distro_utils.get_distro(
        CONF.get('common').get('distro_name'),
        CONF.get('common').get('distro_version'),
        CONF.get('common').get('architecture'))
    commit_updates = CONF.get('common').get('commit_updates')
    push_updates = CONF.get('common').get('push_updates')
    push_repo_url = CONF.get('update_versions').get('push_repo_url')
    push_repo_branch = CONF.get('update_versions').get('push_repo_branch')
    updater_name = CONF.get('common').get('updater_name')
    updater_email = CONF.get('common').get('updater_email')

    REQUIRED_PARAMETERS = [("common", "updater_name"),
                           ("common", "updater_email")]
    if push_updates:
        REQUIRED_PARAMETERS += [("update_versions", "push_repo_url"),
                                ("update_versions", "push_repo_branch")]
    for section, parameter in REQUIRED_PARAMETERS:
        if CONF.get(section).get(parameter) is None:
            raise exception.RequiredParameterMissing(parameter=parameter)

    # get packages names
    packages_to_update_names = []
    for package in packages_to_update:
        packages_to_update_names.append(package.split("#")[0])

    LOG.info("Checking for updates in packages versions: %s",
             ", ".join(packages_to_update_names))
    pm = packages_manager.PackagesManager(packages_to_update_names)
    pm.prepare_packages(packages_class=rpm_package.RPM_Package,
                        download_source_code=False,
                        distro=distro)

    for pkg in pm.packages:
        pkg.lock()
        pkg_version = Version(pkg)
        pkg_version.update(updater_name, updater_email)
        pkg.unlock()

    packages_names = discover_packages()
    METAPACKAGE_NAME = "open-power-host-os"
    packages_names.remove(METAPACKAGE_NAME)

    update_metapackage(versions_repo, distro, METAPACKAGE_NAME, packages_names,
                       updater_name, updater_email)
    update_versions_in_readme(versions_repo, distro, packages_names)

    release_date = datetime.today().date().isoformat()
    if commit_updates:
        commit_message = "Weekly build {date}".format(date=release_date)
        versions_repo.commit_changes(commit_message, updater_name,
                                     updater_email)
        if push_updates:
            LOG.info("Pushing packages versions updates")
            versions_repo.push_head_commits(push_repo_url, push_repo_branch)
Exemplo n.º 3
0
def update_metapackage(
        versions_repo, distro, metapackage_name, packages_names,
        user_name, user_email):
    """
    Update package version and dependencies to the packages created by
    a build of the specified versions repository commit.

    Args:
        versions_repo (GitRepository): versions Git repository handler
        distro (distro.LinuxDistribution): Linux distribution
        metapackage_name (str): name of the release package whose
            dependencies will be updated
        packages_names ([str]): list of dependencies of the release
            package
        user_name (str): name of the user updating the spec file
        user_name (str): email of the user updating the spec file
    """
    LOG.info("Updating release package dependencies: "
             "{}".format(", ".join(packages_names)))
    pm = packages_manager.PackagesManager(packages_names)
    # TODO: this is coupled with RPM-based Linux distributions
    pm.prepare_packages(packages_class=rpm_package.RPM_Package,
                        download_source_code=False, distro=distro)

    LOG.info("Updating release package YAML file")
    YAML_START_DELIMITER = "    install_dependencies:"
    metapackage_yaml_file_path = os.path.join(
        versions_repo.working_tree_dir, metapackage_name,
        metapackage_name + ".yaml")
    yaml_install_dependencies_string = "{start}\n{contents}".format(
        start=YAML_START_DELIMITER,
        contents=create_yaml_install_dependencies_string(pm.packages))
    replace_file_section(
        metapackage_yaml_file_path, yaml_install_dependencies_string,
        YAML_START_DELIMITER)

    LOG.info("Updating release package spec file")
    version_file_path = os.path.join(versions_repo.working_tree_dir, "VERSION")
    with open(version_file_path) as version_file:
        version_parts = version_file.readlines()[-1].strip().split("-")
    metapackage_version = version_parts.pop(0)
    if version_parts:
        metapackage_milestone = version_parts.pop(0)
    else:
        metapackage_milestone = "%nil"

    metapackage = rpm_package.RPM_Package.get_instance(
        metapackage_name, distro)
    metapackage.spec_file.update_version(metapackage_version)
    metapackage.spec_file.replace_macro_definition(
        "milestone", metapackage_milestone)

    replace_spec_dependencies(metapackage.spec_file.path)
    metapackage.spec_file.bump_release(
        ["Update package dependencies"], user_name, user_email)
Exemplo n.º 4
0
def update_versions_in_readme(versions_repo, distro, packages_names):
    """
    Update packages versions in README

    Args:
        versions_repo (GitRepository): versions git repository handler
        distro (distro.LinuxDistribution): Linux distribution
        packages_names ([str]): list of packages whose versions must be updated
    """

    LOG.info("Generating packages versions HTML table from packages: %s",
             ", ".join(packages_names))
    pm = packages_manager.PackagesManager(packages_names)
    # TODO: this is coupled with RPM-based Linux distributions
    pm.prepare_packages(packages_class=rpm_package.RPM_Package,
                        download_source_code=False,
                        distro=distro)

    html_table = create_html_table(pm.packages)
    output_readme_path = os.path.join(versions_repo.working_tree_dir,
                                      'README.md')
    replace_file_section(output_readme_path, html_table, "<table>", "</table>")
def run(CONF):
    versions_repo = setup_versions_repository(CONF)
    packages_to_update = CONF.get('packages') or PACKAGES
    distro = distro_utils.get_distro(CONF.get('distro_name'),
                                     CONF.get('distro_version'),
                                     CONF.get('architecture'))
    commit_updates = CONF.get('commit_updates')
    push_updates = CONF.get('push_updates')
    push_repo_url = CONF.get('push_repo_url')
    push_repo_branch = CONF.get('push_repo_branch')
    updater_name = CONF.get('updater_name')
    updater_email = CONF.get('updater_email')

    REQUIRED_PARAMETERS = ["updater_name", "updater_email"]
    if push_updates:
        REQUIRED_PARAMETERS += ["push_repo_url", "push_repo_branch"]
    for parameter in REQUIRED_PARAMETERS:
        if not CONF.get(parameter):
            raise exception.RequiredParameterMissing(parameter=parameter)

    # get packages names
    packages_to_update_names = []
    for package in packages_to_update:
        packages_to_update_names.append(package.split("#")[0])

    LOG.info("Checking for updates in packages versions: %s",
             ", ".join(packages_to_update_names))
    pm = packages_manager.PackagesManager(packages_to_update_names)
    pm.prepare_packages(packages_class=rpm_package.RPM_Package,
                        download_source_code=False,
                        distro=distro)

    updates_available = False
    for pkg in pm.packages:
        pkg.lock()
        pkg_version = Version(pkg)
        updates_available = (pkg_version.update(updater_name, updater_email)
                             or updates_available)
        pkg.unlock()

    if updates_available:
        packages_names = discover_packages()
        METAPACKAGE_NAME = "open-power-host-os"
        packages_names.remove(METAPACKAGE_NAME)
        update_metapackage(versions_repo, distro, METAPACKAGE_NAME,
                           packages_names, updater_name, updater_email)

        if commit_updates:
            commit_message = (CONF.get('commit_message')
                              or "Update packages versions")
            versions_repo.commit_changes(commit_message, updater_name,
                                         updater_email)

            if push_updates:
                LOG.info("Pushing packages versions updates")
                versions_repo.push_head_commits(push_repo_url,
                                                push_repo_branch)
        elif push_updates:
            LOG.warning("Not pushing branch because no commit was created")
    else:
        LOG.info("No updates in packages versions, skipping metapackage "
                 "update and commit creation")
        if push_updates:
            LOG.info("No updates, pushing branch with unaltered head")
            versions_repo.push_head_commits(push_repo_url, push_repo_branch)
        raise exception.NoPackagesUpdated()

    LOG.info("Packages updated succesfully")