Skip to content

Commit adefa55

Browse files
committed
Update CI files
1 parent eaed8c8 commit adefa55

File tree

3 files changed

+74
-64
lines changed

3 files changed

+74
-64
lines changed

.ci/scripts/validate_commit_message.py

100755100644
Lines changed: 68 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,31 @@
1-
# WARNING: DO NOT EDIT!
2-
#
3-
# This file was generated by plugin_template, and is managed by it. Please use
4-
# './plugin-template --github pulp_python' to update this file.
5-
#
6-
# For more info visit https://github.com/pulp/plugin_template
1+
# This file is managed by the plugin template.
2+
# Do not edit.
73

84
import os
95
import re
106
import subprocess
117
import sys
128
import tomllib
9+
import yaml
1310
from pathlib import Path
1411

1512
from github import Github
1613

17-
with open("pyproject.toml", "rb") as fp:
18-
PYPROJECT_TOML = tomllib.load(fp)
19-
KEYWORDS = ["fixes", "closes"]
20-
BLOCKING_REGEX = [
21-
r"^DRAFT",
22-
r"^WIP",
23-
r"^NOMERGE",
24-
r"^DO\s*NOT\s*MERGE",
25-
r"^EXPERIMENT",
26-
r"^FIXUP",
27-
r"^fixup!", # This is created by 'git commit --fixup'
28-
r"Apply suggestions from code review", # This usually comes from GitHub
29-
]
30-
try:
31-
CHANGELOG_EXTS = [
32-
f".{item['directory']}" for item in PYPROJECT_TOML["tool"]["towncrier"]["type"]
33-
]
34-
except KeyError:
35-
CHANGELOG_EXTS = [".feature", ".bugfix", ".doc", ".removal", ".misc"]
36-
NOISSUE_MARKER = "[noissue]"
37-
38-
sha = sys.argv[1]
39-
message = subprocess.check_output(["git", "log", "--format=%B", "-n 1", sha]).decode("utf-8")
40-
41-
if NOISSUE_MARKER in message:
42-
sys.exit(f"Do not add '{NOISSUE_MARKER}' in the commit message.")
43-
44-
blocking_matches = [m for m in (re.match(pattern, message) for pattern in BLOCKING_REGEX) if m]
45-
if blocking_matches:
46-
print("Found these phrases in the commit message:")
47-
for m in blocking_matches:
48-
print(" - " + m.group(0))
49-
sys.exit("This PR is not ready for consumption.")
5014

51-
g = Github(os.environ.get("GITHUB_TOKEN"))
52-
repo = g.get_repo("pulp/pulp_python")
53-
54-
55-
def check_status(issue):
15+
def check_status(issue, repo, cherry_pick):
5616
gi = repo.get_issue(int(issue))
5717
if gi.pull_request:
5818
sys.exit(f"Error: issue #{issue} is a pull request.")
59-
if gi.closed_at:
19+
if gi.closed_at and not cherry_pick:
20+
print("Make sure to use 'git cherry-pick -x' when backporting a change.")
21+
print(
22+
"If a backport of a change requires a significant amount of rewriting, "
23+
"consider creating a new issue."
24+
)
6025
sys.exit(f"Error: issue #{issue} is closed.")
6126

6227

63-
def check_changelog(issue):
28+
def check_changelog(issue, CHANGELOG_EXTS):
6429
matches = list(Path("CHANGES").rglob(f"{issue}.*"))
6530

6631
if len(matches) < 1:
@@ -70,18 +35,63 @@ def check_changelog(issue):
7035
sys.exit(f"Invalid extension for changelog entry '{match}'.")
7136

7237

73-
print("Checking commit message for {sha}.".format(sha=sha[0:7]))
38+
def main() -> None:
39+
TEMPLATE_CONFIG = yaml.safe_load(Path("template_config.yml").read_text())
40+
GITHUB_ORG = TEMPLATE_CONFIG["github_org"]
41+
PLUGIN_NAME = TEMPLATE_CONFIG["plugin_name"]
42+
43+
with Path("pyproject.toml").open("rb") as _fp:
44+
PYPROJECT_TOML = tomllib.load(_fp)
45+
KEYWORDS = ["fixes", "closes"]
46+
BLOCKING_REGEX = [
47+
r"^DRAFT",
48+
r"^WIP",
49+
r"^NOMERGE",
50+
r"^DO\s*NOT\s*MERGE",
51+
r"^EXPERIMENT",
52+
r"^FIXUP",
53+
r"^fixup!", # This is created by 'git commit --fixup'
54+
r"Apply suggestions from code review", # This usually comes from GitHub
55+
]
56+
try:
57+
CHANGELOG_EXTS = [
58+
f".{item['directory']}" for item in PYPROJECT_TOML["tool"]["towncrier"]["type"]
59+
]
60+
except KeyError:
61+
CHANGELOG_EXTS = [".feature", ".bugfix", ".doc", ".removal", ".misc"]
62+
NOISSUE_MARKER = "[noissue]"
63+
64+
sha = sys.argv[1]
65+
message = subprocess.check_output(["git", "log", "--format=%B", "-n 1", sha]).decode("utf-8")
66+
67+
if NOISSUE_MARKER in message:
68+
sys.exit(f"Do not add '{NOISSUE_MARKER}' in the commit message.")
69+
70+
blocking_matches = [m for m in (re.match(pattern, message) for pattern in BLOCKING_REGEX) if m]
71+
if blocking_matches:
72+
print("Found these phrases in the commit message:")
73+
for m in blocking_matches:
74+
print(" - " + m.group(0))
75+
sys.exit("This PR is not ready for consumption.")
76+
77+
g = Github(os.environ.get("GITHUB_TOKEN"))
78+
repo = g.get_repo(f"{GITHUB_ORG}/{PLUGIN_NAME}")
79+
80+
print("Checking commit message for {sha}.".format(sha=sha[0:7]))
81+
82+
# validate the issue attached to the commit
83+
issue_regex = r"(?:{keywords})[\s:]+#(\d+)".format(keywords="|".join(KEYWORDS))
84+
issues = re.findall(issue_regex, message, re.IGNORECASE)
85+
cherry_pick_regex = r"^\s*\(cherry picked from commit [0-9a-f]*\)\s*$"
86+
cherry_pick = re.search(cherry_pick_regex, message, re.MULTILINE)
87+
88+
if issues:
89+
for issue in issues:
90+
check_status(issue, repo, cherry_pick)
91+
check_changelog(issue, CHANGELOG_EXTS)
7492

75-
# validate the issue attached to the commit
76-
issue_regex = r"(?:{keywords})[\s:]+#(\d+)".format(keywords=("|").join(KEYWORDS))
77-
issues = re.findall(issue_regex, message, re.IGNORECASE)
78-
cherry_pick_regex = r"^\s*\(cherry picked from commit [0-9a-f]*\)\s*$"
79-
cherry_pick = re.search(cherry_pick_regex, message, re.MULTILINE)
93+
print("Commit message for {sha} passed.".format(sha=sha[0:7]))
8094

81-
if issues:
82-
for issue in issues:
83-
if not cherry_pick:
84-
check_status(issue)
85-
check_changelog(issue)
8695

87-
print("Commit message for {sha} passed.".format(sha=sha[0:7]))
96+
if __name__ == "__main__":
97+
main()

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: "Install python dependencies"
3232
run: |
3333
echo ::group::PYDEPS
34-
pip install requests pygithub
34+
pip install requests pygithub pyyaml
3535
echo ::endgroup::
3636
- name: "Check commit message"
3737
if: github.event_name == 'pull_request'

.github/workflows/scripts/script.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ echo "Checking for uncommitted migrations..."
119119
cmd_user_prefix bash -c "django-admin makemigrations python --check --dry-run"
120120

121121
# Run unit tests.
122-
cmd_user_prefix bash -c "PULP_DATABASES__default__USER=postgres pytest -v -r sx --color=yes --suppress-no-test-exit-code -p no:pulpcore --pyargs pulp_python.tests.unit"
122+
cmd_user_prefix bash -c "PULP_DATABASES__default__USER=postgres pytest -v -r sx --color=yes --suppress-no-test-exit-code -p no:pulpcore --durations=20 --pyargs pulp_python.tests.unit"
123123
# Run functional tests
124124
if [[ "$TEST" == "performance" ]]; then
125125
if [[ -z ${PERFORMANCE_TEST+x} ]]; then
@@ -135,11 +135,11 @@ if [ -f "$FUNC_TEST_SCRIPT" ]; then
135135
else
136136
if [[ "$GITHUB_WORKFLOW" =~ "Nightly" ]]
137137
then
138-
cmd_user_prefix bash -c "pytest -v --timeout=300 -r sx --color=yes --suppress-no-test-exit-code --pyargs pulp_python.tests.functional -m parallel -n 8 --nightly"
139-
cmd_user_prefix bash -c "pytest -v --timeout=300 -r sx --color=yes --suppress-no-test-exit-code --pyargs pulp_python.tests.functional -m 'not parallel' --nightly"
138+
cmd_user_prefix bash -c "pytest -v --timeout=300 -r sx --color=yes --suppress-no-test-exit-code --durations=20 --pyargs pulp_python.tests.functional -m parallel -n 8 --nightly"
139+
cmd_user_prefix bash -c "pytest -v --timeout=300 -r sx --color=yes --suppress-no-test-exit-code --durations=20 --pyargs pulp_python.tests.functional -m 'not parallel' --nightly"
140140
else
141-
cmd_user_prefix bash -c "pytest -v --timeout=300 -r sx --color=yes --suppress-no-test-exit-code --pyargs pulp_python.tests.functional -m parallel -n 8"
142-
cmd_user_prefix bash -c "pytest -v --timeout=300 -r sx --color=yes --suppress-no-test-exit-code --pyargs pulp_python.tests.functional -m 'not parallel'"
141+
cmd_user_prefix bash -c "pytest -v --timeout=300 -r sx --color=yes --suppress-no-test-exit-code --durations=20 --pyargs pulp_python.tests.functional -m parallel -n 8"
142+
cmd_user_prefix bash -c "pytest -v --timeout=300 -r sx --color=yes --suppress-no-test-exit-code --durations=20 --pyargs pulp_python.tests.functional -m 'not parallel'"
143143
fi
144144
fi
145145
pushd ../pulp-cli

0 commit comments

Comments
 (0)