forked from apache/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add @slow decorator to run tests on
main
(apache#10057)
* Add @slow decorator to run tests on `main` This adds the infrastructure discussed in https://discuss.tvm.apache.org/t/rfc-ci-skip-slow-tests-on-prs/11910, but without affecting any tests. As we investigate reasons behind [slow tests](https://gist.github.com/driazati/e009f09ff44c6bc91c4d95a8e17fd6f1) in CI, this decorator will allow us to move these to run only on `main` and not PRs after checking with all concerned parties. * cleanup Co-authored-by: driazati <driazati@users.noreply.github.com>
- Loading branch information
1 parent
c3464fe
commit ac6c35b
Showing
3 changed files
with
142 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/usr/bin/env python3 | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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 | ||
# | ||
# http://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. | ||
|
||
import os | ||
import json | ||
import argparse | ||
import subprocess | ||
import re | ||
import textwrap | ||
from urllib import request | ||
from typing import Dict, Tuple, Any, List, Optional | ||
|
||
|
||
from git_utils import GitHubRepo, parse_remote, git | ||
|
||
|
||
SLOW_TEST_TRIGGERS = [ | ||
"@ci run slow tests", | ||
"@ci run slow test", | ||
"@ci run slow", | ||
"@ci slow tests", | ||
"@ci slow test", | ||
"@ci slow", | ||
] | ||
|
||
|
||
def check_match(s: str, searches: List[str]) -> Tuple[bool, Optional[str]]: | ||
for search in searches: | ||
if search in s: | ||
return True, search | ||
|
||
return False, None | ||
|
||
|
||
def display(long_str: str) -> str: | ||
return textwrap.indent(long_str, " ") | ||
|
||
|
||
if __name__ == "__main__": | ||
help = "Exits with 1 if CI should run slow tests, 0 otherwise" | ||
parser = argparse.ArgumentParser(description=help) | ||
parser.add_argument("--pr", required=True) | ||
parser.add_argument("--remote", default="origin", help="ssh remote to parse") | ||
parser.add_argument( | ||
"--pr-body", help="(testing) PR body to use instead of fetching from GitHub" | ||
) | ||
args = parser.parse_args() | ||
|
||
branch = git(["rev-parse", "--abbrev-ref", "HEAD"]) | ||
|
||
# Don't skip slow tests on main or ci-docker-staging | ||
skip_branches = {"main", "ci-docker-staging"} | ||
if branch in skip_branches: | ||
print(f"Branch {branch} is in {skip_branches}, running slow tests") | ||
exit(1) | ||
print(f"Branch {branch} is not in {skip_branches}, checking last commit...") | ||
|
||
log = git(["log", "--format=%B", "-1"]) | ||
|
||
# Check if anything in the last commit's body message matches | ||
log_match, reason = check_match(log, SLOW_TEST_TRIGGERS) | ||
if log_match: | ||
print(f"Matched {reason} in commit message:\n{display(log)}, running slow tests") | ||
exit(1) | ||
|
||
print( | ||
f"Last commit:\n{display(log)}\ndid not have any of {SLOW_TEST_TRIGGERS}, checking PR body..." | ||
) | ||
|
||
if args.pr_body: | ||
body = args.pr_body | ||
else: | ||
remote = git(["config", "--get", f"remote.{args.remote}.url"]) | ||
user, repo = parse_remote(remote) | ||
|
||
github = GitHubRepo(token=os.environ["GITHUB_TOKEN"], user=user, repo=repo) | ||
pr = github.get(f"pulls/{args.pr}") | ||
body = pr["body"] | ||
|
||
body_match, reason = check_match(body, SLOW_TEST_TRIGGERS) | ||
|
||
if body_match: | ||
print(f"Matched {reason} in PR body:\n{display(body)}, running slow tests") | ||
exit(1) | ||
|
||
print( | ||
f"PR Body:\n{display(body)}\ndid not have any of {SLOW_TEST_TRIGGERS}, skipping slow tests" | ||
) | ||
exit(0) |