Esempio n. 1
0
    def testLuciRerunBuildSearch(self):
        build_id = 1234567890
        commit_position = 65432
        commit = GitilesCommit(gitiles_host='chromium.googlesource.com',
                               gitiles_project='chromium/src',
                               gitiles_ref='refs/heads/master',
                               gitiles_id='git_hash',
                               commit_position=commit_position)
        analysis = self._CreateCompileFailureAnalysis()
        self._CreateCompileRerunBuild(build_id, commit_position, analysis.key)

        rerun_builds = CompileRerunBuild.SearchBuildOnCommit(
            analysis.key, commit)
        self.assertEqual(1, len(rerun_builds))
        self.assertEqual(build_id, rerun_builds[0].build_id)
Esempio n. 2
0
 def _GetExistingRerunBuild(self, analysis_key, rerun_commit):
     return CompileRerunBuild.SearchBuildOnCommit(analysis_key,
                                                  rerun_commit)
def TriggerRerunBuild(context, analyzed_build_id, referred_build, analysis_key,
                      rerun_builder, rerun_commit, output_targets):
  """Triggers a rerun build if there's no existing one.

  Creates and saves a CompileRerunBuild entity if a new build is triggered.

  Checking for existing build and saving new build are in one transaction to
  make sure no duplicated rerun builds can be triggered.

  Args:
    context (findit_v2.services.context.Context): Scope of the analysis.
    analyzed_build_id (int): Build id of the build that's being analyzed.
    referred_build (buildbucket build.proto): Info about the build being
      referred to trigger new rerun builds. This build could be the analyzed
      build or a previous rerun build in the same analysis.
    analysis_key (Key to CompileFailureAnalysis): Key to the running analysis.
    rerun_builder (BuilderId): Builder to rerun the build.
    rerun_commit (GitilesCommit): Gitiles commit the build runs on.
    output_targets (dict): A dict of targets the rerun build should re-compile.
    {
      'compile': ['target1.o', ...]
    }
  """
  # Check if there's a running build on that commit already.
  existing_builds = CompileRerunBuild.SearchBuildOnCommit(
      analysis_key, rerun_commit)
  if existing_builds:
    # TODO(crbug/957760): Re-trigger the build if the existing one(s) ended with
    # unexpected failures.
    logging.debug('Found existing rerun build for analysis %s on commit %d.',
                  analysis_key.urlsafe(), rerun_commit.commit_position)
    return

  rerun_tags = _GetRerunBuildTags(analyzed_build_id)
  input_properties = _GetRerunBuildInputProperties(context, referred_build,
                                                   output_targets)
  if not input_properties:
    logging.error(
        'Failed to get input properties to trigger rerun build'
        'for build %d.', analyzed_build_id)
    return

  gitiles_commit_pb = common_pb2.GitilesCommit(
      project=rerun_commit.gitiles_project,
      host=rerun_commit.gitiles_host,
      ref=rerun_commit.gitiles_ref,
      id=rerun_commit.gitiles_id)
  new_build = buildbucket_client.TriggerV2Build(
      rerun_builder, gitiles_commit_pb, input_properties, tags=rerun_tags)

  if not new_build:
    logging.error(
        'Failed to trigger rerun build for %s in build %d,'
        'on commit %s', output_targets, analyzed_build_id,
        rerun_commit.gitiles_id)
    return

  CompileRerunBuild.Create(
      luci_project=rerun_builder.project,
      luci_bucket=rerun_builder.bucket,
      luci_builder=rerun_builder.builder,
      build_id=new_build.id,
      legacy_build_number=new_build.number,
      gitiles_host=rerun_commit.gitiles_host,
      gitiles_project=rerun_commit.gitiles_project,
      gitiles_ref=rerun_commit.gitiles_ref,
      gitiles_id=rerun_commit.gitiles_id,
      commit_position=rerun_commit.commit_position,
      status=new_build.status,
      create_time=new_build.create_time.ToDatetime(),
      parent_key=analysis_key).put()