This is an automated email from the ASF dual-hosted git repository.

mousius pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new ce77d20c46 [ci] Allow skip tag anywhere in PR title (#11714)
ce77d20c46 is described below

commit ce77d20c4615c655214d0bd38307813e539ba9a2
Author: driazati <[email protected]>
AuthorDate: Tue Jun 28 00:49:35 2022 -0700

    [ci] Allow skip tag anywhere in PR title (#11714)
---
 tests/python/ci/test_ci.py        | 107 +++++++++++++++++++++-----------------
 tests/scripts/cmd_utils.py        |   8 +++
 tests/scripts/git_skip_ci.py      |  13 +++--
 tests/scripts/github_tag_teams.py |   7 +--
 4 files changed, 76 insertions(+), 59 deletions(-)

diff --git a/tests/python/ci/test_ci.py b/tests/python/ci/test_ci.py
index 8adf77d500..814344427f 100644
--- a/tests/python/ci/test_ci.py
+++ b/tests/python/ci/test_ci.py
@@ -256,49 +256,22 @@ def test_update_branch(tmpdir_factory):
     )
 
 
-def test_skip_ci(tmpdir_factory):
-    """
-    Test that CI is skipped when it should be
-    """
-    skip_ci_script = REPO_ROOT / "tests" / "scripts" / "git_skip_ci.py"
-
-    def test(commands, should_skip, pr_title, why):
-        git = TempGit(tmpdir_factory.mktemp("tmp_git_dir"))
-        # Jenkins git is too old and doesn't have 'git init --initial-branch'
-        git.run("init")
-        git.run("checkout", "-b", "main")
-        git.run("remote", "add", "origin", "https://github.com/apache/tvm.git";)
-        git.run("config", "user.name", "ci")
-        git.run("config", "user.email", "[email protected]")
-        git.run("commit", "--allow-empty", "--message", "base commit")
-        for command in commands:
-            git.run(*command)
-        pr_number = "1234"
-        proc = subprocess.run(
-            [str(skip_ci_script), "--pr", pr_number, "--pr-title", pr_title],
-            cwd=git.cwd,
-            check=False,
-        )
-        expected = 0 if should_skip else 1
-        assert proc.returncode == expected, why
-
-    test(
+@parameterize_named(
+    dict(
         commands=[],
         should_skip=False,
         pr_title="[skip ci] test",
-        why="ci should not be skipped",
-    )
-
-    test(
+        why="ci should not be skipped on main",
+    ),
+    dict(
         commands=[
             ["commit", "--allow-empty", "--message", "[skip ci] commit 1"],
         ],
         should_skip=False,
         pr_title="[skip ci] test",
         why="ci should not be skipped on main",
-    )
-
-    test(
+    ),
+    dict(
         commands=[
             ["checkout", "-b", "some_new_branch"],
             ["commit", "--allow-empty", "--message", "[skip ci] commit 1"],
@@ -306,9 +279,8 @@ def test_skip_ci(tmpdir_factory):
         should_skip=True,
         pr_title="[skip ci] test",
         why="ci should be skipped on a branch with [skip ci] in the last 
commit",
-    )
-
-    test(
+    ),
+    dict(
         commands=[
             ["checkout", "-b", "some_new_branch"],
             ["commit", "--allow-empty", "--message", "[skip ci] commit 1"],
@@ -317,9 +289,8 @@ def test_skip_ci(tmpdir_factory):
         pr_title="[no skip ci] test",
         why="ci should not be skipped on a branch with "
         "[skip ci] in the last commit but not the PR title",
-    )
-
-    test(
+    ),
+    dict(
         commands=[
             ["checkout", "-b", "some_new_branch"],
             ["commit", "--allow-empty", "--message", "[skip ci] commit 1"],
@@ -327,10 +298,9 @@ def test_skip_ci(tmpdir_factory):
         ],
         should_skip=True,
         pr_title="[skip ci] test",
-        why="ci should not be skipped with [skip ci] in the PR title",
-    )
-
-    test(
+        why="ci should be skipped with [skip ci] in the PR title",
+    ),
+    dict(
         commands=[
             ["checkout", "-b", "some_new_branch"],
             ["commit", "--allow-empty", "--message", "[skip ci] commit 1"],
@@ -338,10 +308,9 @@ def test_skip_ci(tmpdir_factory):
         ],
         should_skip=True,
         pr_title="[skip ci] test",
-        why="ci should not be skipped with [skip ci] in the PR title",
-    )
-
-    test(
+        why="ci should be skipped with [skip ci] in the PR title",
+    ),
+    dict(
         commands=[
             ["checkout", "-b", "some_new_branch"],
             ["commit", "--allow-empty", "--message", "commit 1"],
@@ -351,8 +320,48 @@ def test_skip_ci(tmpdir_factory):
         ],
         should_skip=True,
         pr_title="[skip ci] test",
-        why="ci should not be skipped with [skip ci] in the PR title",
+        why="ci should be skipped with [skip ci] in the PR title",
+    ),
+    dict(
+        commands=[
+            ["checkout", "-b", "some_new_branch"],
+        ],
+        should_skip=True,
+        pr_title="[something][skip ci] test",
+        why="skip ci tag should work anywhere in title",
+    ),
+)
+def test_skip_ci(tmpdir_factory, commands, should_skip, pr_title, why):
+    """
+    Test that CI is skipped when it should be
+    """
+    skip_ci_script = REPO_ROOT / "tests" / "scripts" / "git_skip_ci.py"
+
+    git = TempGit(tmpdir_factory.mktemp("tmp_git_dir"))
+    # Jenkins git is too old and doesn't have 'git init --initial-branch'
+    git.run("init")
+    git.run("checkout", "-b", "main")
+    git.run("remote", "add", "origin", "https://github.com/apache/tvm.git";)
+    git.run("config", "user.name", "ci")
+    git.run("config", "user.email", "[email protected]")
+    git.run("commit", "--allow-empty", "--message", "base commit")
+    for command in commands:
+        git.run(*command)
+    pr_number = "1234"
+    proc = subprocess.run(
+        [str(skip_ci_script), "--pr", pr_number, "--pr-title", pr_title],
+        cwd=git.cwd,
+        stderr=subprocess.STDOUT,
+        stdout=subprocess.PIPE,
+        encoding="utf-8",
+        check=False,
     )
+    expected = 0 if should_skip else 1
+    if proc.returncode != expected:
+        raise RuntimeError(
+            f"Unexpected return code {proc.returncode} "
+            f"(expected {expected}) in {why}:\n{proc.stdout}"
+        )
 
 
 def test_skip_globs(tmpdir_factory):
diff --git a/tests/scripts/cmd_utils.py b/tests/scripts/cmd_utils.py
index 771c3ee52d..f83ec6f24e 100644
--- a/tests/scripts/cmd_utils.py
+++ b/tests/scripts/cmd_utils.py
@@ -19,7 +19,9 @@ import subprocess
 import os
 import logging
 import sys
+import re
 from pathlib import Path
+from typing import List
 
 
 REPO_ROOT = Path(__file__).resolve().parent.parent.parent
@@ -62,3 +64,9 @@ class Sh:
         defaults.update(kwargs)
 
         return subprocess.run(cmd, **defaults)
+
+
+def tags_from_title(title: str) -> List[str]:
+    tags = re.findall(r"\[(.*?)\]", title)
+    tags = [t.strip() for t in tags]
+    return tags
diff --git a/tests/scripts/git_skip_ci.py b/tests/scripts/git_skip_ci.py
index 9b4d538bd0..1e02fcb964 100755
--- a/tests/scripts/git_skip_ci.py
+++ b/tests/scripts/git_skip_ci.py
@@ -17,9 +17,11 @@
 # under the License.
 
 import os
+import logging
 import argparse
 
 from git_utils import git, GitHubRepo, parse_remote
+from cmd_utils import tags_from_title, init_log
 
 
 if __name__ == "__main__":
@@ -31,6 +33,7 @@ if __name__ == "__main__":
         "--pr-title", help="(testing) PR title to use instead of fetching from 
GitHub"
     )
     args = parser.parse_args()
+    init_log()
 
     branch = git(["rev-parse", "--abbrev-ref", "HEAD"])
     log = git(["log", "--format=%s", "-1"])
@@ -46,12 +49,14 @@ if __name__ == "__main__":
             github = GitHubRepo(token=os.environ["TOKEN"], user=user, 
repo=repo)
             pr = github.get(f"pulls/{args.pr}")
             title = pr["title"]
-        print("pr title:", title)
-        return title.startswith("[skip ci]")
+        logging.info(f"pr title: {title}")
+        tags = tags_from_title(title)
+        logging.info(f"Found title tags: {tags}")
+        return "skip ci" in tags
 
     if args.pr != "null" and args.pr.strip() != "" and branch != "main" and 
check_pr_title():
-        print("PR title starts with '[skip ci]', skipping...")
+        logging.info("PR title starts with '[skip ci]', skipping...")
         exit(0)
     else:
-        print(f"Not skipping CI:\nargs.pr: {args.pr}\nbranch: 
{branch}\ncommit: {log}")
+        logging.info(f"Not skipping CI:\nargs.pr: {args.pr}\nbranch: 
{branch}\ncommit: {log}")
         exit(1)
diff --git a/tests/scripts/github_tag_teams.py 
b/tests/scripts/github_tag_teams.py
index f040c1edc9..4f03b4f71a 100755
--- a/tests/scripts/github_tag_teams.py
+++ b/tests/scripts/github_tag_teams.py
@@ -25,6 +25,7 @@ from typing import Dict, Any, List, Tuple
 
 
 from git_utils import git, GitHubRepo, parse_remote, find_ccs
+from cmd_utils import tags_from_title
 
 
 GITHUB_NAME_REGEX = r"@[a-zA-Z0-9-]+"
@@ -125,12 +126,6 @@ def parse_teams(r: Dict[str, Any], issue_number: int) -> 
Dict[str, str]:
     return {k.lower(): v for k, v in result.items() if k.strip()}
 
 
-def tags_from_title(title: str) -> List[str]:
-    tags = re.findall(r"\[(.*?)\]", title)
-    tags = [t.strip() for t in tags]
-    return tags
-
-
 def tags_from_labels(labels: List[Dict[str, Any]]) -> List[str]:
     return [label["name"] for label in labels]
 

Reply via email to