Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions scripts/semantic_release_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ def _parse_conventional_commit(self, commit_message):
"""
try:
# Normalize commit message
message = commit_message.lower().strip()
message = commit_message.strip()
lower_message = message.lower()

# Check for BREAKING CHANGE
if "breaking change" in message:
# Check for BREAKING CHANGE in footer/body
if "breaking change" in lower_message or "breaking-change" in lower_message:
return "major"

# Parse commit type
Expand All @@ -139,20 +140,27 @@ def _parse_conventional_commit(self, commit_message):
<type>(<optional scope>): <description>
<type>[optional scope]: <description>
"""
match = re.match(r"^(\w+)(?:\(|\[)?[^\)\]]*(?:\)|\])?:", message)
# optional breaking change marker (!), and flexible spacing.
match = re.match(r"^(\w+)(?:\(|\[)?[^\)\]! \t:]*(?:\)|\])?(!)?\s?:", message)
if not match:
# If the commit message does not match the conventional commit format
# and is not empty, treat it as a "chore:" and return "patch".
if message:
return "patch"
return None

commit_type = match.group(1)
commit_type = match.group(1).lower()
is_breaking = bool(match.group(2))

if is_breaking:
return "major"

# Mapping of commit types to version bump
type_bump_map = {
"feat": "minor",
"feature": "minor",
"fix": "patch",
"bugfix": "patch",
"chore": "patch",
"docs": "patch",
"refactor": "patch",
Expand Down Expand Up @@ -239,7 +247,7 @@ def get_package_commits(self, package_path):
cmd = [
"git",
"log",
f"{self.prev_commit}^..{self.current_commit}",
f"{self.prev_commit}..{self.current_commit}",
"--pretty=format:%s",
"--",
path,
Expand Down Expand Up @@ -287,6 +295,7 @@ def determine_package_bump(self, package_path):

for commit in package_commits:
commit_bump = self._parse_conventional_commit(commit)
print(f"DEBUG: {package_path} commit: '{commit}' -> bump: {commit_bump}")
if commit_bump and bump_priority.get(
commit_bump, 0
) > bump_priority.get(highest_bump, 0):
Expand Down