1# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5
6# Recipe which runs the Skia infra tests.
7
8
9DEPS = [
10  'infra',
11  'recipe_engine/context',
12  'recipe_engine/path',
13  'recipe_engine/properties',
14  'recipe_engine/step',
15  'vars',
16]
17
18
19def git_init(api, repo_root, env):
20  with api.context(cwd=repo_root, env=env):
21    # Some tests assume that they're being run inside a git repo.
22    api.step('git init', cmd=['git', 'init'])
23    api.step('git add .', cmd=['git', 'add', '.'])
24    api.step('git commit', cmd=['git', 'commit', '-a', '-m', 'initial commit'])
25
26
27def RunSteps(api):
28  api.vars.setup()
29
30  # Run the infra tests.
31  repo_name = api.properties['repository'].split('/')[-1]
32  if repo_name.endswith('.git'):
33    repo_name = repo_name[:-len('.git')]
34  repo_root = api.path['start_dir'].join(repo_name)
35  infra_tests = repo_root.join('infra', 'bots', 'infra_tests.py')
36
37  # Merge the default environment with the Go environment.
38  env = {}
39  env.update(api.infra.go_env)
40  for k, v in api.vars.default_env.iteritems():
41    # The PATH variable gets merged; all others get replaced.
42    if k == 'PATH':
43      # This works because the value for PATH in go_env and default_env includes
44      # the '%(PATH)s' placeholder.
45      env[k] = env[k] % {k: v}
46    else:
47      env[k] = v
48
49  git_init(api, repo_root, env)
50  if repo_name != 'skia':
51    git_init(api, api.path['start_dir'].join('skia'), env)
52
53  with api.context(cwd=repo_root, env=env):
54    # Unfortunately, the recipe tests are flaky due to file removal on Windows.
55    # Run multiple attempts.
56    last_exc = None
57    for _ in range(3):
58      try:
59        api.step('infra_tests', cmd=['python', '-u', infra_tests])
60        break
61      except api.step.StepFailure as e:  # pragma: nocover
62        last_exc = e
63    else:  # pragma: nocover
64      raise last_exc
65
66def GenTests(api):
67  yield (
68      api.test('infra_tests') +
69      api.properties(buildername='Housekeeper-PerCommit-InfraTests_Win',
70                     repository='https://skia.googlesource.com/skia.git',
71                     path_config='kitchen',
72                     swarm_out_dir='[SWARM_OUT_DIR]')
73  )
74  yield (
75      api.test('infra_tests_lottie_ci') +
76      api.properties(buildername='Housekeeper-PerCommit-InfraTests_Linux',
77                     repository='https://skia.googlesource.com/lottie-ci.git',
78                     path_config='kitchen',
79                     swarm_out_dir='[SWARM_OUT_DIR]')
80  )
81