-
Notifications
You must be signed in to change notification settings - Fork 256
Failure to determine correct level bump with custom parser in 9.17.0 #1162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@pwrmiller, thanks for pointing me to a specific place in the code that you think there is a change, however, this is not enough information for me to understand what is happening and how to replicate. Please fill in your configuration in the boxes above and provide your commit messages in a git tree so that I can replicate the problem because all of our extensive test cases did not catch/replicate your environment. Obviously, it was not intended to be a breaking change otherwise I would of bumped it otherwise but people make mistakes. |
@codejedi365 I've provided additional context on my configuration. My apologies for not providing sufficient context for your review. |
@pwrmiller, I did find a bug in the code. Basically I was attempting to maintain the legacy return value of the I've came up with an initial fix to apply more stricter type checking from return values of parsers, followed with a better type cast. |
Separately, I wanted to offer a few suggestions to your custom parser implementation.
+ from semantic_release.commit_parser.angular import AngularParserOptions
+ from semantic_release.helpers import force_str
+ class MyCommitParserOptions(AngularParserOptions):
- class MyCommitParserOptions(ParserOptions):
- def __init__(self, **_: Any):
- # Load whole configuration
- super().__init__(**_)
- pyproject = toml.load("pyproject.toml")
-
- # Extract commit parsers options
- commit_parser_options = pyproject["tool"]["semantic_release"][
- "commit_parser_options"
- ]
-
- # Load options as instance variables
- self.allowed_tags = commit_parser_options["allowed_tags"]
- self.minor_tags = commit_parser_options["minor_tags"]
- self.patch_tags = commit_parser_options["patch_tags"]
- self.default_bump_level = LevelBump(commit_parser_options["default_bump_level"])
class MyCommitParser(CommitParser[ParseResult, MyCommitParserOptions]):
+
+ parser_options = ADOCommitParserOptions # removed in v10
+
- def __init__(self, **kwargs):
- super().__init__(**kwargs)
- self.options = MyCommitParserOptions()
+ def __init__(self, options: MyCommitParserOptions | None = None) -> None:
+ super().__init__(options)
+
+ @staticmethod
+ def get_default_options() -> MyCommitParserOptions:
+ return MyCommitParserOptions()
def parse(self, commit: git.objects.commit.Commit) -> Optional[ParseResult]:
- sentences = commit.message.strip().split("\n\n")
+ sentences = force_str(commit.message).strip().split("\n\n")
unique_sentences = list(dict.fromkeys(sentences))
message = "\n\n".join(unique_sentences)
allowed_tags_regex_part = "|".join(map(re.escape, self.options.allowed_tags))
match = re.match(
rf"^.*({allowed_tags_regex_part})(?:\(([^)]+)\))?: (.+)(?:\n|$)([\s\S]*)",
message,
)
if match:
type_ = match.group(1)
scope = match.group(2) or ""
description = match.group(3)
rest_of_message = match.group(4)
descriptions = [description]
breaking_descriptions = []
for line in rest_of_message.split("\n"):
line = line.strip()
if line.startswith("BREAKING CHANGE: "):
breaking_descriptions.append(line.replace("BREAKING CHANGE: ", ""))
elif line != "":
descriptions.append(line)
bump = self.options.default_bump_level
if breaking_descriptions:
bump = LevelBump.MAJOR
elif type_ in self.options.minor_tags:
bump = LevelBump.MINOR
elif type_ in self.options.patch_tags:
bump = LevelBump.PATCH
return ParsedCommit(
bump=bump,
type=type_,
scope=scope,
descriptions=descriptions,
breaking_descriptions=breaking_descriptions,
commit=commit,
)
else:
return ParseError(commit=commit, error="Could not parse commit message") |
@codejedi365 thank you so much for the detailed review and recommendations on my commit parser. I'll take a look on my end into avoiding the custom I'll be revisiting that |
I would check out
If it is a more verbose description, then you may want to look at issue #1132 which discusses how to customize the changelog output. We now support parsing squash commits if that is what you were describing as a more verbose description. The default changelog currently prints out the entire commit body but in v10 it will only display the subject/summary line. |
resolves the error where the casting to a list was incorrectly implemented causing single results back from custom parsers (legacy return value) to be mis-interpreted which meant no parse level would be determined. Resolves: python-semantic-release#1162
resolves the error where the casting to a list was incorrectly implemented causing single results back from custom parsers (legacy return value) to be mis-interpreted which meant no parse level would be determined. Resolves: python-semantic-release#1162
resolves the error where the casting to a list was incorrectly implemented causing single results back from custom parsers (legacy return value) to be mis-interpreted which meant no parse level would be determined. Resolves: python-semantic-release#1162
resolves the error where the casting to a list was incorrectly implemented causing single results back from custom parsers (legacy return value) to be mis-interpreted which meant no parse level would be determined. Resolves: python-semantic-release#1162
🎉 This issue has been resolved in Version 9.18.0 🎉You can find more information about this release on the GitHub Releases page. |
Bug Report
Description
Different / breaking behavior between 9.16.1 and 9.17.0 in
algorithm.py
Step 5. Parse commits to determine the bump level that should be applied.Expected behavior
I would have expected the same behavior between 9.16.1 and 9.17.0 as minor version changes should not exhibit breaking behavior. This seems to be a regression.
Actual behavior
Specifically, in 9.16.1, parsed_levels will contain the results of the parsed levels in the commits_since_last_release, but 9.17.0 will not. It is not entirely clear to me where this is failing due to the complexity of the mapped/filtered set.
Environment
poetry show python-semantic-release
git log --oneline --decorate --graph --all -n 50
Configuration
Semantic Release Configuration
I use a custom commit parser to support working with Azure Devops.Build System Configuration
GitHub Actions Job Definition
Execution Log
poetry run semantic-release -vv version --no-vcs-release
9.17.1
9.16.1
Additional context
Debugging suggests that perhaps the result of the filter on isinstance for ParsedCommit might be failing, since at this point the parsed_result is already a LevelBump. Though this is not entirely clear due to the complexity of step 5.
The commit parser returns the correct ParsedCommit(s) in both versions of PSR, however, the filtered list in parsed_levels differs between versions.
The text was updated successfully, but these errors were encountered: