roll_commenter: Add logging to revision logic Bug: b/525381446 Change-Id: I90e3a3db0099a37e66df1d84ec8f3db2a41adf84 Reviewed-on: https://pigweed-review.googlesource.com/c/infra/recipes/+/424992
diff --git a/recipes/roll_commenter.py b/recipes/roll_commenter.py index a586b21..640ae87 100644 --- a/recipes/roll_commenter.py +++ b/recipes/roll_commenter.py
@@ -148,7 +148,8 @@ build: build_pb.Build, ) -> str | None: if build.status != common_pb.SUCCESS: - return + api.step.empty('build not successful') + return None input_props = json_format.MessageToDict(build.input.properties) or {} er_input = input_props.get('checkout_options', {}).get( @@ -165,7 +166,8 @@ continue # pragma: no cover if roll.get('dry_run', True): - return + api.step.empty('dry run') + return None for _, value in output_props.items(): if not isinstance(value, Mapping): @@ -178,20 +180,28 @@ value['remote'], ): if 'revision' in value: + api.step.empty(f'found revision {value["revision"]}') return value['revision'] + api.step.empty(f'found new revision {value["new"]}') return value['new'] + api.step.empty('no matching revision') + return None + def _get_current_revision( api: recipe_api.RecipeScriptApi, remote: str, builds: Sequence[build_pb.Build], ) -> str | None: - for build in builds: - if res := _get_revision_from_build(api, remote, build): - return res + with api.step.nest('get current revision'): + for build in builds: + api.step.empty(f'checking build {build.id}') + if res := _get_revision_from_build(api, remote, build): + return res - return None + api.step.empty('no revision found') + return None class State(TypedDict): @@ -874,12 +884,19 @@ return result def passed( - *, n: int, dry_run: bool = False, **kwargs: Any + *, + n: int, + dry_run: bool = False, + wrong_remote: bool = False, + **kwargs: Any, ) -> build_pb.Build: build = api.builder_status.passed(**kwargs) key = 'new' if n % 2 else 'revision' + remote = ( + 'https://wrong.git' if wrong_remote else api.checkout.pigweed_repo + ) build.output.properties['pigweed'] = { - 'remote': api.checkout.pigweed_repo, + 'remote': remote, key: commit40(n), } build.output.properties['gerrit_changes'] = [ @@ -1274,3 +1291,16 @@ ), drop_expectations_must_be_last(), ) + + yield api.test( + 'wrong_remote', + checkout_options(), + roller_props('foo-roller', 'bar-roller'), + api.checkout.ci_test_data(), + state_in(last=12, warned=(), foo_roller=12, bar_roller=12), + results('foo-roller', passed(id=88001, n=12, wrong_remote=True)), + results('bar-roller', passed(id=88002, n=12)), + skipping('foo-roller'), + state_out(last=12, bar_roller=12), + drop_expectations_must_be_last(), + )