DPDK CI discussions
 help / color / mirror / Atom feed
* [PATCH v1] tools: Update create_series_artifact script
@ 2024-07-17 18:06 Adam Hassick
  2024-07-23 13:03 ` Aaron Conole
  0 siblings, 1 reply; 2+ messages in thread
From: Adam Hassick @ 2024-07-17 18:06 UTC (permalink / raw)
  To: ci; +Cc: aconole, alialnu, Adam Hassick

This is a collection of small changes to the create_artifact_script
that the community lab has made over the past several months. The
most notable change is the addition of the "branch" argument, which
allows the caller to specify a branch to apply on.

* Add branch override argument.
* Default to main branch if guess_git_tree fails.
* Return list of default patch tags if patch_parser fails.
* Use patch name instead of database ID for the patch file name.

Signed-off-by: Adam Hassick <ahassick@iol.unh.edu>
---
 tools/create_series_artifact.py | 51 +++++++++++++++++++++++++++------
 1 file changed, 43 insertions(+), 8 deletions(-)

diff --git a/tools/create_series_artifact.py b/tools/create_series_artifact.py
index 235896c..550ea82 100755
--- a/tools/create_series_artifact.py
+++ b/tools/create_series_artifact.py
@@ -47,6 +47,7 @@ BRANCH_NAME_MAP = {
 
 @dataclass
 class CreateSeriesParameters(object):
+    branch_override: Optional[str]
     pw_server: str
     pw_project: str
     pw_token: str
@@ -95,7 +96,8 @@ class ProjectTree(object):
     def move_logs(self):
         shutil.move(self.log_file_path, pathlib.Path(os.getcwd(), "log.txt"))
         shutil.move(
-            self.props_file_path, pathlib.Path(os.getcwd(), self.data.output_properties)
+            self.props_file_path,
+            pathlib.Path(os.getcwd(), self.data.output_properties),
         )
 
     def __init__(self, data: CreateSeriesParameters):
@@ -302,12 +304,23 @@ class ProjectTree(object):
         return True
 
 
+def get_patch_filename(patch_name: str) -> str:
+    filename: str = "".join(
+        [
+            "-" if char.isspace() else char.lower()
+            for char in patch_name
+            if char.isalnum() or char.isspace()
+        ]
+    )
+    return f"{filename}.patch"
+
+
 def get_tags(
     patch_parser_script: pathlib.Path,
     patch_parser_cfg: pathlib.Path,
     series: Dict,
 ) -> List[str]:
-    series_filename = f"{series['id']}.patch"
+    series_filename = get_patch_filename(series.get("name", "unnamed"))
 
     # Pull down the patch series as a single file.
     pw_api.download(series["mbox"], None, series_filename)
@@ -320,7 +333,13 @@ def get_tags(
     )
 
     # Assert that patch parser succeeded.
-    parse_result.check_returncode()
+    if parse_result.returncode != 0:
+        print(
+            "WARNING: Patch parsing for tags failed:",
+            parse_result.stderr.decode(),
+        )
+        # Return some default tags.
+        return ["core", "driver", "application"]
 
     # Return the output
     return parse_result.stdout.decode().splitlines()
@@ -360,6 +379,9 @@ def parse_args() -> argparse.Namespace:
         action="store_true",
         help="When set, does not acknowledge the Depends-on label.",
     )
+    parser.add_argument(
+        "-b", "--branch", type=str, help="When present, apply on this branch."
+    )
 
     return parser.parse_args()
 
@@ -409,6 +431,7 @@ def collect_series_info(args: argparse.Namespace) -> CreateSeriesParameters:
     patch_ids.sort()
 
     return CreateSeriesParameters(
+        branch_override=args.branch,
         pw_server=pw_server,
         pw_project=pw_project,
         pw_token=pw_token,
@@ -440,17 +463,29 @@ def main() -> int:
     # Pull down the DPDK mirror.
     tree = ProjectTree(data)
 
-    # Try to guess the Git tree for this patchset.
-    guessed_tree = tree.guess_git_tree()
+    if data.branch_override:
+        guessed_tree: str = (
+            BRANCH_NAME_MAP.get(data.branch_override) or data.branch_override
+        )
+
+        # Try to check out to the tree.
+        if not tree.checkout(guessed_tree):
+            print(
+                f'Could not checkout to specified branch "{data.branch_override}" because it did not exist.'
+            )
+            return 1
+    else:
+        guessed_tree = tree.guess_git_tree()
 
     if not guessed_tree:
-        print("Failed to guess git tree.")
-        return 1
+        print("Failed to guess git tree. Trying main instead...")
+        guessed_tree = "main"
 
     # Try to apply this patch.
     if not (
         try_to_apply(tree)  # First, try to apply on the guessed tree.
-        or guessed_tree != "main"  # If that fails, and the guessed tree was not main
+        or not data.branch_override  # Skip when branch is given
+        and guessed_tree != "main"  # 2nd attempt on main if guess not main
         and tree.checkout("main")  # Checkout to main, then
         and try_to_apply(tree)  # Try to apply on main
     ):
-- 
2.45.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] tools: Update create_series_artifact script
  2024-07-17 18:06 [PATCH v1] tools: Update create_series_artifact script Adam Hassick
@ 2024-07-23 13:03 ` Aaron Conole
  0 siblings, 0 replies; 2+ messages in thread
From: Aaron Conole @ 2024-07-23 13:03 UTC (permalink / raw)
  To: Adam Hassick; +Cc: ci, alialnu

Adam Hassick <ahassick@iol.unh.edu> writes:

> This is a collection of small changes to the create_artifact_script
> that the community lab has made over the past several months. The
> most notable change is the addition of the "branch" argument, which
> allows the caller to specify a branch to apply on.
>
> * Add branch override argument.
> * Default to main branch if guess_git_tree fails.
> * Return list of default patch tags if patch_parser fails.
> * Use patch name instead of database ID for the patch file name.
>
> Signed-off-by: Adam Hassick <ahassick@iol.unh.edu>
> ---

Thanks, applied!


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-23 13:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-17 18:06 [PATCH v1] tools: Update create_series_artifact script Adam Hassick
2024-07-23 13:03 ` Aaron Conole

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).