aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra/bots/recipe_modules/run/examples/full.py
blob: d6a27c9b9694626aa4eeeff386166a307e616dec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.


DEPS = [
  'recipe_engine/context',
  'recipe_engine/path',
  'recipe_engine/properties',
  'recipe_engine/step',
  'run',
  'vars',
]


def myfunc(api, i):
  api.run(api.step, 'run %d' % i, cmd=['echo', str(i)])


def RunSteps(api):
  api.vars.setup()
  try:
    api.run(api.step, 'fail', cmd=['false'])
  except api.step.StepFailure:
    pass
  api.run(api.step, 'fail again', cmd=['false'], abort_on_failure=False)
  api.run(api.step, 'do a thing', cmd=['echo', 'do the thing'])
  assert len(api.run.failed_steps) == 2

  # Run once.
  for i in range(10):
    api.run.run_once(myfunc, api, i)

  # Read and write files.
  api.run.readfile('myfile.txt')
  api.run.writefile('myfile.txt', 'contents')
  api.run.rmtree('mydir')
  api.run.asset_version('my_asset', api.vars.cache_dir.join('work', 'skia'))

  # Merge PATHs.
  with api.context(env={'PATH': 'mydir:%(PATH)s'}):
    api.run(api.step, 'env', cmd=['env'])

  def between_attempts_fn(attempt):
    api.run(api.step, 'between_attempts #%d' % attempt,
            cmd=['echo', 'between_attempt'])

  # Retries.
  try:
    api.run.with_retry(api.step, 'retry fail', 5, cmd=['false'],
                       between_attempts_fn=between_attempts_fn)
  except api.step.StepFailure:
    pass
  assert len(api.run.failed_steps) == 7

  api.run.with_retry(api.step, 'retry success', 3, cmd=['false'],
                     between_attempts_fn=between_attempts_fn)
  assert len(api.run.failed_steps) == 7

  # Check failure.
  api.run.check_failure()


def GenTests(api):
  buildername = 'Build-Win-Clang-x86_64-Release-Vulkan'
  yield (
      api.test('test') +
      api.properties(buildername=buildername,
                     repository='https://skia.googlesource.com/skia.git',
                     revision='abc123',
                     path_config='kitchen',
                     swarm_out_dir='[SWARM_OUT_DIR]') +
      api.step_data('fail', retcode=1) +
      api.step_data('fail again', retcode=1) +
      api.step_data('retry fail', retcode=1) +
      api.step_data('retry fail (attempt 2)', retcode=1) +
      api.step_data('retry fail (attempt 3)', retcode=1) +
      api.step_data('retry fail (attempt 4)', retcode=1) +
      api.step_data('retry fail (attempt 5)', retcode=1) +
      api.step_data('retry success', retcode=1) +
      api.step_data('retry success (attempt 2)', retcode=1)
    )