| # 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/gerrit", |
| "fuchsia/git", |
| "fuchsia/status_check", |
| "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. |
| repo_dir = api.path["start_dir"].join(project) |
| with api.step.nest("checkout %s" % project): |
| api.git.checkout(remote, path=repo_dir) |
| |
| # Run update script |
| with api.context(cwd=repo_dir): |
| api.step("run %s" % script, [script]) |
| |
| # Land the changes made by the script |
| change = api.auto_roller.attempt_roll( |
| api.gerrit.host_from_remote_url(remote), |
| gerrit_project=project, |
| repo_dir=repo_dir, |
| commit_message='Updating with "%s"' % script, |
| commit_untracked=commit_untracked_files, |
| dry_run=dry_run, |
| ) |
| |
| return api.auto_roller.raw_result(change) |
| |
| |
| def GenTests(api): |
| yield ( |
| api.status_check.test("basic") |
| + api.properties( |
| remote="https://fuchsia.googlesource.com/foo/bar", |
| script="example/script.sh", |
| ) |
| + api.auto_roller.success() |
| ) |