示例#1
0
    def _do_postprocess(self, result_dict):
        """Construct the bom from the collected summary, then write it out."""
        path = _determine_bom_path(self.options)
        summary_table = result_dict

        bom = self.construct_bom(summary_table, DEFAULT_BOM_DEPENDENCIES)
        bom_text = yaml.dump(bom, default_flow_style=False)
        write_to_path(bom_text, path)
        logging.info('Wrote bom to %s', path)
示例#2
0
    def __build_with_gcb(self, repository):
        name = repository.name
        nebula_dir = self._get_nebula_repository_path(name)

        version = self._get_nebula_repository_version(name)
        gcb_config = self.__derive_gcb_config(name, version)
        if gcb_config is None:
            logging.info('Skipping GCB for %s because there is config for it',
                         name)
            return

        options = self.options
        log_flags = '--log-http' if options.log_level == 'debug' else ''
        name_scratch_dir = os.path.join(options.scratch_dir, name)

        # Use an absoluate path here because we're going to
        # pass this to the gcloud command, which will be running
        # in a different directory so relative paths wont hold.
        config_path = os.path.abspath(
            os.path.join(name_scratch_dir, '{name}-gcb.yml'.format(name=name)))
        write_to_path(gcb_config, config_path)

        # Local .gradle dir stomps on GCB's .gradle directory when the gradle
        # wrapper is installed, so we need to delete the local one.
        # The .gradle dir is transient and will be recreated on the next gradle
        # build, so this is OK.
        #
        # This can still be shared among components as long as the
        # scratch directory remains around.
        if options.force_clean_gradle_cache:
            # If we're going to delete existing ones, then keep each component
            # separate so they dont stomp on one another
            gradle_cache = os.path.abspath(os.path.join(nebula_dir, '.gradle'))
        else:
            # Otherwise allow all the components to share a common gradle directory
            gradle_cache = os.path.abspath(
                os.path.join(options.scratch_dir, '.gradle'))

        if options.force_clean_gradle_cache and os.path.isdir(gradle_cache):
            shutil.rmtree(gradle_cache)

        # Note this command assumes a cwd of nebula_dir
        cmd = ('gcloud container builds submit {log_flags}'
               ' --account={account} --project={project}'
               ' --config="{config_path}" .'.format(
                   log_flags=log_flags,
                   account=options.gcb_service_account,
                   project=options.gcb_project,
                   config_path=config_path))

        logfile = os.path.join(name_scratch_dir,
                               '{name}-gcb-build.log'.format(name=name))
        check_subprocesses_to_logfile(
            '{name} container build'.format(name=name),
            logfile, [cmd],
            cwd=nebula_dir)
  def _do_postprocess(self, result_dict):
    """Construct changelog from the collected summary, then write it out."""
    options = self.options
    summary_table = result_dict
    path = (options.changelog_path
            or os.path.join(options.scratch_dir, 'changelog.md'))

    builder = ChangelogBuilder()
    for name, summary in summary_table.items():
      builder.add_repository(self.source_repositories[name], summary)
    changelog_text = builder.build()
    write_to_path(changelog_text, path)
    logging.info('Wrote changelog to %s', path)
示例#4
0
  def _get_nebula_repository_path(self, name, force_new=False):
    """Return the path to the repository for nebula to build.

    If the repository does not exist then one will be cloned from the
    source repository.

    Nebula gets confused by our tags because it expects the Netflix ones.
    Since we dont understand how to change nebula and dont want to invest
    the time into it, we're just going to remove all the tags and add the
    one we want nebula to use so it isnt confused.

    Rather than modifying the original repository, we'll do all this in a
    new one. The bonus is that we can commit and tag the repo so that
    gradle/nebula is happy but without modifying the original repo at all
    until we are ready to later.

    Args:
      name: [string] The name of the repository
      force_new: [bool] If true, clear any existing repository
    """
    git_dir = self.source_code_manager.get_local_repository_path(name)
    original_repo_path = os.path.abspath(git_dir)

    options = self.options
    nebula_repo_path = os.path.join(options.scratch_dir, 'build', name)

    if os.path.exists(nebula_repo_path):
      if not force_new:
        logged_is_newer = self.__logged_is_newer.get(nebula_repo_path, False)
        if self.__is_newer_repo(nebula_repo_path, original_repo_path,
                                not logged_is_newer):
          if not logged_is_newer:
            logging.info('Reusing existing %s', nebula_repo_path)
            self.__logged_is_newer[nebula_repo_path] = True
          return nebula_repo_path

      self.__logged_is_newer[nebula_repo_path] = False
      logging.info('Removing old nebula repo %s', nebula_repo_path)
      shutil.rmtree(nebula_repo_path, ignore_errors=True)

    logging.debug('Determining version and build tag of %s',
                  original_repo_path)
    summary = self.git.collect_repository_summary(original_repo_path)
    build_tag = '{version}-{build}'.format(
        version=summary.version, build=options.build_number)

    logging.info('Cloning %s to nebula repo %s', name, nebula_repo_path)
    self.git.clone_repository_to_path(original_repo_path, nebula_repo_path)

    # Nebula complains if the git tag version doesn't match the branch's
    # version, i.e. in patch releases. As a workaround, we checkout the
    # HEAD commit of the current branch in a 'detached HEAD' state so
    # Nebula doesn't complain about our branch version and git tag
    # version not matching.
    self.git.reinit_local_repository_with_tag(
        nebula_repo_path, build_tag,
        'Snapshot from {path} to satisfy nebula.\n\n'
        'commit: {commit}\ntag: {tag}\nversion: {version}'
        .format(path=original_repo_path,
                commit=summary.commit_id,
                tag=summary.tag,
                version=summary.version))
    self.__nebula_repository_version[name] = summary.version
    summary_path = os.path.join(
        options.scratch_dir, name, '{name}-summary.yml'.format(name=name))
    write_to_path(summary.to_yaml(with_commit_messages=False), summary_path)
    return nebula_repo_path