blob: 71da72f6fa549bb922f5a491a3b96b068190be3b [file] [log] [blame]
# Copyright 2018 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Example recipe for auto-rolling."""
from recipe_engine import post_process
from recipe_engine.recipe_api import Property
DEPS = [
'fuchsia/auto_roller',
'fuchsia/jiri',
'fuchsia/git',
'fuchsia/gitiles',
'recipe_engine/json',
'recipe_engine/path',
'recipe_engine/properties',
'recipe_engine/raw_io',
]
PROPERTIES = {
'project':
Property(kind=str, help='Gerrit project', default=None),
'remote':
Property(kind=str, help='Remote repository'),
'commit_untracked_files':
Property(
kind=bool, default=False, help='Whether to commit untracked files'),
'dry_run':
Property(
kind=bool,
default=False,
help='Whether to dry-run the auto-roller (CQ+1 and abandon the change)'
),
}
def RunSteps(api, project, remote, commit_untracked_files, dry_run):
# Check out the repo.
api.git.checkout(remote)
# Do some changes to the repo.
# ...
# Land the changes.
api.auto_roller.attempt_roll(
gerrit_project=project,
repo_dir=api.path['start_dir'].join(project),
commit_message='hello world!',
commit_untracked=commit_untracked_files,
dry_run=dry_run,
)
# Update project manifest
api.auto_roller.update_manifest_project(
manifest='manifest',
project_name='project_name',
revision='revision',
updated_deps={})
# Update package manifest
api.auto_roller.update_manifest_package(
manifest='manifest',
package_name='package_name',
version='git_revision:revision',
updated_deps={})
def GenTests(api):
mock_manifest_data = api.jiri.read_manifest_element(
api=api,
manifest='manifest',
element_name='project_name',
element_type='project',
test_output={
'remote': 'https://fuchsia.googlesource.com/mock/remote',
})
mock_log_data = api.gitiles.log('log project_name', 'A')
noop_edit = api.step_data(
'jiri edit project_name',
api.json.output({'projects': []}),
)
noop_package_edit = api.step_data(
'jiri edit package_name',
api.json.output({'packages': []}),
)
# yapf: disable
# Test a successful roll of zircon into garnet w/ manifest update.
yield (api.test('zircon-manifest-update') + api.properties(
project='garnet',
remote='https://fuchsia.googlesource.com/garnet',
poll_interval_secs=0.001,
poll_timeout_secs=0.1) +
api.auto_roller.success_step_data() +
mock_manifest_data + mock_log_data)
# Test a successful roll of zircon into garnet w/ no-op manifest update.
yield (api.test('zircon-no-manifest-update') + api.properties(
project='garnet',
remote='https://fuchsia.googlesource.com/garnet',
poll_interval_secs=0.001,
poll_timeout_secs=0.1) +
api.auto_roller.success_step_data() +
mock_manifest_data + noop_edit)
# Test a successful roll of zircon into garnet w/ no-op package update.
yield (api.test('no-package-update') + api.properties(
project='garnet',
remote='https://fuchsia.googlesource.com/garnet',
poll_interval_secs=0.001,
poll_timeout_secs=0.1) +
api.auto_roller.success_step_data() +
mock_manifest_data + mock_log_data + noop_package_edit)
# Test a successful roll of zircon into garnet with the default poll
# configuration.
yield (api.test('zircon_default') + api.properties(
project='garnet', remote='https://fuchsia.googlesource.com/garnet') +
api.auto_roller.success_step_data() +
mock_manifest_data + mock_log_data)
# Test a successful roll of zircon into garnet with the default poll
# configuration, and include untracked files.
yield (api.test('zircon_untracked') + api.properties(
project='garnet',
remote='https://fuchsia.googlesource.com/garnet',
commit_untracked_files=True) +
api.auto_roller.success_step_data() +
mock_manifest_data + mock_log_data)
# Test a no-op roll of zircon into garnet with the default poll
# configuration.
yield (api.test('zircon_noop') + api.properties(
project='garnet', remote='https://fuchsia.googlesource.com/garnet') +
api.step_data('check for no-op commit', api.raw_io.stream_output('')) +
mock_manifest_data + mock_log_data)
# Test a failure to roll zircon into garnet because CQ failed. The
# Commit-Queue label is unset at the first check during polling.
yield (api.test('zircon_cq_failure') + api.properties(
project='garnet',
remote='https://fuchsia.googlesource.com/garnet',
poll_interval_secs=0.001,
poll_timeout_secs=0.1) +
api.auto_roller.failure_step_data())
yield (api.test('zircon_abandoned') + api.properties(
project='garnet',
remote='https://fuchsia.googlesource.com/garnet',
poll_interval_secs=0.001,
poll_timeout_secs=0.1) +
api.auto_roller.abandoned_step_data())
# Test a dry-run of the auto-roller for rolling zircon into garnet. We
# substitute in mock data for the first check that the CQ dry-run completed by
# unsetting the CQ label to indicate that the CQ dry-run finished.
yield (api.test('zircon_dry_run') + api.properties(
project='garnet',
remote='https://fuchsia.googlesource.com/garnet',
dry_run=True,
poll_interval_secs=0.001,
poll_timeout_secs=0.1) +
api.auto_roller.dry_run_step_data() +
mock_manifest_data + mock_log_data)
# Test a failure to roll zircon because the auto-roller timed out. Sets the
# poll_timeout to be very close to the poll_interval so only one loop is
# made. Here, we substitute in mock data that indicates CQ is still running,
# but since we only try once, we will time out.
yield (api.test('zircon_timeout') + api.properties(
project='garnet',
remote='https://fuchsia.googlesource.com/garnet',
poll_interval_secs=0.001,
poll_timeout_secs=0.0015) +
api.auto_roller.timeout_step_data(iteration=0) +
api.auto_roller.timeout_step_data(iteration=1))
# Test a successful roll of zircon that passes after the final loop
# executes. We now check status after the last sleep in case the roll
# passed at the last second. Otherwise this test is setup as
# zircon_timeout above.
yield (api.test('zircon_pass_last_second') + api.properties(
project='garnet',
remote='https://fuchsia.googlesource.com/garnet',
poll_interval_secs=0.001,
poll_timeout_secs=0.0015) +
api.auto_roller.timeout_step_data(iteration=0) +
api.auto_roller.success_step_data(iteration=1) +
mock_manifest_data + mock_log_data)
# Test a successful roll of zircon with integral arguments to poll_*_secs.
# This tests for any regression in supporting integral values for
# polling-related properties.
yield (api.test('zircon_integral_poll_secs') + api.properties(
project='garnet',
remote='https://fuchsia.googlesource.com/garnet',
poll_interval_secs=1,
poll_timeout_secs=1) +
api.auto_roller.success_step_data() +
mock_manifest_data + mock_log_data)
# Test a successful roll of zircon with integral arguments to poll_*_secs.
# This tests for any regression in supporting integral values for
# polling-related properties.
yield (
api.test('zircon_existing_roll') +
api.properties(
project='garnet', remote='https://fuchsia.googlesource.com/garnet') +
api.step_data('git push', retcode=1) +
api.auto_roller.success_step_data() +
mock_manifest_data +
mock_log_data)
# yapf: enable