diff --git a/Jenkinsfile b/Jenkinsfile index 364c3b99b985a..2b73508da0d34 100755 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -45,7 +45,7 @@ // 'python3 jenkins/generate.py' // Note: This timestamp is here to ensure that updates to the Jenkinsfile are // always rebased on main before merging: -// Generated at 2022-08-30T15:23:03.836398 +// Generated at 2022-08-30T15:26:50.100067 import org.jenkinsci.plugins.pipeline.modeldefinition.Utils // NOTE: these lines are scanned by docker/dev_common.sh. Please update the regex as needed. --> @@ -311,7 +311,7 @@ def check_pr(pr_number) { variable: 'GITHUB_TOKEN', )]) { sh ( - script: "python3 tests/scripts/check_pr.py --pr ${pr_number}", + script: "python3 ci/scripts/check_pr.py --pr ${pr_number}", label: 'Check PR title and body', ) } diff --git a/ci/jenkins/Prepare.groovy.j2 b/ci/jenkins/Prepare.groovy.j2 index 7dbbb291fdf42..6d0c0ec9c4b69 100644 --- a/ci/jenkins/Prepare.groovy.j2 +++ b/ci/jenkins/Prepare.groovy.j2 @@ -161,7 +161,7 @@ def check_pr(pr_number) { variable: 'GITHUB_TOKEN', )]) { sh ( - script: "python3 tests/scripts/check_pr.py --pr ${pr_number}", + script: "python3 ci/scripts/check_pr.py --pr ${pr_number}", label: 'Check PR title and body', ) } diff --git a/tests/scripts/check_pr.py b/ci/scripts/check_pr.py similarity index 83% rename from tests/scripts/check_pr.py rename to ci/scripts/check_pr.py index 94a9180c83b43..00b0246edd0c8 100644 --- a/tests/scripts/check_pr.py +++ b/ci/scripts/check_pr.py @@ -29,6 +29,7 @@ GITHUB_USERNAME_REGEX = re.compile(r"(@[a-zA-Z0-9-]+)", flags=re.MULTILINE) OK = object() +FAIL = object() @dataclass @@ -42,48 +43,44 @@ class Check: def non_empty(s: str): if len(s) == 0: - return False + return FAIL return OK def usernames(s: str): m = GITHUB_USERNAME_REGEX.findall(s) - if m and len(m) > 0: - return m - return OK + return m if m else OK def tags(s: str): items = tags_from_title(s) if len(items) == 0: - return False + return FAIL return OK def trailing_period(s: str): if s.endswith("."): - return False + return FAIL return OK title_checks = [ Check(check=non_empty, error_fn=lambda d: "PR must have a title but title was empty"), Check(check=trailing_period, error_fn=lambda d: "PR must not end in a tailing '.'"), - Check( - check=usernames, - error_fn=lambda d: f"PR title must not tag anyone but found these usernames: {d}", - ), - Check( - check=tags, - error_fn=lambda d: f"PR title must have a topic tag like [the_topic] (e.g. [tir], [relay], etc.) but found none", - ), + # TODO(driazati): enable this check once https://github.com/apache/tvm/issues/12637 is done + # Check( + # check=usernames, + # error_fn=lambda d: f"PR title must not tag anyone but found these usernames: {d}", + # ), ] body_checks = [ Check(check=non_empty, error_fn=lambda d: "PR must have a body but body was empty"), - Check( - check=usernames, - error_fn=lambda d: f"PR body must not tag anyone but found these usernames: {d}", - ), + # TODO(driazati): enable this check once https://github.com/apache/tvm/issues/12637 is done + # Check( + # check=usernames, + # error_fn=lambda d: f"PR body must not tag anyone but found these usernames: {d}", + # ), ] @@ -139,6 +136,9 @@ def run_checks(checks: List[Check], s: str, name: str) -> bool: body = pr["body"] title = pr["title"] + body = body.strip() + title = title.strip() + title_passed = run_checks(checks=title_checks, s=title, name="PR title") print("") body_passed = run_checks(checks=body_checks, s=body, name="PR body") @@ -147,5 +147,7 @@ def run_checks(checks: List[Check], s: str, name: str) -> bool: print("All checks passed!") exit(0) else: - print("Some checks failed, please review the logs above") + print( + "Some checks failed, please review the logs above and edit your PR on GitHub accordingly" + ) exit(1)