Skip to content

Commit 30df0fc

Browse files
authored
Merge pull request ClickHouse#61725 from ClickHouse/ci_modify_ci_from_pr_body
CI: modify CI from PR body
2 parents e562a7c + 389566f commit 30df0fc

File tree

5 files changed

+72
-29
lines changed

5 files changed

+72
-29
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,33 @@ At a minimum, the following information should be added (but add more as needed)
4040

4141

4242
> Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/
43+
44+
---
45+
### Modify your CI run:
46+
##### NOTE:
47+
- if your merge the PR with modified CI you **MUST** know what you are doing.
48+
- modifiers can be applied only if set before CI starts
49+
- remove `!` to apply
50+
- return all `!` to restore defaults
51+
```
52+
!#ci_set_<SET_NAME> - to run only preconfigured set of tests, e.g.:
53+
!#ci_set_arm - to run only integration tests on ARM
54+
!#ci_set_integration - to run only integration tests on AMD
55+
!#ci_set_analyzer - to run only tests for analyzer
56+
NOTE: you can configure your own ci set
57+
```
58+
```
59+
!#job_<JOB NAME> - to run only specified job, e.g.:
60+
!#job_stateless_tests_release
61+
!#job_package_debug
62+
!#job_style_check
63+
!#job_integration_tests_asan
64+
```
65+
```
66+
!#batch_2 - to run only 2nd batch for all multi-batch jobs
67+
!#btach_1_2_3 - to run only 1, 2, 3rd batch for all multi-batch jobs
68+
```
69+
```
70+
!#no_merge_commit - to disable merge commit (no merge from master)
71+
!#do_not_test - to disable whole CI (except style check)
72+
```

.gitmessage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626

2727
## To run only specified batches for multi-batch job(s)
2828
#batch_2
29-
#btach_1_2_3
29+
#batch_1_2_3

tests/ci/ci.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,15 +1407,25 @@ def _concurrent_create_status(job: str, batch: int, num_batches: int) -> None:
14071407
print("... CI report update - done")
14081408

14091409

1410-
def _fetch_commit_tokens(message: str) -> List[str]:
1411-
pattern = r"#[\w-]+"
1412-
matches = [match[1:] for match in re.findall(pattern, message)]
1410+
def _fetch_commit_tokens(message: str, pr_info: PRInfo) -> List[str]:
1411+
pattern = r"([^!]|^)#(\w+)"
1412+
matches = [match[-1] for match in re.findall(pattern, message)]
14131413
res = [
14141414
match
14151415
for match in matches
14161416
if match in Labels or match.startswith("job_") or match.startswith("batch_")
14171417
]
1418-
return res
1418+
print(f"CI modifyers from commit message: [{res}]")
1419+
res_2 = []
1420+
if pr_info.is_pr():
1421+
matches = [match[-1] for match in re.findall(pattern, pr_info.body)]
1422+
res_2 = [
1423+
match
1424+
for match in matches
1425+
if match in Labels or match.startswith("job_") or match.startswith("batch_")
1426+
]
1427+
print(f"CI modifyers from PR body: [{res_2}]")
1428+
return list(set(res + res_2))
14191429

14201430

14211431
def _upload_build_artifacts(
@@ -1701,8 +1711,7 @@ def main() -> int:
17011711
message = args.commit_message or git_runner.run(
17021712
f"{GIT_PREFIX} log {pr_info.sha} --format=%B -n 1"
17031713
)
1704-
tokens = _fetch_commit_tokens(message)
1705-
print(f"Commit message tokens: [{tokens}]")
1714+
tokens = _fetch_commit_tokens(message, pr_info)
17061715
if Labels.NO_MERGE_COMMIT in tokens and CI:
17071716
git_runner.run(f"{GIT_PREFIX} checkout {pr_info.sha}")
17081717
git_ref = git_runner.run(f"{GIT_PREFIX} rev-parse HEAD")

tests/ci/pr_info.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ def is_release(self) -> bool:
316316
def is_release_branch(self) -> bool:
317317
return self.number == 0
318318

319+
def is_pr(self):
320+
return self.event_type == EventType.PULL_REQUEST
321+
319322
def is_scheduled(self):
320323
return self.event_type == EventType.SCHEDULE
321324

tests/ci/style_check.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
import sys
99
from concurrent.futures import ProcessPoolExecutor
1010
from pathlib import Path
11-
from typing import List, Tuple, Union
11+
from typing import List, Tuple
1212

13-
import magic
1413
from docker_images_helper import get_docker_image, pull_image
1514
from env_helper import CI, REPO_COPY, TEMP_PATH
1615
from git_helper import GIT_PREFIX, git_runner
@@ -96,32 +95,34 @@ def commit_push_staged(pr_info: PRInfo) -> None:
9695
git_runner(push_cmd)
9796

9897

99-
def is_python(file: Union[Path, str]) -> bool:
98+
def is_python(file: str) -> bool:
10099
"""returns if the changed file in the repository is python script"""
101100
# WARNING: python-magic v2:0.4.24-2 is used in ubuntu 22.04,
102101
# and `Support os.PathLike values in magic.from_file` is only from 0.4.25
103-
try:
104-
return bool(
105-
magic.from_file(os.path.join(REPO_COPY, file), mime=True)
106-
== "text/x-script.python"
107-
)
108-
except IsADirectoryError:
109-
# Process submodules w/o errors
110-
return False
111-
112-
113-
def is_shell(file: Union[Path, str]) -> bool:
102+
# try:
103+
# return bool(
104+
# magic.from_file(os.path.join(REPO_COPY, file), mime=True)
105+
# == "text/x-script.python"
106+
# )
107+
# except IsADirectoryError:
108+
# # Process submodules w/o errors
109+
# return False
110+
return file.endswith(".py")
111+
112+
113+
def is_shell(file: str) -> bool:
114114
"""returns if the changed file in the repository is shell script"""
115115
# WARNING: python-magic v2:0.4.24-2 is used in ubuntu 22.04,
116116
# and `Support os.PathLike values in magic.from_file` is only from 0.4.25
117-
try:
118-
return bool(
119-
magic.from_file(os.path.join(REPO_COPY, file), mime=True)
120-
== "text/x-shellscript"
121-
)
122-
except IsADirectoryError:
123-
# Process submodules w/o errors
124-
return False
117+
# try:
118+
# return bool(
119+
# magic.from_file(os.path.join(REPO_COPY, file), mime=True)
120+
# == "text/x-shellscript"
121+
# )
122+
# except IsADirectoryError:
123+
# # Process submodules w/o errors
124+
# return False
125+
return file.endswith(".sh")
125126

126127

127128
def main():

0 commit comments

Comments
 (0)