Skip to content
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/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,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. As of v10.0.0, a double-equals (``==``) operator is also supported
as a valid operand symbol.
as a valid operand symbol. As of $NEW_RELEASE_TAG, PSR can omit all operands as long
as there is at least one whitespace character between the variable name and the version.

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 @@ -1410,6 +1411,9 @@ will be matched and replaced by the new version:
# requirements.txt
my-package == 1.2.3

# C-Macro style (no operand only whitespace required)
#define VERSION "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 @@ -228,8 +228,8 @@ def from_string_definition(
# 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, double-equals, colon, or @ as assignment operator
# ignoring whitespace separation
r"\s*(:=|==|[:=@])\s*",
# ignoring whitespace separation. Also allows a space as the separator for c-macro style definitions.
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 @@ -215,6 +215,59 @@ def test_pattern_declaration_is_version_replacer():
"""
),
),
(
"Using default number format for c-macro style definition (see #1348)",
f"{test_file}:APP_VERSION:{VersionStampType.NUMBER_FORMAT.value}",
# irrelevant for this case
lazy_fixture(default_tag_format_str.__name__),
# Uses colon separator with double quotes
dedent(
"""\
#ifndef VERSION_H
#define VERSION_H

#define APP_VERSION "0.0.0"

#endif // VERSION_H
"""
),
dedent(
f"""\
#ifndef VERSION_H
#define VERSION_H

#define APP_VERSION "{next_version}"

#endif // VERSION_H
"""
),
),
(
"Using default tag format for c-macro style definition (see #1348)",
f"{test_file}:APP_VERSION:{VersionStampType.TAG_FORMAT.value}",
lazy_fixture(default_tag_format_str.__name__),
# Uses colon separator with double quotes
dedent(
"""\
#ifndef VERSION_H
#define VERSION_H

#define APP_VERSION "v0.0.0"

#endif // VERSION_H
"""
),
dedent(
f"""\
#ifndef VERSION_H
#define VERSION_H

#define APP_VERSION "v{next_version}"

#endif // VERSION_H
"""
),
),
]
],
)
Expand Down
Loading