blob: 0123dd2d58e075a3f98b6f0e118e7f6ef7bee4b1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# go-bumpver
_Inspired by the python bump2version tool._
bumpver - print the next semantec version in a given sequence
## Usage
```bash
bumpver part [major|minor|patch] [flags] file [-|file]
```
## Why?
- Most version bumpers are fairly tightly coupled to git
- Make commits for you
- Few have useful pre release mechanisms
- Lack of simple interfaces
- Lack of unix philosophy
## How?
`go-bumpver` takes the sequence of version(s) from a file or stdin and prints the next version. It drops invalid versions in the sequence and only uses valid ones. It does not make a tag or change any state in git or any other VCS, it only prints the next version. It also has the ability to bump pre-release tags using simple formating string.
### Inputs
**stdin**
```bash
❯ echo "1.1.1\n1.2.1" | bumpver patch -
1.2.2
```
**file**
```bash
❯ echo v0.1.0 > VERSION
❯ bumpver patch VERSION
0.1.1
```
**local repo**
```bash
❯ bumpver patch <(git tag -l)
3.3.2
```
**remote repo**
```bash
❯ bumpver patch <(git ls-remote --tags --refs origin v\* | awk -F'[ /]' '{ print $NF }')
3.3.4
```
**bump tags released along a branch**
This example supports software that has support for multiple versions at once. E.g. version 2.X is still supported but 3.X is based off of main.
```bash
❯ bumpver patch <(git tag --merged <release branch name>)
2.1.4
```
### Bumps
**a patch**
```bash
❯ bumpver patch <(git tag -l)
3.3.2
```
**a minor**
```bash
❯ bumpver minor <(git tag -l)
3.4.0
```
**a major**
```bash
❯ bumpver major <(git tag -l)
4.0.0
```
***prior version***
Getting the last version could be useful for generating diffs, release notes etc.
```bash
❯ bumpver major --last-version <(git tag -l)
3.8.1
❯ bumpver major <(git tag -l)
4.0.0
```
### Pre-release
Pre-releases can be formatted in a way that can be easily bumped. Providing `--prerelease` will generate a new prerelease for the given bump. Meaning if you use `major --prerelease` with the last version 1.2.2 will give `2.0.0-RC.0`.
Use Case:
- A Pull Request/Merge Request is opened. A tag needs to be generated for the PR/MR.
- Bumping release candidates for testing.
#### Format Strings
- `$BumpInt`: increases the integer value.
- `$KeyArg <KEY NAME>`: Value of the key from `key-args` option
#### $BumpInit
Consider the following format string: `rc.$BumpInt`
```bash
❯ echo "0.1.0-rc.1" | bumpver patch --prerelease --prerelease-fmt 'rc.$BumpInt' -
0.1.0-rc.2
```
A none existant pre-release yields
```bash
❯ echo "0.1.0" | bumpver patch --prerelease --prerelease-fmt 'rc.$BumpInt' -
0.1.1-rc.0
```
#### $KeyArg
`$KeyArg` allows for run time side effects on prerelease versions. This means you can bump an integer or provide key word argument. Example use cases:
- add the PR/MR number to the version
- add metadata for the version
```bash
❯ bumpver patch --prerelease --prerelease-fmt 'rc.$KeyArg PR_NUM.$BumpInt' --key-args PR_NUM=44 vers.txt
1.2.2-rc.44.0
❯ bumpver patch --prerelease --prerelease-fmt 'rc.$KeyArg USER_NAME.$BumpInt' --key-args USER_NAME=grumps vers.txt
1.2.2-rc.grumps.0
```
|