|
1 | 1 | # Version parts
|
2 | 2 |
|
3 |
| -A version string consists of one or more parts, e.g. the version `1.0.2` has three parts, separated by a dot (`.`) character. The names of these parts are defined in the named groups within the `parse` regular expression. The default configuration ( `(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)`) names them *major, minor,* and *patch.* |
| 3 | +- The version string is the rendering of some or all version parts. |
| 4 | +- While the version string may be rendered differently in various places, the value for all parts is maintained in bump-my-version's configuration. |
| 5 | +- The version parts are typically dependent on each other. Incrementing one part might change other elements. |
| 6 | +- You can compare two version strings (of the same project) and know which is more recent. |
4 | 7 |
|
5 |
| -By default all parts are considered numeric, that is their initial value is `0` and they are increased as integers. Also, the value `0` is considered to be |
6 |
| -optional if it's not needed for serialization, i.e. the version `1.4.0` is |
7 |
| -equal to `1.4` if `{major}.{minor}` is given as a `serialize` value. |
| 8 | +## Version configuration |
8 | 9 |
|
9 |
| -For advanced versioning schemes, non-numeric parts may be desirable (e.g. to |
10 |
| -identify [alpha or beta versions](http://en.wikipedia.org/wiki/Software_release_life_cycle#Stages_of_development) |
11 |
| -to indicate the stage of development, the flavor of the software package or |
12 |
| -a release name). To do so, you can use a `[bumpversion:part:…]` section |
13 |
| -containing the part's name (e.g. a part named `release_name` is configured in |
14 |
| -a section called `[bumpversion:part:release_name]`. |
| 10 | +A version configuration consists of the following: |
15 | 11 |
|
16 |
| -The following options are valid inside a part configuration: |
| 12 | +- A regular expression that will parse all the possible parts and name them |
| 13 | +- A list of one or more serialization formats |
17 | 14 |
|
| 15 | +A version string consists of one or more parts; e.g., version `1.0.2` has three parts, separated by a dot (`.`) character. |
18 | 16 |
|
| 17 | +The names of these parts are defined in the named groups within the `parse` regular expression. The default configuration calls them *major, minor,* and *patch.* |
19 | 18 |
|
| 19 | +The `serialize` configuration value is a list of default formats. You have the option for multiple serialization formats to omit *optional* values. For example, the following configuration: |
20 | 20 |
|
| 21 | +```toml |
| 22 | +serialize = [ |
| 23 | + "{major}.{minor}.{patch}", |
| 24 | + "{major}.{minor}", |
| 25 | +] |
| 26 | +``` |
21 | 27 |
|
22 |
| -Example: |
| 28 | +Bump-my-version will serialize using the first format if the `patch` value is not `0`. If the `patch` value *is* `0`, bump-my-version will use the second format. |
23 | 29 |
|
24 |
| -```ini |
25 |
| -[bumpversion:part:release_name] |
26 |
| -values = |
27 |
| -witty-warthog |
28 |
| -ridiculous-rat |
29 |
| -marvelous-mantis |
30 |
| -``` |
| 30 | +## Version part configuration |
31 | 31 |
|
32 |
| ---- |
| 32 | +A version part configuration consists of the following: |
33 | 33 |
|
34 |
| -Example: |
| 34 | +- An incrementing function |
| 35 | +- An optional value |
| 36 | +- A first value |
| 37 | +- A flag indicating its dependence or independence of changes to other version parts |
| 38 | + |
| 39 | +### Incrementing functions |
| 40 | + |
| 41 | +There are two incrementing functions: numeric and value. The numeric function uses integer values and returns the next integer value. The values function uses a sequence of values and returns the next value until finished. |
| 42 | + |
| 43 | +By default, parts use the numeric function starting at 0. |
35 | 44 |
|
36 |
| -```ini |
37 |
| -[bumpversion] |
38 |
| -current_version = 1.alpha |
39 |
| -parse = (?P<num>\d+)(\.(?P<release>.*))? |
40 |
| -serialize = |
41 |
| -{num}.{release} |
42 |
| -{num} |
43 |
| - |
44 |
| -[bumpversion:part:release] |
45 |
| -optional_value = gamma |
46 |
| -values = |
47 |
| -alpha |
48 |
| -beta |
49 |
| -gamma |
| 45 | +You can configure a part using the values function by providing a list of values in the version part's configuration. For example, for the `release_name` part: |
| 46 | + |
| 47 | +```toml |
| 48 | +[tool.bumpversion.parts.release_name] |
| 49 | +values = [ |
| 50 | + "witty-warthog", |
| 51 | + "ridiculous-rat", |
| 52 | + "marvelous-mantis", |
| 53 | +] |
50 | 54 | ```
|
51 | 55 |
|
52 |
| -Here, `bump-my-version release` would bump `1.alpha` to `1.beta`. Executing |
53 |
| -`bump-my-version release` again would bump `1.beta` to `1`, because |
54 |
| -`release` being `gamma` is configured optional. |
| 56 | +### Optional values |
| 57 | + |
| 58 | +By default, the *first* value of a version part is considered *optional.* An optional value may be omitted from the version serialization. Using the example from above: |
55 | 59 |
|
56 |
| -You should consider the version of `1` to technically be `1.gamma` |
57 |
| -with the `.gamma` part not being serialized since it is optional. |
58 |
| -The `{num}` entry in the `serialize` list allows the release part to be |
59 |
| -hidden. If you only had `{num}.{release}`, an optional release will always |
60 |
| -be serialized. |
| 60 | +```toml |
| 61 | +serialize = [ |
| 62 | + "{major}.{minor}.{patch}", |
| 63 | + "{major}.{minor}", |
| 64 | +] |
| 65 | +``` |
61 | 66 |
|
62 |
| -Attempting to bump the release when it is the value of |
63 |
| -`gamma` will cause a `ValueError` as it will think you are trying to |
64 |
| -exceed the `values` list of the release part. |
| 67 | +Version `1.4.0` is rendered as `1.4` since the `patch` is `0`; as the first value, it is optional. |
65 | 68 |
|
66 |
| ---- |
| 69 | +Optional values are helpful for non-numeric version parts that indicate development stages, such as [alpha or beta](http://en.wikipedia.org/wiki/Software_release_life_cycle#Stages_of_development). |
67 | 70 |
|
68 | 71 | Example:
|
69 | 72 |
|
70 |
| -```ini |
71 |
| -[bumpversion] |
72 |
| -current_version = 1.alpha1 |
73 |
| -parse = (?P<num>\d+)(\.(?P<release>.*)(?P<build>\d+))? |
74 |
| -serialize = |
75 |
| -{num}.{release}{build} |
76 |
| - |
77 |
| -[bumpversion:part:release] |
78 |
| -values = |
79 |
| -alpha |
80 |
| -beta |
81 |
| -gamma |
82 |
| - |
83 |
| -[bumpversion:part:build] |
84 |
| -first_value = 1 |
| 73 | +```toml |
| 74 | +[tool.bumpversion] |
| 75 | +current_version = "1.0.0" |
| 76 | +parse = """(?x) |
| 77 | + (?P<major>[0-9]+) |
| 78 | + \\.(?P<minor>[0-9]+) |
| 79 | + \\.(?P<patch>[0-9]+) |
| 80 | + (?: |
| 81 | + -(?P<pre_label>alpha|beta|stable) |
| 82 | + (?:-(?P<pre_n>[0-9]+))? |
| 83 | + )? |
| 84 | +""" |
| 85 | +serialize = [ |
| 86 | + "{major}.{minor}.{patch}-{pre_label}-{pre_n}", |
| 87 | + "{major}.{minor}.{patch}", |
| 88 | +] |
| 89 | + |
| 90 | +[tool.bumpversion.parts.pre_label] |
| 91 | +optional_value = "stable" |
| 92 | +values =[ |
| 93 | + "alpha", |
| 94 | + "beta", |
| 95 | + "stable", |
| 96 | +] |
85 | 97 | ```
|
86 | 98 |
|
87 |
| -Here, `bump-my-version release` would bump `1.alpha1` to `1.beta1`. |
| 99 | +Bumping the `patch` part of version `1.0.0` would change the version to `1.0.1-alpha-0`. Bumping the `pre_label` part would change the version to `1.0.1-beta-0`. Bumping the `pre_label` part again would change the version to `1.0.1`. The `stable-0` is not serialized because both `stable` and `0` are *optional*. |
88 | 100 |
|
89 |
| -Without the `first_value = 1` of the build part configured, |
90 |
| -`bump-my-version release` would bump `1.alpha1` to `1.beta0`, starting |
91 |
| -the build at `0`. |
| 101 | +### First Values |
92 | 102 |
|
| 103 | +You can specify the starting number with the first_value configuration for numeric version parts. |
93 | 104 |
|
| 105 | +For example, if we added the following to the above configuration: |
94 | 106 |
|
95 |
| ---- |
| 107 | +```toml |
| 108 | +[tool.bumpversion.parts.pre_n] |
| 109 | +first_value = "1" |
| 110 | +``` |
96 | 111 |
|
97 |
| -Example: |
| 112 | +Bumping the `patch` value of version `1.0.0` would change the version to `1.0.1-alpha-1` instead of `1.0.1-alpha-0`. |
| 113 | + |
| 114 | +### Independent Values |
98 | 115 |
|
99 |
| -```ini |
100 |
| -[bumpversion] |
101 |
| -current_version: 2.1.6-5123 |
102 |
| -parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\-(?P<build>\d+) |
103 |
| -serialize = {major}.{minor}.{patch}-{build} |
| 116 | +In the pattern `{major}.{minor}.{patch}-{pre_label}-{pre_n}`, each version part resets to its first value when the element preceding it changes. All these version parts are *dependent.* |
104 | 117 |
|
105 |
| -[bumpversion:file:VERSION.txt] |
| 118 | +You can include a value that incremented *independently* from the other parts, such as a `build` part: `{major}.{minor}.{patch}-{pre_label}-{pre_n}+{build}`—in the configuration for that part, set `independent=true`. |
106 | 119 |
|
107 |
| -[bumpversion:part:build] |
108 |
| -independent = True |
| 120 | +```toml |
| 121 | +[tool.bumpversion.parts.build] |
| 122 | +independent = true |
109 | 123 | ```
|
110 | 124 |
|
111 |
| -Here, `bump-my-version build` would bump `2.1.6-5123` to `2.1.6-5124`. Executing`bump-my-version major` |
112 |
| -would bump `2.1.6-5124` to `3.0.0-5124` without resetting the build number. |
| 125 | +## Reference |
| 126 | + |
| 127 | +- https://devopedia.org/semantic-versioning |
| 128 | +- https://semver.org |
| 129 | +- https://calver.org |
0 commit comments