Skip to content

Commit dedb3b7

Browse files
codejedi365relekang
authored andcommitted
feat(version-config): add option to disable 0.x.x versions
1 parent a040aa4 commit dedb3b7

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

semantic_release/cli/commands/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ def version( # noqa: C901
332332
commit_parser=parser,
333333
prerelease=prerelease,
334334
major_on_zero=major_on_zero,
335+
allow_zero_version=runtime.allow_zero_version,
335336
)
336337

337338
if build_metadata:

semantic_release/cli/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class RawConfig(BaseModel):
145145
commit_parser_options: Dict[str, Any] = {}
146146
logging_use_named_masks: bool = False
147147
major_on_zero: bool = True
148+
allow_zero_version: bool = True
148149
remote: RemoteConfig = RemoteConfig()
149150
tag_format: str = "v{version}"
150151
publish: PublishConfig = PublishConfig()
@@ -229,6 +230,7 @@ class RuntimeContext:
229230
commit_parser: CommitParser[ParseResult, ParserOptions]
230231
version_translator: VersionTranslator
231232
major_on_zero: bool
233+
allow_zero_version: bool
232234
prerelease: bool
233235
assets: List[str]
234236
commit_author: Actor
@@ -414,6 +416,7 @@ def from_raw_config(
414416
commit_parser=commit_parser,
415417
version_translator=version_translator,
416418
major_on_zero=raw.major_on_zero,
419+
allow_zero_version=raw.allow_zero_version,
417420
build_command=raw.build_command,
418421
version_declarations=tuple(version_declarations),
419422
hvcs_client=hvcs_client,

semantic_release/version/algorithm.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def _increment_version(
143143
prerelease: bool,
144144
prerelease_token: str,
145145
major_on_zero: bool,
146+
allow_zero_version: bool,
146147
) -> Version:
147148
"""
148149
Using the given versions, along with a given `level_bump`, increment to
@@ -158,19 +159,29 @@ def _increment_version(
158159
`latest_full_version_in_history`, correspondingly, is the latest full release which
159160
is in this branch's history.
160161
"""
162+
local_vars = list(locals().items())
161163
log.debug(
162-
"_increment_version: %s", ", ".join(f"{k} = {v}" for k, v in locals().items())
164+
"_increment_version: %s", ", ".join(f"{k} = {v}" for k, v in local_vars)
163165
)
164-
if not major_on_zero and latest_version.major == 0:
165-
# if we are a 0.x.y release and have set `major_on_zero`,
166-
# breaking changes should increment the minor digit
167-
# Correspondingly, we reduce the level that we increment the
168-
# version by.
169-
log.debug(
170-
"reducing version increment due to 0. version and major_on_zero=False"
171-
)
166+
if latest_version.major == 0:
167+
if not allow_zero_version:
168+
# Set up default version to be 1.0.0 if currently 0.x.x which means a commented
169+
# breaking change is not required to bump to 1.0.0
170+
log.debug(
171+
"Bumping major version as 0.x.x versions are disabled because of allow_zero_version=False"
172+
)
173+
level_bump = LevelBump.MAJOR
174+
175+
elif not major_on_zero:
176+
# if we are a 0.x.y release and have set `major_on_zero`,
177+
# breaking changes should increment the minor digit
178+
# Correspondingly, we reduce the level that we increment the
179+
# version by.
180+
log.debug(
181+
"reducing version increment due to 0. version and major_on_zero=False"
182+
)
172183

173-
level_bump = min(level_bump, LevelBump.MINOR)
184+
level_bump = min(level_bump, LevelBump.MINOR)
174185

175186
if prerelease:
176187
log.debug("prerelease=true")
@@ -261,6 +272,7 @@ def next_version(
261272
commit_parser: CommitParser[ParseResult, ParserOptions],
262273
prerelease: bool = False,
263274
major_on_zero: bool = True,
275+
allow_zero_version: bool = True,
264276
) -> Version:
265277
"""
266278
Evaluate the history within `repo`, and based on the tags and commits in the repo
@@ -398,8 +410,9 @@ def next_version(
398410
level_bump = max(parsed_levels, default=LevelBump.NO_RELEASE)
399411
log.info("The type of the next release release is: %s", level_bump)
400412
if level_bump is LevelBump.NO_RELEASE:
401-
log.info("No release will be made")
402-
return latest_version
413+
if latest_version.major != 0 or allow_zero_version:
414+
log.info("No release will be made")
415+
return latest_version
403416

404417
return _increment_version(
405418
latest_version=latest_version,
@@ -418,4 +431,5 @@ def next_version(
418431
prerelease=prerelease,
419432
prerelease_token=translator.prerelease_token,
420433
major_on_zero=major_on_zero,
434+
allow_zero_version=allow_zero_version,
421435
)

0 commit comments

Comments
 (0)