Trigger GitHub CI with a comment on PR (#35211)
* fix * fix * comment * final * final * final --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
This commit is contained in:
@@ -15,19 +15,20 @@
|
||||
"""
|
||||
This script is used to get the models for which to run slow CI.
|
||||
|
||||
A new model added in a pull request will be included, as well as models specified in a commit message with a prefix
|
||||
`[run-slow]`, `[run_slow]` or `[run slow]`. For example, the commit message `[run_slow]bert, gpt2` will give `bert` and
|
||||
`gpt2`.
|
||||
A new model added in a pull request will be included, as well as models specified in a GitHub pull request's comment
|
||||
with a prefix `run-slow`, `run_slow` or `run slow`. For example, the commit message `run_slow: bert, gpt2` will give
|
||||
`bert` and `gpt2`.
|
||||
|
||||
Usage:
|
||||
|
||||
```bash
|
||||
python utils/pr_slow_ci_models.py.py
|
||||
python utils/pr_slow_ci_models.py
|
||||
```
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import string
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
@@ -89,7 +90,7 @@ def get_new_python_files() -> List[str]:
|
||||
|
||||
def get_new_model():
|
||||
new_files = get_new_python_files()
|
||||
reg = re.compile(r"src/transformers/(models/.*)/modeling_.*\.py")
|
||||
reg = re.compile(r"src/transformers/models/(.*)/modeling_.*\.py")
|
||||
|
||||
new_model = ""
|
||||
for x in new_files:
|
||||
@@ -101,45 +102,53 @@ def get_new_model():
|
||||
return new_model
|
||||
|
||||
|
||||
def parse_commit_message(commit_message: str) -> str:
|
||||
def parse_message(message: str) -> str:
|
||||
"""
|
||||
Parses the commit message to find the models specified in it to run slow CI.
|
||||
Parses a GitHub pull request's comment to find the models specified in it to run slow CI.
|
||||
|
||||
Args:
|
||||
commit_message (`str`): The commit message of the current commit.
|
||||
message (`str`): The body of a GitHub pull request's comment.
|
||||
|
||||
Returns:
|
||||
`str`: The substring in `commit_message` after `[run-slow]`, [run_slow]` or [run slow]`. If no such prefix is
|
||||
found, the empty string is returned.
|
||||
`str`: The substring in `message` after `run-slow`, run_slow` or run slow`. If no such prefix is found, the
|
||||
empty string is returned.
|
||||
"""
|
||||
if commit_message is None:
|
||||
if message is None:
|
||||
return ""
|
||||
|
||||
command_search = re.search(r"\[([^\]]*)\](.*)", commit_message)
|
||||
if command_search is None:
|
||||
message = message.strip().lower()
|
||||
|
||||
# run-slow: model_1, model_2
|
||||
if not message.startswith(("run-slow", "run_slow", "run slow")):
|
||||
return ""
|
||||
message = message[len("run slow") :]
|
||||
# remove leading `:`
|
||||
while message.strip().startswith(":"):
|
||||
message = message.strip()[1:]
|
||||
|
||||
command = command_search.groups()[0]
|
||||
command = command.lower().replace("-", " ").replace("_", " ")
|
||||
run_slow = command == "run slow"
|
||||
if run_slow:
|
||||
models = command_search.groups()[1].strip()
|
||||
return models
|
||||
else:
|
||||
return ""
|
||||
return message
|
||||
|
||||
|
||||
def get_models(commit_message: str):
|
||||
models = parse_commit_message(commit_message)
|
||||
return [f"models/{x}" for x in models.replace(",", " ").split()]
|
||||
def get_models(message: str):
|
||||
models = parse_message(message)
|
||||
return models.replace(",", " ").split()
|
||||
|
||||
|
||||
def check_model_names(model_name: str):
|
||||
allowed = string.ascii_letters + string.digits + "_"
|
||||
return not (model_name.startswith("_") or model_name.endswith("_")) and all(c in allowed for c in model_name)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--commit_message", type=str, default="", help="The commit message.")
|
||||
parser.add_argument("--message", type=str, default="", help="The content of a comment.")
|
||||
args = parser.parse_args()
|
||||
|
||||
new_model = get_new_model()
|
||||
specified_models = get_models(args.commit_message)
|
||||
specified_models = get_models(args.message)
|
||||
models = ([] if new_model == "" else [new_model]) + specified_models
|
||||
# a guard for strange model names
|
||||
models = [model for model in models if check_model_names(model)]
|
||||
# Add "models/"
|
||||
models = [f"models/{model}" for model in models]
|
||||
print(sorted(set(models)))
|
||||
|
||||
Reference in New Issue
Block a user