You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bump-my-version uses [template strings](https://docs.python.org/3/library/string.html#format-string-syntax) to search the configured files for the old or current version and replace the text with the new version.
4
+
5
+
You can configure the search or replace templates globally and within each `tool.bumpversion.files` entry in your configuration.
6
+
7
+
The default search template is `{current_version}` to find the version string within the file and replace it with `{new_version}`.
8
+
9
+
The search and replace templates can be multiple lines, like so:
10
+
11
+
```toml
12
+
[tool.bumpversion]
13
+
current_version = "1.2.3"
14
+
15
+
[[tool.bumpversion.files]]
16
+
filename = "config.ini"
17
+
search = "[myproject]\nversion={current_version}"
18
+
replace = "[myproject]\nversion={new_version}"
19
+
```
20
+
21
+
Alternatively, using [TOML's multiline strings](https://toml.io/en/v1.0.0#string):
22
+
23
+
```toml
24
+
[tool.bumpversion]
25
+
current_version = "1.2.3"
26
+
27
+
[[tool.bumpversion.files]]
28
+
filename = "config.ini"
29
+
search = """
30
+
[myproject]
31
+
version={current_version}"""
32
+
33
+
replace = """
34
+
[myproject]
35
+
version={new_version}"""
36
+
```
37
+
38
+
## Avoiding incorrect replacements
39
+
40
+
In files that have multiple version strings, bump-my-version may find the wrong string and replace it. Given this `requirements.txt` for `MyProject`:
4
41
5
42
```text
6
43
Django>=1.5.6,<1.6
7
44
MyProject==1.5.6
8
45
```
9
46
10
-
using this `.bumpversion.toml` will ensure only the line containing `MyProject` will be changed:
47
+
The default search and replace templates will replace the wrong text. Instead of changing `MyProject`'s version from `1.5.6` to `1.6.0`, it changes `Django`'s version:
48
+
49
+
```text
50
+
Django>=1.6.0,<1.6
51
+
MyProject==1.5.6
52
+
```
53
+
54
+
Providing search and replace templates for the `requirements.txt` file will avoid this.
55
+
56
+
This `.bumpversion.toml` will ensure only the line containing `MyProject` will be changed:
You can use file configurations to replace the version in multiple files, even if each file has the version formatted differently.
86
+
87
+
In a module-aware Go project, when you create a major version of your module beyond `v1`, your module name must include the major version number (e.g., `github.com/myorg/myproject/v2`). However, you also have the full version in a YAML file named `release-channels.yaml`.
88
+
89
+
`go.mod` file:
38
90
39
-
## Using bumpversion to maintain a go mod file within a Go project
91
+
```go
92
+
module github.com/myorg/myproject/v2
93
+
94
+
go1.12
95
+
96
+
require (
97
+
...
98
+
)
99
+
```
40
100
41
-
In a module-aware Go project, when you create a major version of your module beyond v1, your module name will need to include the major version number (e.g., `github.com/myorg/myproject/v2`).
101
+
`release-channels.yaml` file:
102
+
103
+
```yaml
104
+
stable: "v2.21.4"
105
+
```
42
106
43
107
You can use bump-my-version to maintain the major version number within the `go.mod` file by using the `parse` and `serialize` options, as in this example:
While all the version bumps are `minor` or `patch`, the `go.mod` file doesn't change, while the `release-channels.yaml` file will. As soon as you do a `major` version bump, the `go.mod` file now contains this module directive:
To make several replacements in the same file, you must configure multiple `[[tool.bumpversion.files]]` sections for the same file with different configuration options.
71
135
72
-
Then run this command to create version 3.0.0 of your project:
136
+
In this example, the changelog is generated before the version bump. It uses `Unreleased` as the heading and includes a link to GitHub to compare this version (`HEAD`) with the previous version.
73
137
74
-
```console
75
-
bump-my-version --new-version 3.0.0 major
76
-
```
138
+
To change `Unreleased ` to the current version, we have an entry with `search` set to `Unreleased`. The default `replace` value is `{new_version}`, so changing it is unnecessary.
77
139
78
-
Your `go.mod` file now contains this module directive:
140
+
To change the link, another entry has its `search` set to `{current_version}...HEAD` and the `replace` set to `{current_version}...{new_version}`.
0 commit comments