Skip to content

Versioning unsupported files

Want to bump the version of a file that isn’t natively supported? Request it as a feature so it can be added to Knope’s built-in support! In the meantime, you have a couple options:

Knope can update the version of any file using regex patterns:

[package]
versioned_files = [
{ path = "README.md", regex = "v(?<version>\\d+\\.\\d+\\.\\d+)" }
]

The regex pattern must include a named capture group (?<version>...) around the version number you want to replace. See the Text files with regex patterns section for more details.

You can write a script to manually bump that file with the version produced by BumpVersion or PrepareRelease using a Command step, like this:

[package]
versioned_files = [] # With no versioned_files, the version will be determined via Git tag
changelog = "CHANGELOG.md"
[[workflows]]
name = "release"
[[workflows.steps]]
type = "PrepareRelease"
[[workflows.steps]]
type = "Command"
command = "my-command-which-bumps-a-custom-file-with $version"

For more advanced cases, you can combine the regex feature with a Command step:

custom-steps.py
version = "1.2.3"
# ... do custom things with the version
knope.toml
[package]
versioned_files = [
{ path = "custom-steps.py", regex = 'version = \"(?<version>.*)\"' }
]
[[workflows]]
name = "release"
[[workflows.steps]]
# This updates the version in `custom-steps.py`
type = "PrepareRelease"
[[workflows.steps]]
type = "Command"
command = "python custom-steps.py"