roll_util: Add extra label support to rollers
Add support to rollers for extra label arguments in the auto_roller
module.
Grabbing these arguments from roll_util module properties, so they don't
need to be retrieved and processed in each roller recipe.
Change-Id: I5c6bdae7e6034674e94840da2fb50a0427c9bb0b
Bug: 252
Reviewed-on: https://pigweed-review.googlesource.com/c/infra/recipes/+/19621
Commit-Queue: Rob Mohr <mohrr@google.com>
Reviewed-by: Gary Miguel <garymm@google.com>
diff --git a/recipe_modules/roll_util/__init__.py b/recipe_modules/roll_util/__init__.py
index 1ae69c6..38b9ef2 100644
--- a/recipe_modules/roll_util/__init__.py
+++ b/recipe_modules/roll_util/__init__.py
@@ -12,9 +12,13 @@
# License for the specific language governing permissions and limitations under
# the License.
+from PB.recipe_modules.pigweed.roll_util import properties
+
DEPS = [
'fuchsia/git',
'recipe_engine/context',
'recipe_engine/raw_io',
'recipe_engine/step',
]
+
+PROPERTIES = properties.InputProperties
diff --git a/recipe_modules/roll_util/api.py b/recipe_modules/roll_util/api.py
index 88c1a7f..96f8e5b 100644
--- a/recipe_modules/roll_util/api.py
+++ b/recipe_modules/roll_util/api.py
@@ -69,6 +69,11 @@
class RollUtilApi(recipe_api.RecipeApi):
+ def __init__(self, props, *args, **kwargs):
+ super(RollUtilApi, self).__init__(*args, **kwargs)
+ self.labels_to_set = {x.label: x.value for x in props.labels_to_set}
+ self.labels_to_wait_on = props.labels_to_wait_on
+
def _single_commit_roll_message(
self, project_name, commit, old_revision, new_revision
):
diff --git a/recipe_modules/roll_util/properties.proto b/recipe_modules/roll_util/properties.proto
new file mode 100644
index 0000000..598592d
--- /dev/null
+++ b/recipe_modules/roll_util/properties.proto
@@ -0,0 +1,33 @@
+// Copyright 2020 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+syntax = "proto3";
+
+package recipe_modules.pigweed.roll_util;
+
+message LabelToSet {
+ // Name of label to set.
+ string label = 1;
+
+ // Value of label to set.
+ int32 value = 2;
+}
+
+message InputProperties {
+ // Additional labels to set when uploading patches.
+ repeated LabelToSet labels_to_set = 1;
+
+ // Non-CQ/CR labels to wait on before attempting submission.
+ repeated string labels_to_wait_on = 2;
+}
\ No newline at end of file
diff --git a/recipe_modules/roll_util/tests/full.expected/labels.json b/recipe_modules/roll_util/tests/full.expected/labels.json
new file mode 100644
index 0000000..f4d2826
--- /dev/null
+++ b/recipe_modules/roll_util/tests/full.expected/labels.json
@@ -0,0 +1,19 @@
+[
+ {
+ "cmd": [],
+ "name": "labels_to_set",
+ "~followup_annotations": [
+ "@@@STEP_SUMMARY_TEXT@{u'Trigger': 1}@@@"
+ ]
+ },
+ {
+ "cmd": [],
+ "name": "labels_to_wait_on",
+ "~followup_annotations": [
+ "@@@STEP_SUMMARY_TEXT@[u'Verified', u'Good']@@@"
+ ]
+ },
+ {
+ "name": "$result"
+ }
+]
\ No newline at end of file
diff --git a/recipe_modules/roll_util/tests/full.py b/recipe_modules/roll_util/tests/full.py
index 3064765..b6b1b72 100644
--- a/recipe_modules/roll_util/tests/full.py
+++ b/recipe_modules/roll_util/tests/full.py
@@ -21,13 +21,14 @@
'pigweed/roll_util',
'recipe_engine/path',
'recipe_engine/properties',
+ 'recipe_engine/step',
]
PROPERTIES = {
- 'project_name': Property(kind=str),
- 'original_commits': Property(kind=List),
- 'old_revision': Property(kind=str),
- 'new_revision': Property(kind=str),
+ 'project_name': Property(kind=str, default=None),
+ 'original_commits': Property(kind=List, default=None),
+ 'old_revision': Property(kind=str, default=None),
+ 'new_revision': Property(kind=str, default=None),
}
@@ -36,14 +37,24 @@
):
proj_dir = api.path['start_dir'].join('project')
- if api.roll_util.check_roll_direction(
- api.path['checkout'], old_revision, new_revision
- ):
- api.roll_util.message(
- project_name, proj_dir, old_revision, new_revision
- )
- else:
- api.roll_util.backwards_roll_step('remote', old_revision, new_revision)
+ if project_name:
+ if api.roll_util.check_roll_direction(
+ api.path['checkout'], old_revision, new_revision
+ ):
+ api.roll_util.message(
+ project_name, proj_dir, old_revision, new_revision
+ )
+ else:
+ api.roll_util.backwards_roll_step(
+ 'remote', old_revision, new_revision
+ )
+
+ if api.roll_util.labels_to_set:
+ with api.step.nest('labels_to_set') as pres:
+ pres.step_summary_text = repr(api.roll_util.labels_to_set)
+ if api.roll_util.labels_to_wait_on:
+ with api.step.nest('labels_to_wait_on') as pres:
+ pres.step_summary_text = repr(api.roll_util.labels_to_wait_on)
def GenTests(api): # pylint: disable=invalid-name
@@ -120,3 +131,12 @@
)
+ api.roll_util.cancelled()
)
+
+ properties = {
+ '$pigweed/roll_util': {
+ 'labels_to_set': [{'label': 'Trigger', 'value': 1}],
+ 'labels_to_wait_on': ['Verified', 'Good'],
+ },
+ }
+
+ yield api.status_check.test('labels') + api.properties(**properties)