| # Copyright 2019 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 for updating the code search super manifest project.""" |
| |
| from recipe_engine.recipe_api import Property |
| |
| DEPS = [ |
| "fuchsia/checkout", |
| "fuchsia/git", |
| "fuchsia/jiri", |
| "fuchsia/status_check", |
| "recipe_engine/context", |
| "recipe_engine/file", |
| "recipe_engine/path", |
| "recipe_engine/properties", |
| "recipe_engine/step", |
| ] |
| |
| PROPERTIES = { |
| "manifest": Property(kind=str, help="Jiri manifest to use.", default="flower"), |
| "remote": Property(kind=str, help="Remote manifest repository.",), |
| "super_manifest_project": Property( |
| kind=str, help="Super manifest project to update.", |
| ), |
| "dry_run": Property(kind=bool, help="Don't push changes.", default=False), |
| } |
| |
| GENERATE_SCRIPT = "setup.sh" |
| |
| |
| def RunSteps(api, manifest, remote, super_manifest_project, dry_run): |
| api.checkout.fuchsia_with_options( |
| manifest=manifest, |
| path=api.path["start_dir"], |
| remote=remote, |
| fetch_packages=False, |
| ) |
| |
| with api.step.nest("checkout super manifest project"): |
| super_manifest_project_path = api.path["start_dir"].join("super") |
| api.file.ensure_directory("make dirs", super_manifest_project_path) |
| |
| api.git.checkout( |
| url=super_manifest_project, |
| path=super_manifest_project_path, |
| submodules=False, |
| ) |
| |
| generate_script_path = super_manifest_project_path.join(GENERATE_SCRIPT) |
| with api.context(cwd=super_manifest_project_path): |
| # See https://fuchsia.googlesource.com/jiri/+/master/cmd/jiri/generate-gitmodules.go |
| # for details. |
| api.jiri( |
| "generate-gitmodules", |
| "--redir-root", |
| "--generate-script", |
| generate_script_path, |
| ".gitmodules", |
| ) |
| api.step("run %s" % GENERATE_SCRIPT, [generate_script_path]) |
| api.file.remove("remove %s" % GENERATE_SCRIPT, generate_script_path) |
| # Add & Push updated submodules. |
| api.git.add(pathspec=".gitmodules") |
| # Only commit and push if we have a diff, otherwise commit fails. |
| if api.git.diff( |
| ref_base=None, cached=True, exit_code=True, ok_ret="any" |
| ).retcode: |
| api.git.commit(message="Update submodules based on jiri manifest") |
| api.git.push("HEAD:master", dryrun=dry_run) |
| |
| |
| def GenTests(api): |
| def props(**kwargs): |
| return api.properties( |
| remote="https://fuchsia.googlesource.com/integration", |
| super_manifest_project="https://fuchsia.googlesource.com/super", |
| **kwargs |
| ) |
| |
| yield api.status_check.test("no_diff") + props() |
| yield api.status_check.test("yes_diff") + props() + api.step_data( |
| "git diff", retcode=1 |
| ) |
| yield api.status_check.test("dry_run") + props(dry_run=True) + api.step_data( |
| "git diff", retcode=1 |
| ) |