| # Copyright 2020 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. |
| """Recipe to auto roll changes by running a script in the same repo.""" |
| |
| from urlparse import urlparse |
| from recipe_engine.recipe_api import Property |
| |
| DEPS = [ |
| 'fuchsia/auto_roller', |
| 'fuchsia/git', |
| 'recipe_engine/context', |
| 'recipe_engine/path', |
| 'recipe_engine/properties', |
| 'recipe_engine/step', |
| ] |
| |
| PROPERTIES = { |
| 'remote': |
| Property(kind=str, help='Repository URL'), |
| 'script': |
| Property(kind=str, help='Script to run to update the repo'), |
| 'commit_untracked_files': |
| Property( |
| kind=bool, default=True, 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, remote, commit_untracked_files, script, dry_run): |
| # Get the name of the project (e.g. "infra/prebuilt", "samples", etc.) from |
| # the remote repository URL (e.g. "https://fuchsia.googlesource.com/infra/prebuilt") |
| project = urlparse(remote).path.lstrip('/') |
| # Check out the repo. |
| api.git.checkout(remote) |
| repo_dir = api.path['start_dir'].join(project) |
| |
| # Run update script |
| with api.context(cwd=repo_dir): |
| api.step('run %s' % script, [script]) |
| |
| # Land the changes made by the script |
| api.auto_roller.attempt_roll( |
| gerrit_project=project, |
| repo_dir=repo_dir, |
| commit_message='Updating with "%s"' % script, |
| commit_untracked=commit_untracked_files, |
| dry_run=dry_run) |
| |
| |
| def GenTests(api): |
| yield (api.test('basic') + api.properties( |
| remote='https://fuchsia.googlesource.com/samples', |
| script='example/script.sh') + api.auto_roller.success_step_data()) |