Skip to content

Commit 8784b9a

Browse files
authored
fix(cmd-version): fix handling of multiple prerelease token variants & git flow merges (python-semantic-release#1120)
* refactor: define a custom logging level of silly * fix(version): remove some excessive log msgs from debug to silly level * test(fixtures): refactor builder functions for version file updates * test(fixtures): adjust build command to handle versions w/ build metadata * test(fixtures): fix gitflow repo that included an invalid build metadata string * test(fixtures): fix major_on_zero setting in repos to match expected behavior * test(cmd-version): add test cases to run an example repo rebuild w/ psr * test(cmd-version): enable git flow repo rebuild w/ psr test cases * fix(cmd-version): handle multiple prerelease token variants properly In the case where there are alpha and beta releases, we must only consider the previous beta release even if alpha releases exist due to merging into beta release only branches which have no changes considerable changes from alphas but must be marked otherwise. Resolves: python-semantic-release#789 * fix(cmd-version): fix version determination algorithm to capture commits across merged branches * perf(cmd-version): refactor version determination algorithm for accuracy & speed * test(algorithm): refactor test to match new function signature * style(algorithm): drop unused functions & imports * test(algorithm): adapt test case for new DFS commit traversal implementation
1 parent 6dfbbb0 commit 8784b9a

24 files changed

+2054
-507
lines changed

src/semantic_release/cli/commands/main.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from semantic_release.cli.config import GlobalCommandLineOptions
1616
from semantic_release.cli.const import DEFAULT_CONFIG_FILE
1717
from semantic_release.cli.util import rprint
18+
from semantic_release.enums import SemanticReleaseLogLevels
1819

1920
# if TYPE_CHECKING:
2021
# pass
@@ -108,7 +109,15 @@ def main(
108109
"""
109110
console = Console(stderr=True)
110111

111-
log_level = [logging.WARNING, logging.INFO, logging.DEBUG][verbosity]
112+
log_levels = [
113+
SemanticReleaseLogLevels.WARNING,
114+
SemanticReleaseLogLevels.INFO,
115+
SemanticReleaseLogLevels.DEBUG,
116+
SemanticReleaseLogLevels.SILLY,
117+
]
118+
119+
log_level = log_levels[verbosity]
120+
112121
logging.basicConfig(
113122
level=log_level,
114123
format=FORMAT,
@@ -123,7 +132,7 @@ def main(
123132
logger = logging.getLogger(__name__)
124133
logger.debug("logging level set to: %s", logging.getLevelName(log_level))
125134

126-
if log_level == logging.DEBUG:
135+
if log_level <= logging.DEBUG:
127136
globals.debug = True
128137

129138
if noop:

src/semantic_release/enums.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import logging
34
from enum import IntEnum, unique
45

56

@@ -37,3 +38,32 @@ def from_string(cls, val: str) -> LevelBump:
3738
>>> LevelBump.from_string("minor") == LevelBump.MINOR
3839
"""
3940
return cls[val.upper().replace("-", "_")]
41+
42+
43+
class SemanticReleaseLogLevels(IntEnum):
44+
"""IntEnum representing the log levels used by semantic-release."""
45+
46+
FATAL = logging.FATAL
47+
CRITICAL = logging.CRITICAL
48+
ERROR = logging.ERROR
49+
WARNING = logging.WARNING
50+
INFO = logging.INFO
51+
DEBUG = logging.DEBUG
52+
SILLY = 5
53+
54+
def __str__(self) -> str:
55+
"""
56+
Return the level name rather than 'SemanticReleaseLogLevels.<level>'
57+
E.g.
58+
>>> str(SemanticReleaseLogLevels.DEBUG)
59+
'DEBUG'
60+
>>> str(SemanticReleaseLogLevels.CRITICAL)
61+
'CRITICAL'
62+
"""
63+
return self.name.upper()
64+
65+
66+
logging.addLevelName(
67+
SemanticReleaseLogLevels.SILLY,
68+
str(SemanticReleaseLogLevels.SILLY),
69+
)

0 commit comments

Comments
 (0)