Skip to content

Commit 5cbc10b

Browse files
committed
Update CI files
1 parent 1a00169 commit 5cbc10b

File tree

4 files changed

+48
-28
lines changed

4 files changed

+48
-28
lines changed

.ci/scripts/check_release.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@ def current_version(repo, commitish):
5050

5151
def check_pyproject_dependencies(repo, from_commit, to_commit):
5252
try:
53-
old_pyproject = tomllib.load(repo.show("{from_commit}:pyproject.toml"))
53+
new_pyproject = tomllib.loads(repo.git.show(f"{to_commit}:pyproject.toml"))
54+
try:
55+
new_dependencies = set(new_pyproject["project"]["dependencies"])
56+
except KeyError:
57+
# New branch does not declare dependencies in pyproject.toml.
58+
# Assume no release needed for this reason.
59+
return []
60+
old_pyproject = tomllib.loads(repo.git.show(f"{from_commit}:pyproject.toml"))
5461
old_dependencies = set(old_pyproject["project"]["dependencies"])
55-
new_pyproject = tomllib.load(repo.show("{to_commit}:pyproject.toml"))
56-
new_dependencies = set(new_pyproject["project"]["dependencies"])
5762
if old_dependencies != new_dependencies:
5863
return ["dependencies"]
5964
else:

.ci/scripts/validate_commit_message.py

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,78 @@
55
#
66
# For more info visit https://github.com/pulp/plugin_template
77

8+
import os
89
import re
10+
import subprocess
911
import sys
12+
import tomllib
1013
from pathlib import Path
11-
import subprocess
12-
import os
13-
import warnings
14+
1415
from github import Github
1516

16-
CHANGELOG_EXTS = [".feature", ".bugfix", ".doc", ".removal", ".misc", ".deprecation"]
17+
with open("pyproject.toml", "rb") as fp:
18+
PYPROJECT_TOML = tomllib.load(fp)
1719
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"Apply suggestions from code review",
28+
]
29+
try:
30+
CHANGELOG_EXTS = [
31+
f".{item['directory']}" for item in PYPROJECT_TOML["tool"]["towncrier"]["type"]
32+
]
33+
except KeyError:
34+
CHANGELOG_EXTS = [".feature", ".bugfix", ".doc", ".removal", ".misc"]
35+
NOISSUE_MARKER = "[noissue]"
1836

1937
sha = sys.argv[1]
2038
message = subprocess.check_output(["git", "log", "--format=%B", "-n 1", sha]).decode("utf-8")
2139

40+
if NOISSUE_MARKER in message:
41+
sys.exit(f"Do not add '{NOISSUE_MARKER}' in the commit message.")
42+
43+
if any((re.match(pattern, message, re.IGNORECASE) for pattern in BLOCKING_REGEX)):
44+
sys.exit("This PR is not ready for consumption.")
45+
2246
g = Github(os.environ.get("GITHUB_TOKEN"))
2347
repo = g.get_repo("pulp/pulpcore")
2448

2549

26-
def __check_status(issue):
50+
def check_status(issue):
2751
gi = repo.get_issue(int(issue))
2852
if gi.pull_request:
2953
sys.exit(f"Error: issue #{issue} is a pull request.")
30-
if gi.closed_at and "cherry picked from commit" not in message:
31-
warnings.warn(
32-
"When backporting, use the -x flag to append a line that says "
33-
"'(cherry picked from commit ...)' to the original commit message."
34-
)
54+
if gi.closed_at:
3555
sys.exit(f"Error: issue #{issue} is closed.")
3656

3757

38-
def __check_changelog(issue):
58+
def check_changelog(issue):
3959
matches = list(Path("CHANGES").rglob(f"{issue}.*"))
4060

4161
if len(matches) < 1:
4262
sys.exit(f"Could not find changelog entry in CHANGES/ for {issue}.")
4363
for match in matches:
4464
if match.suffix not in CHANGELOG_EXTS:
4565
sys.exit(f"Invalid extension for changelog entry '{match}'.")
46-
if match.suffix == ".feature" and "cherry picked from commit" in message:
47-
sys.exit(f"Can not backport '{match}' as it is a feature.")
4866

4967

5068
print("Checking commit message for {sha}.".format(sha=sha[0:7]))
5169

5270
# validate the issue attached to the commit
53-
regex = r"(?:{keywords})[\s:]+#(\d+)".format(keywords=("|").join(KEYWORDS))
54-
pattern = re.compile(regex, re.IGNORECASE)
55-
56-
issues = pattern.findall(message)
71+
issue_regex = r"(?:{keywords})[\s:]+#(\d+)".format(keywords=("|").join(KEYWORDS))
72+
issues = re.findall(issue_regex, message, re.IGNORECASE)
73+
cherry_pick_regex = r"^\s*\(cherry picked from commit [0-9a-f]*\)\s*$"
74+
cherry_pick = re.search(cherry_pick_regex, message, re.MULTILINE)
5775

5876
if issues:
59-
for issue in pattern.findall(message):
60-
__check_status(issue)
61-
__check_changelog(issue)
77+
for issue in issues:
78+
if not cherry_pick:
79+
check_status(issue)
80+
check_changelog(issue)
6281

6382
print("Commit message for {sha} passed.".format(sha=sha[0:7]))

.github/template_gitref

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2021.08.26-413-g9b1257e
1+
2021.08.26-415-g804d8f6

.github/workflows/scripts/check_commit.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,4 @@ set -euv
1515
for SHA in $(curl -H "Authorization: token $GITHUB_TOKEN" "$GITHUB_CONTEXT" | jq -r '.[].sha')
1616
do
1717
python3 .ci/scripts/validate_commit_message.py "$SHA"
18-
VALUE=$?
19-
if [ "$VALUE" -gt 0 ]; then
20-
exit $VALUE
21-
fi
2218
done

0 commit comments

Comments
 (0)