Skip to content

feat(cmd-version): enable version stamp of vars with double-equals operand in version_variables #1244

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

Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,8 @@ The regular expression generated from the ``version_variables`` definition will:

2. The variable name defined by ``variable`` and the version must be separated by
an operand symbol (``=``, ``:``, ``:=``, or ``@``). Whitespace is optional around
the symbol.
the symbol. As of $NEW_VERSION, a double-equals (``==``) operator is also supported
as a valid operand symbol.

3. The value of the variable must match a `SemVer`_ regular expression and can be
enclosed by single (``'``) or double (``"``) quotation marks but they must match. However,
Expand Down Expand Up @@ -1400,6 +1401,9 @@ will be matched and replaced by the new version:
# Custom Tag Format with tag_format set (monorepos)
__release__ = "module-v1.2.3"

# requirements.txt
my-package == 1.2.3

.. important::
The Regular Expression expects a version value to exist in the file to be replaced.
It cannot be an empty string or a non-semver compliant string. If this is the very
Expand Down
4 changes: 2 additions & 2 deletions src/semantic_release/version/declarations/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ def from_string_definition(
# Supports optional matching quotations around variable name
# Negative lookbehind to ensure we don't match part of a variable name
f"""(?x)(?P<quote1>['"])?(?<![\\w.-]){regex_escape(variable)}(?P=quote1)?""",
# Supports walrus, equals sign, colon, or @ as assignment operator
# Supports walrus, equals sign, double-equals, colon, or @ as assignment operator
# ignoring whitespace separation
r"\s*(:=|[:=@])\s*",
r"\s*(:=|==|[:=@])\s*",
# Supports optional matching quotations around a version pattern (tag or raw format)
f"""(?P<quote2>['"])?{value_replace_pattern_str}(?P=quote2)?""",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ def test_pattern_declaration_is_version_replacer():
"""if version := '1.0.0': """,
f"""if version := '{next_version}': """,
),
(
"Explicit number format for requirements.txt file with double equals",
f"{test_file}:my-package:{VersionStampType.NUMBER_FORMAT.value}",
# irrelevant for this case
lazy_fixture(default_tag_format_str.__name__),
# Uses double equals separator
"""my-package == 1.0.0""",
f"""my-package == {next_version}""",
),
(
"Using default number format for multi-line & quoted json",
f"{test_file}:version:{VersionStampType.NUMBER_FORMAT.value}",
Expand Down
Loading