Repository navigation
Closed
Labels
confirmedPrevent from becoming stalePrevent from becoming stalefeatureA new feature or a feature requestA new feature or a feature request
Description
Question
I am trying to update a C header file with the version. I have managed to get the file to update using build_command but this doesn't seem to get pushed along with the Changelog when PSR runs.
I tried several different ways to configure the version variable, but it never updated the Header file, but does update the pyproject/py file okay.
Using the build_command does update the variable but it doesn't push header back along with the TAG so the next build step, that runs when a tag is pushed, is always out of date.
Here is my header file:
#ifndef VERSION_H
#define VERSION_H
#define APP_VERSION "0.0.0"
#endif // VERSION_H
This is my build_command:
VERSION=$(uvx python-semantic-release version --print)
echo '#define APP_VERSION "$VERSION"' > src/version.h
And this is my version_variable, I tried many different formats;
src/version.h:#define APP_VERSION
Configuration
[project]
version = "1.1.0-rc.8" <-- updates OK.
[tool.semantic_release]
assets = []
build_command_env = []
commit_message = "{version}\n\nAutomatically generated by python-semantic-release"
commit_parser = "conventional"
logging_use_named_masks = false
major_on_zero = true
allow_zero_version = false
no_git_verify = false
tag_format = "v{version}"
version_variable = ["src/version.h:#define APP_VERSION"]
version_toml = ["pyproject.toml:project.version"]
build_command = """
VERSION=$(uvx python-semantic-release version --print)
echo '#define APP_VERSION "$VERSION"' > src/version.h
git add src/version.h
"""
[tool.semantic_release.branches.master]
match = "(main|master)"
prerelease_token = "rc"
prerelease = false
[tool.semantic_release.branches.develop]
match = "develop"
prerelease = true
prerelease_token = "rc"
[tool.semantic_release.changelog]
exclude_commit_patterns = []
mode = "update"
insertion_flag = "<!-- version list -->"
template_dir = "templates"
[tool.semantic_release.changelog.default_templates]
changelog_file = "CHANGELOG.md"
output_format = "md"
mask_initial_release = true
[tool.semantic_release.changelog.environment]
block_start_string = "{%"
block_end_string = "%}"
variable_start_string = "{{"
variable_end_string = "}}"
comment_start_string = "{#"
comment_end_string = "#}"
trim_blocks = false
lstrip_blocks = false
newline_sequence = "\n"
keep_trailing_newline = false
extensions = []
autoescape = false
[tool.semantic_release.commit_author]
env = "GIT_COMMIT_AUTHOR"
default = "semantic-release <semantic-release>"
[tool.semantic_release.commit_parser_options]
minor_tags = ["feat"]
patch_tags = ["fix", "perf"]
other_allowed_tags = [
"build",
"chore",
"ci",
"docs",
"style",
"refactor",
"test",
]
allowed_tags = [
"feat",
"fix",
"perf",
"build",
"chore",
"ci",
"docs",
"style",
"refactor",
"test",
]
default_bump_level = 0
parse_squash_commits = true
ignore_merge_commits = true
[tool.semantic_release.remote]
name = "origin"
type = "gitlab"
ignore_token_for_push = false
insecure = false
[tool.semantic_release.publish]
dist_glob_patterns = ["dist/*"]
upload_to_vcs_release = trueAdditional context
Added above already.
Thanks for the help in advance.
Metadata
Metadata
Assignees
Labels
confirmedPrevent from becoming stalePrevent from becoming stalefeatureA new feature or a feature requestA new feature or a feature request
Activity
[-]How can I update a C header file with teh version?[/-][+]How can I update a C header file with the version?[/+]codejedi365 commentedon Nov 2, 2025
@garrethcain, after some testing, I realized that the current
version_variablessetting and corresponding regular expression that is created does not support the space separation variable definition that is found in a C macro. I will have to modify the PatternVersionDeclaration object to support a single space separation. Sorry for the inconvenience!garrethcain commentedon Nov 2, 2025
Thanks for the update and excellent support.
Looking forward to a fix in a future release. 👍
test(version-variables): add c-macro style version stamp unit test
feat(cmd-version): adds c-macro style version definition support to `…
docs(configuration): update `version_variables` examples with a c-mac…
feat(cmd-version): adds c-macro style version definition support to `…
codejedi365 commentedon Nov 10, 2025
🎉 This issue has been resolved in v10.5.0 🎉
You can find more information about this release on the GitHub Releases page.
If your issue persists, please reply here and we will re-open the issue. If you receive a new error, please open a new issue and reference this issue there.
garrethcain commentedon Nov 10, 2025
This seems to still be an issue;
Header file is as in the post above, the file is never modified but the pyproject.toml is updated as always.
codejedi365 commentedon Nov 10, 2025
@garrethcain, Oh forgot to tell you to remove "#define" and just use APP_VERSION.
And depending if you want the version as the associated tag then add
:tffor tag formatgarrethcain commentedon Nov 10, 2025
I tried that way too. After reading the PR that's how it looked it worked.
version_variable = ["src/version.h:APP_VERSION"]codejedi365 commentedon Nov 10, 2025
Oh your setting is wrong. It's
version_variableswith ans.garrethcain commentedon Nov 10, 2025
That's pretty funny. It was never going to work right from the beginning.
That fixed it. Thanks again!
codejedi365 commentedon Nov 10, 2025
Looking to refactor the configuration in a major release so that errors like that are not quietly suppressed but instead throw an error.