DPDK CI discussions
 help / color / mirror / Atom feed
From: Adam Hassick <ahassick@iol.unh.edu>
To: ci@dpdk.org
Cc: aconole@redhat.com, alialnu@nvidia.com,
	Adam Hassick <ahassick@iol.unh.edu>
Subject: [PATCH v1] tools: Update create_series_artifact script
Date: Wed, 17 Jul 2024 14:06:42 -0400	[thread overview]
Message-ID: <20240717180642.24550-1-ahassick@iol.unh.edu> (raw)

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


             reply	other threads:[~2024-07-17 18:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-17 18:06 Adam Hassick [this message]
2024-07-23 13:03 ` Aaron Conole

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240717180642.24550-1-ahassick@iol.unh.edu \
    --to=ahassick@iol.unh.edu \
    --cc=aconole@redhat.com \
    --cc=alialnu@nvidia.com \
    --cc=ci@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).