Skip to content

How can I update a C header file with the version? #1348

@garrethcain

Description

@garrethcain

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 = true

Additional context

Added above already.

Thanks for the help in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmedPrevent from becoming stalefeatureA new feature or a feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions