git-release-tag 0.8.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- git_release_tag/__init__.py +1 -0
- git_release_tag/__main__.py +213 -0
- git_release_tag/click_parameter_types.py +75 -0
- git_release_tag/git.py +32 -0
- git_release_tag/logger.py +9 -0
- git_release_tag/release_info.py +505 -0
- git_release_tag-0.8.1.dist-info/METADATA +178 -0
- git_release_tag-0.8.1.dist-info/RECORD +12 -0
- git_release_tag-0.8.1.dist-info/WHEEL +5 -0
- git_release_tag-0.8.1.dist-info/entry_points.txt +2 -0
- git_release_tag-0.8.1.dist-info/licenses/LICENSE +201 -0
- git_release_tag-0.8.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dry_run = False
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
import click
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from os.path import relpath
|
|
6
|
+
|
|
7
|
+
from git_release_tag.click_parameter_types import (
|
|
8
|
+
SemVer,
|
|
9
|
+
PreTagCommand,
|
|
10
|
+
ReleaseLevel,
|
|
11
|
+
OrderedGroup,
|
|
12
|
+
)
|
|
13
|
+
from git_release_tag.release_info import ReleaseInfo
|
|
14
|
+
from git_release_tag.logger import log
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@click.group(cls=OrderedGroup)
|
|
18
|
+
@click.option("--dry-run", is_flag=True, default=False, help="do not change anything")
|
|
19
|
+
@click.option("--verbose", is_flag=True, default=False, help="output")
|
|
20
|
+
@click.pass_context
|
|
21
|
+
def main(ctx, dry_run, verbose):
|
|
22
|
+
"""
|
|
23
|
+
semantic version tag support for components in git repositories.
|
|
24
|
+
"""
|
|
25
|
+
if verbose:
|
|
26
|
+
log.setLevel(logging.DEBUG)
|
|
27
|
+
ctx.obj = ctx.params
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@main.command()
|
|
31
|
+
@click.option(
|
|
32
|
+
"--initial-release",
|
|
33
|
+
type=SemVer(),
|
|
34
|
+
default="0.0.0",
|
|
35
|
+
required=False,
|
|
36
|
+
help="initial version",
|
|
37
|
+
)
|
|
38
|
+
@click.option("--tag-prefix", type=str, required=False, help="for the semver tag")
|
|
39
|
+
@click.option(
|
|
40
|
+
"--pre-tag-command",
|
|
41
|
+
type=PreTagCommand(),
|
|
42
|
+
default=None,
|
|
43
|
+
required=False,
|
|
44
|
+
help="to run before version is set and tag is made",
|
|
45
|
+
)
|
|
46
|
+
@click.option(
|
|
47
|
+
"--tag-on-changes-in",
|
|
48
|
+
type=click.Path(file_okay=False, exists=True),
|
|
49
|
+
default=["."],
|
|
50
|
+
required=False,
|
|
51
|
+
multiple=True,
|
|
52
|
+
help="bumps the release when there are changes in dependent directories",
|
|
53
|
+
)
|
|
54
|
+
@click.argument(
|
|
55
|
+
"directory", type=click.Path(file_okay=False, exists=True), required=True, nargs=-1
|
|
56
|
+
)
|
|
57
|
+
@click.pass_context
|
|
58
|
+
def initialize(
|
|
59
|
+
ctx, initial_release, tag_prefix, pre_tag_command, tag_on_changes_in, directory
|
|
60
|
+
):
|
|
61
|
+
"""
|
|
62
|
+
directory with release configuration.
|
|
63
|
+
|
|
64
|
+
Creates a release configuration using the specified `initial-release`, `tag-prefix`, and
|
|
65
|
+
`pre-tag-command`. the file is called .release and has the following syntax:
|
|
66
|
+
|
|
67
|
+
\b
|
|
68
|
+
release=<initial-release>
|
|
69
|
+
tag=<tag-prefix><initial-release>
|
|
70
|
+
pre_tag_command=<pre-tag-command>
|
|
71
|
+
tag_on_changes_in=<tag-on-changes-in-directory>
|
|
72
|
+
|
|
73
|
+
The `pre-tag-command` is executed and any outstanding changes are committed and tagged with
|
|
74
|
+
the specified `tag`.
|
|
75
|
+
|
|
76
|
+
The directories must be in a git workspace.
|
|
77
|
+
"""
|
|
78
|
+
directories = sorted(
|
|
79
|
+
directory, key=lambda p: len(os.path.abspath(p).split("/")), reverse=True
|
|
80
|
+
)
|
|
81
|
+
tag_on_changes_in = [Path(s).absolute().as_posix() for s in tag_on_changes_in]
|
|
82
|
+
prefixes = list(map(lambda d: os.path.basename(os.path.abspath(d)), directories))
|
|
83
|
+
if tag_prefix is not None and len(directories) > 1:
|
|
84
|
+
log.error("you cannot specify the same tag-prefix for different directories")
|
|
85
|
+
exit(1)
|
|
86
|
+
|
|
87
|
+
if len(set(prefixes)) != len(prefixes):
|
|
88
|
+
log.error(
|
|
89
|
+
"base directory names must be unique in order to avoid non unique tag-prefixes"
|
|
90
|
+
)
|
|
91
|
+
exit(1)
|
|
92
|
+
|
|
93
|
+
for path in directories:
|
|
94
|
+
component = ReleaseInfo(path)
|
|
95
|
+
if not component.is_inside_work_tree:
|
|
96
|
+
log.error("%s is not inside a git workspace, please run git init", path)
|
|
97
|
+
exit(1)
|
|
98
|
+
|
|
99
|
+
result = True
|
|
100
|
+
for path in directories:
|
|
101
|
+
relative_dirs = [relpath(s, Path(path).absolute()) for s in tag_on_changes_in]
|
|
102
|
+
result = (
|
|
103
|
+
ReleaseInfo.initialize(
|
|
104
|
+
path,
|
|
105
|
+
semver=initial_release,
|
|
106
|
+
base_tag=tag_prefix
|
|
107
|
+
if tag_prefix is not None
|
|
108
|
+
else f"{os.path.basename(os.path.abspath(path))}-",
|
|
109
|
+
pre_tag_command=pre_tag_command,
|
|
110
|
+
tag_on_changes_in=relative_dirs,
|
|
111
|
+
dry_run=ctx.obj["dry_run"],
|
|
112
|
+
)
|
|
113
|
+
and result
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
exit(not result)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
@main.command("show")
|
|
120
|
+
@click.option("--recursive", "-r", is_flag=True, default=False, help="all directories")
|
|
121
|
+
@click.option("--with-tags", is_flag=True, default=False, help="of the latest release")
|
|
122
|
+
@click.argument(
|
|
123
|
+
"directory", type=click.Path(file_okay=False, exists=True), required=False, nargs=-1
|
|
124
|
+
)
|
|
125
|
+
@click.pass_context
|
|
126
|
+
def show(ctx, recursive, with_tags, directory):
|
|
127
|
+
"""
|
|
128
|
+
current release version.
|
|
129
|
+
|
|
130
|
+
If a single directory is specified, it will print out the current release version in the
|
|
131
|
+
form of `<release>[<-sha-commit>[-dirty]]`. If multiple directories are specified, it will print out the
|
|
132
|
+
directory name followed by the release version.
|
|
133
|
+
"""
|
|
134
|
+
release_infos = ReleaseInfo.find_all(directory, recursive, ctx.obj["dry_run"])
|
|
135
|
+
for release_info in release_infos:
|
|
136
|
+
if not release_info.has_release_configuration:
|
|
137
|
+
log.error(
|
|
138
|
+
f"directory {release_info.directory} has no release configuration"
|
|
139
|
+
)
|
|
140
|
+
exit(1)
|
|
141
|
+
|
|
142
|
+
if recursive:
|
|
143
|
+
if with_tags:
|
|
144
|
+
print(
|
|
145
|
+
f"{release_info.directory}\t{release_info.current_version}\t{release_info.tag}"
|
|
146
|
+
)
|
|
147
|
+
else:
|
|
148
|
+
print(f"{release_info.directory}\t{release_info.current_version}")
|
|
149
|
+
else:
|
|
150
|
+
print(release_info.current_version)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
@main.command("bump")
|
|
154
|
+
@click.option("--recursive", "-r", is_flag=True, default=False, help="all directories")
|
|
155
|
+
@click.option("--level", type=ReleaseLevel(), required=True, help="to bump")
|
|
156
|
+
@click.option(
|
|
157
|
+
"--force", is_flag=True, default=False, help="even if there are no changes"
|
|
158
|
+
)
|
|
159
|
+
@click.argument(
|
|
160
|
+
"directory", type=click.Path(file_okay=False, exists=True), required=False, nargs=-1
|
|
161
|
+
)
|
|
162
|
+
@click.pass_context
|
|
163
|
+
def bump(ctx, recursive: bool, force: bool, level: int, directory):
|
|
164
|
+
"""
|
|
165
|
+
semantic version and tags the commit.
|
|
166
|
+
|
|
167
|
+
It either bumps the major, minor or the level of the semantic version and tag the commit.
|
|
168
|
+
`--force` will update the semantic version, even if there are no changes since the previous release.
|
|
169
|
+
|
|
170
|
+
The `pre-tag-command` is executed and any outstanding changes are committed and tagged with
|
|
171
|
+
the specified `tag`.
|
|
172
|
+
"""
|
|
173
|
+
release_infos = ReleaseInfo.find_all(directory, recursive, ctx.obj["dry_run"])
|
|
174
|
+
|
|
175
|
+
if not ReleaseInfo.validate(release_infos):
|
|
176
|
+
exit(1)
|
|
177
|
+
|
|
178
|
+
for release_info in release_infos:
|
|
179
|
+
release_info.tag_next_release(level, force=force)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
@main.command("validate")
|
|
183
|
+
@click.option(
|
|
184
|
+
"--recursive/--no-recursive",
|
|
185
|
+
"-r",
|
|
186
|
+
is_flag=True,
|
|
187
|
+
default=False,
|
|
188
|
+
help="all directories",
|
|
189
|
+
)
|
|
190
|
+
@click.argument(
|
|
191
|
+
"directory", type=click.Path(file_okay=False, exists=True), required=False, nargs=-1
|
|
192
|
+
)
|
|
193
|
+
@click.pass_context
|
|
194
|
+
def validate(ctx, recursive: bool, directory):
|
|
195
|
+
"""
|
|
196
|
+
integrity of release configuration.
|
|
197
|
+
|
|
198
|
+
checks whether the specified directories use a unique tag prefix and
|
|
199
|
+
whether the specified tag exists in the git repository.
|
|
200
|
+
"""
|
|
201
|
+
try:
|
|
202
|
+
release_infos = ReleaseInfo.find_all(directory, recursive, True)
|
|
203
|
+
if ReleaseInfo.validate(release_infos):
|
|
204
|
+
logging.info("ok")
|
|
205
|
+
else:
|
|
206
|
+
exit(1)
|
|
207
|
+
except ValueError as error:
|
|
208
|
+
logging.error(str(error))
|
|
209
|
+
exit(1)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
if __name__ == "__main__":
|
|
213
|
+
main()
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import click
|
|
2
|
+
import re
|
|
3
|
+
from collections import OrderedDict
|
|
4
|
+
from git_release_tag.release_info import ReleaseInfo
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class SemVer(click.ParamType):
|
|
8
|
+
"""
|
|
9
|
+
a semantic version in the form of major.minor.patch
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
name = "semver"
|
|
13
|
+
|
|
14
|
+
def convert(self, value, param, ctx) -> str:
|
|
15
|
+
if value is None:
|
|
16
|
+
return value
|
|
17
|
+
|
|
18
|
+
m = re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", value)
|
|
19
|
+
if not m:
|
|
20
|
+
self.fail(f'could not parse "{value}" as release')
|
|
21
|
+
|
|
22
|
+
return value
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class PreTagCommand(click.ParamType):
|
|
26
|
+
"""
|
|
27
|
+
a shell command containing references to @@RELEASE@@, @@TAG@@ or @@BASE_TAG@@
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
name = "pre_tag_command"
|
|
31
|
+
|
|
32
|
+
def convert(self, value, param, ctx) -> str:
|
|
33
|
+
if not value is None:
|
|
34
|
+
return value
|
|
35
|
+
|
|
36
|
+
allowed = set(["RELEASE", "TAG", "BASE_TAG"])
|
|
37
|
+
refs = set(re.findall(r"@@([a-zA-Z_]+)@@", value))
|
|
38
|
+
unsupported = refs.difference(allowed)
|
|
39
|
+
if unsupported:
|
|
40
|
+
self.fail(f"found unsupported references {unsupported}")
|
|
41
|
+
if "RELEASE" not in refs:
|
|
42
|
+
self.fail(f"expected at least a @@RELEASE@@ reference in pre tag command")
|
|
43
|
+
|
|
44
|
+
return value
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class ReleaseLevel(click.Choice):
|
|
48
|
+
"""
|
|
49
|
+
release level patch, minor or major
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
name = "release-level"
|
|
53
|
+
|
|
54
|
+
def __init__(self):
|
|
55
|
+
super(ReleaseLevel, self).__init__(["patch", "minor", "major"])
|
|
56
|
+
|
|
57
|
+
def convert(self, value, param, ctx) -> str:
|
|
58
|
+
result = super(ReleaseLevel, self).convert(value, param, ctx)
|
|
59
|
+
levels = {
|
|
60
|
+
"major": ReleaseInfo.MAJOR,
|
|
61
|
+
"minor": ReleaseInfo.MINOR,
|
|
62
|
+
"patch": ReleaseInfo.PATCH,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return levels.get(result)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class OrderedGroup(click.Group):
|
|
69
|
+
def __init__(self, name=None, commands=None, **attrs):
|
|
70
|
+
super(OrderedGroup, self).__init__(name, commands, **attrs)
|
|
71
|
+
#: the registered subcommands by their exported names.
|
|
72
|
+
self.commands = commands or OrderedDict()
|
|
73
|
+
|
|
74
|
+
def list_commands(self, ctx):
|
|
75
|
+
return self.commands
|
git_release_tag/git.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
import re
|
|
3
|
+
from git_release_tag.logger import log
|
|
4
|
+
import subprocess
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _to_cli(cmd: List[str]):
|
|
8
|
+
return " ".join(map(lambda s: f"'{s}'" if re.findall(r"\s", s) else s, cmd))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def exec(cmd: List[str], cwd: str, dry_run: bool = False, fail_on_error: bool = True):
|
|
12
|
+
log.debug("$ %s #cwd = %s", _to_cli(cmd), cwd)
|
|
13
|
+
|
|
14
|
+
if dry_run:
|
|
15
|
+
return ("", ""), None
|
|
16
|
+
|
|
17
|
+
process = subprocess.Popen(
|
|
18
|
+
cmd,
|
|
19
|
+
cwd=cwd,
|
|
20
|
+
stdout=subprocess.PIPE,
|
|
21
|
+
stderr=subprocess.PIPE,
|
|
22
|
+
universal_newlines=True,
|
|
23
|
+
)
|
|
24
|
+
out = process.communicate()
|
|
25
|
+
log.debug("returncode = %s", process.returncode)
|
|
26
|
+
log.debug("stdout = %s", out[0])
|
|
27
|
+
log.debug("stderr = %s", out[1])
|
|
28
|
+
if fail_on_error and process.returncode != 0:
|
|
29
|
+
log.error("%s failed in %s, %s", " ".join(cmd), cwd, (out[0] + out[1]))
|
|
30
|
+
exit(1)
|
|
31
|
+
|
|
32
|
+
return out, process
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import fnmatch
|
|
2
|
+
import os
|
|
3
|
+
import re
|
|
4
|
+
import subprocess
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import List, Optional
|
|
7
|
+
|
|
8
|
+
from git_release_tag import git
|
|
9
|
+
from git_release_tag.logger import log
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ReleaseInfo(object):
|
|
13
|
+
PATCH = 2
|
|
14
|
+
MINOR = 1
|
|
15
|
+
MAJOR = 0
|
|
16
|
+
|
|
17
|
+
def __init__(self, path: str, dry_run: bool = False):
|
|
18
|
+
super(ReleaseInfo, self).__init__()
|
|
19
|
+
self.dry_run = dry_run
|
|
20
|
+
self.directory = path
|
|
21
|
+
self.path = os.path.join(os.path.abspath(self.directory), ".release")
|
|
22
|
+
self.tag_on_changes_in = ["."]
|
|
23
|
+
|
|
24
|
+
self.base_tag = None
|
|
25
|
+
self._semver = None
|
|
26
|
+
self._pre_tag_command = None
|
|
27
|
+
|
|
28
|
+
if not os.path.isdir(self.directory):
|
|
29
|
+
log.error(f"directory {self.directory} does not exist")
|
|
30
|
+
exit(1)
|
|
31
|
+
|
|
32
|
+
if self.has_release_configuration:
|
|
33
|
+
self.read()
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def tag_on_changes_in(self) -> [str]:
|
|
37
|
+
"""
|
|
38
|
+
the list of directories which determine the release.
|
|
39
|
+
"""
|
|
40
|
+
return self._compare_directories
|
|
41
|
+
|
|
42
|
+
@tag_on_changes_in.setter
|
|
43
|
+
def tag_on_changes_in(self, directories: [str]):
|
|
44
|
+
self._compare_directories = directories if directories else ["."]
|
|
45
|
+
root = self.git_top_level(Path(self.directory).absolute())
|
|
46
|
+
|
|
47
|
+
relative_directories = []
|
|
48
|
+
for directory in self._compare_directories:
|
|
49
|
+
absolute_path = Path(self.directory).absolute().joinpath(directory)
|
|
50
|
+
if not absolute_path.is_dir():
|
|
51
|
+
raise ValueError(
|
|
52
|
+
f"dependency {directory} of {self.directory} is not a directory"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
toplevel = self.git_top_level(absolute_path)
|
|
56
|
+
if toplevel != root:
|
|
57
|
+
raise ValueError(
|
|
58
|
+
f"dependency {directory} is not in the same git repository as {self.directory}"
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
relative_directories.append(os.path.relpath(absolute_path, self.directory))
|
|
62
|
+
self._compare_directories = relative_directories
|
|
63
|
+
|
|
64
|
+
if "." not in self._compare_directories:
|
|
65
|
+
self._compare_directories.append(".")
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def has_release_configuration(self) -> bool:
|
|
69
|
+
return os.path.exists(self.path)
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def semver(self):
|
|
73
|
+
return self._semver
|
|
74
|
+
|
|
75
|
+
@semver.setter
|
|
76
|
+
def semver(self, value):
|
|
77
|
+
if value and not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", value):
|
|
78
|
+
raise ValueError(
|
|
79
|
+
f"semantic version of release '{self.semver}' does not match release <major>.<minor>.<patch>"
|
|
80
|
+
)
|
|
81
|
+
self._semver = value
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def pre_tag_command(self):
|
|
85
|
+
return self._pre_tag_command
|
|
86
|
+
|
|
87
|
+
@pre_tag_command.setter
|
|
88
|
+
def pre_tag_command(self, value):
|
|
89
|
+
if value:
|
|
90
|
+
allowed = set(["RELEASE", "TAG", "BASE_TAG"])
|
|
91
|
+
refs = set(re.findall(r"@@([a-zA-Z_]+)@@", value))
|
|
92
|
+
unsupported = refs.difference(allowed)
|
|
93
|
+
if unsupported:
|
|
94
|
+
raise ValueError(f"found unsupported references {unsupported}")
|
|
95
|
+
if "RELEASE" not in refs:
|
|
96
|
+
raise ValueError(
|
|
97
|
+
f"expected at least a @@RELEASE@@ reference in pre tag command: '{value}' of {self.directory}"
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
self._pre_tag_command = value
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def tag(self):
|
|
104
|
+
return f"{self.base_tag}{self.semver}"
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def all_tags(self) -> List[str]:
|
|
108
|
+
return list(
|
|
109
|
+
map(lambda l: l.strip(), self.git_query(["git", "tag"]).split("\n"))
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
def read(self):
|
|
113
|
+
result = {}
|
|
114
|
+
with open(self.path, "r") as f:
|
|
115
|
+
for line in f:
|
|
116
|
+
line = line.rstrip()
|
|
117
|
+
if len(line) > 0 and line[0] != "#":
|
|
118
|
+
value = line.split("=", 1)
|
|
119
|
+
result[value[0].strip()] = value[1].strip()
|
|
120
|
+
if not ("release" in result and "tag" in result):
|
|
121
|
+
log.error(f"{self.path} does not contain release and/or tag values")
|
|
122
|
+
exit(1)
|
|
123
|
+
|
|
124
|
+
if not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", result["release"]):
|
|
125
|
+
log.error(
|
|
126
|
+
f"ERROR: incorrect format of release in {self.path}, expected <major.minor.patch>"
|
|
127
|
+
)
|
|
128
|
+
exit(1)
|
|
129
|
+
self.semver = result["release"]
|
|
130
|
+
|
|
131
|
+
match = re.search(r"(?P<release>[0-9]+\.[0-9]+\.[0-9]+$)", result["tag"])
|
|
132
|
+
if match:
|
|
133
|
+
self.base_tag = result["tag"][: match.start()]
|
|
134
|
+
if match.group("release") != self.semver:
|
|
135
|
+
log.warning(
|
|
136
|
+
f"tag {self.tag} in {self.path} does not match specified release {match.group('release')}"
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
else:
|
|
140
|
+
log.error(
|
|
141
|
+
f"ERROR: incorrect format old the tag in {self.path}, expected tag <base>{self.semver}"
|
|
142
|
+
)
|
|
143
|
+
exit(1)
|
|
144
|
+
|
|
145
|
+
try:
|
|
146
|
+
self.tag_on_changes_in = result.get("tag_on_changes_in", ".").split()
|
|
147
|
+
except ValueError as error:
|
|
148
|
+
log.error(error)
|
|
149
|
+
exit(1)
|
|
150
|
+
|
|
151
|
+
self.pre_tag_command = result.get("pre_tag_command")
|
|
152
|
+
|
|
153
|
+
def __repr__(self):
|
|
154
|
+
return self.path
|
|
155
|
+
|
|
156
|
+
def __eq__(self, other):
|
|
157
|
+
return self.path == other.path
|
|
158
|
+
|
|
159
|
+
def __hash__(self):
|
|
160
|
+
return hash(self.path)
|
|
161
|
+
|
|
162
|
+
def write(self):
|
|
163
|
+
log.debug(f"writing {self.path}")
|
|
164
|
+
if self.dry_run:
|
|
165
|
+
return
|
|
166
|
+
|
|
167
|
+
with open(self.path, "w") as f:
|
|
168
|
+
f.write("release=%s\n" % self.semver)
|
|
169
|
+
f.write("tag=%s\n" % self.tag)
|
|
170
|
+
if self.pre_tag_command:
|
|
171
|
+
f.write("pre_tag_command=%s\n" % self.pre_tag_command)
|
|
172
|
+
if self.tag_on_changes_in and self.tag_on_changes_in != ["."]:
|
|
173
|
+
f.write(
|
|
174
|
+
"tag_on_changes_in={}\n".format(" ".join(self.tag_on_changes_in))
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
def next_version(self, level):
|
|
178
|
+
assert self.semver
|
|
179
|
+
release = list(map(lambda n: int(n), self.semver.split(".")))
|
|
180
|
+
if level == ReleaseInfo.PATCH:
|
|
181
|
+
release[ReleaseInfo.PATCH] += 1
|
|
182
|
+
elif level == ReleaseInfo.MINOR:
|
|
183
|
+
release[ReleaseInfo.MINOR] += 1
|
|
184
|
+
release[ReleaseInfo.PATCH] = 0
|
|
185
|
+
elif level == ReleaseInfo.MAJOR:
|
|
186
|
+
release[ReleaseInfo.MAJOR] += 1
|
|
187
|
+
release[ReleaseInfo.MINOR] = 0
|
|
188
|
+
release[ReleaseInfo.PATCH] = 0
|
|
189
|
+
else:
|
|
190
|
+
log.error("I can only bump PATCH, MINOR or MAJOR levels")
|
|
191
|
+
exit(1)
|
|
192
|
+
|
|
193
|
+
self.semver = "%d.%d.%d" % (release[0], release[1], release[2])
|
|
194
|
+
|
|
195
|
+
def git_query(self, cmd: List[str], fail_on_error: bool = True) -> str:
|
|
196
|
+
out, process = git.exec(
|
|
197
|
+
cmd, self.directory, dry_run=False, fail_on_error=fail_on_error
|
|
198
|
+
)
|
|
199
|
+
return out[0]
|
|
200
|
+
|
|
201
|
+
def git_update(self, cmd: List[str]) -> str:
|
|
202
|
+
out, process = git.exec(
|
|
203
|
+
cmd, self.directory, dry_run=self.dry_run, fail_on_error=True
|
|
204
|
+
)
|
|
205
|
+
return out[0]
|
|
206
|
+
|
|
207
|
+
@staticmethod
|
|
208
|
+
def git_top_level(directory) -> str:
|
|
209
|
+
out, _ = git.exec(
|
|
210
|
+
["git", "rev-parse", "--show-toplevel"],
|
|
211
|
+
directory,
|
|
212
|
+
dry_run=False,
|
|
213
|
+
fail_on_error=False,
|
|
214
|
+
)
|
|
215
|
+
return out[0].strip()
|
|
216
|
+
|
|
217
|
+
@property
|
|
218
|
+
def is_inside_work_tree(self):
|
|
219
|
+
cmd = ["git", "rev-parse", "--is-inside-work-tree"]
|
|
220
|
+
out, process = git.exec(cmd, self.directory, dry_run=False, fail_on_error=False)
|
|
221
|
+
return process.returncode == 0 and out[0].strip() == "true"
|
|
222
|
+
|
|
223
|
+
@property
|
|
224
|
+
def git_prefix(self):
|
|
225
|
+
return (
|
|
226
|
+
self.git_query(["git", "rev-parse", "--show-prefix"]).rstrip().rstrip("/")
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
@property
|
|
230
|
+
def short_revision(self) -> str:
|
|
231
|
+
return self.git_query(
|
|
232
|
+
add_arguments(
|
|
233
|
+
["git", "log", "-n", "1", "--format=%h", "--"],
|
|
234
|
+
self.tag_on_changes_in,
|
|
235
|
+
)
|
|
236
|
+
).rstrip()
|
|
237
|
+
|
|
238
|
+
@property
|
|
239
|
+
def changes_since_tag(self) -> str:
|
|
240
|
+
return self.git_query(
|
|
241
|
+
add_arguments(
|
|
242
|
+
["git", "diff", "--shortstat", "-r", self.tag, "--"],
|
|
243
|
+
self.tag_on_changes_in,
|
|
244
|
+
)
|
|
245
|
+
).rstrip()
|
|
246
|
+
|
|
247
|
+
@property
|
|
248
|
+
def change_list(self) -> List[str]:
|
|
249
|
+
return list(
|
|
250
|
+
filter(
|
|
251
|
+
lambda c: c,
|
|
252
|
+
self.git_query(
|
|
253
|
+
add_arguments(["git", "status", "-s", "--"], self.tag_on_changes_in)
|
|
254
|
+
).split("\n"),
|
|
255
|
+
)
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
@property
|
|
259
|
+
def current_version(self):
|
|
260
|
+
if self.change_list:
|
|
261
|
+
return f"{self.semver}-{self.short_revision}-dirty"
|
|
262
|
+
elif self.changes_since_tag:
|
|
263
|
+
return f"{self.semver}-{self.short_revision}"
|
|
264
|
+
else:
|
|
265
|
+
return self.semver
|
|
266
|
+
|
|
267
|
+
def tag_next_release(self, level, message: str = None, force: bool = False):
|
|
268
|
+
if not force:
|
|
269
|
+
changes = self.changes_since_tag
|
|
270
|
+
if changes:
|
|
271
|
+
log.info(f"found {changes} since {self.semver}.")
|
|
272
|
+
else:
|
|
273
|
+
log.info(f"{self.directory} has no changes since {self.semver}.")
|
|
274
|
+
return
|
|
275
|
+
|
|
276
|
+
self.next_version(level)
|
|
277
|
+
if self.tag in self.all_tags:
|
|
278
|
+
log.error(f"tag {self.tag} already exists")
|
|
279
|
+
exit(1)
|
|
280
|
+
|
|
281
|
+
self.write()
|
|
282
|
+
if not message:
|
|
283
|
+
message = f"bumped {self.git_prefix} to release {self.semver}"
|
|
284
|
+
self.commit_and_tag(message)
|
|
285
|
+
|
|
286
|
+
def git_init(self):
|
|
287
|
+
self.git_update(["git", "init"])
|
|
288
|
+
|
|
289
|
+
def commit_and_tag(self, message: str):
|
|
290
|
+
self.exec_pre_tag_command()
|
|
291
|
+
|
|
292
|
+
changes = list(map(lambda s: s[3:], self.change_list))
|
|
293
|
+
if changes:
|
|
294
|
+
log.info(f"commit changes to {', '.join(changes)} in {self.directory}")
|
|
295
|
+
self.git_update(add_arguments(["git", "add"], self.tag_on_changes_in))
|
|
296
|
+
self.git_update(["git", "commit", "-m", message])
|
|
297
|
+
else:
|
|
298
|
+
log.info(f"no changes to commit in {self.directory}")
|
|
299
|
+
|
|
300
|
+
self.git_update(["git", "tag", self.tag])
|
|
301
|
+
log.info(f"release {self.semver} of {self.directory} tagged by {self.tag}")
|
|
302
|
+
|
|
303
|
+
@staticmethod
|
|
304
|
+
def initialize(
|
|
305
|
+
directory: str,
|
|
306
|
+
semver: str = "0.0.0",
|
|
307
|
+
base_tag: str = "",
|
|
308
|
+
pre_tag_command: str = "",
|
|
309
|
+
tag_on_changes_in=["."],
|
|
310
|
+
dry_run: bool = False,
|
|
311
|
+
) -> bool:
|
|
312
|
+
if not os.path.isdir(directory):
|
|
313
|
+
log.error(f"{directory} is not a directory.")
|
|
314
|
+
exit(1)
|
|
315
|
+
|
|
316
|
+
path = os.path.join(directory, ".release")
|
|
317
|
+
if os.path.exists(path):
|
|
318
|
+
log.error(f"{directory} is ready initialized.")
|
|
319
|
+
return False
|
|
320
|
+
|
|
321
|
+
info = ReleaseInfo(path=directory, dry_run=dry_run)
|
|
322
|
+
info.semver = semver
|
|
323
|
+
info.base_tag = base_tag
|
|
324
|
+
info.pre_tag_command = pre_tag_command
|
|
325
|
+
info.tag_on_changes_in = tag_on_changes_in
|
|
326
|
+
|
|
327
|
+
if info.is_inside_work_tree and info.tag in info.all_tags:
|
|
328
|
+
log.error(f"tag {info.tag} already exist in git repository for {info.path}")
|
|
329
|
+
exit(1)
|
|
330
|
+
|
|
331
|
+
info.write()
|
|
332
|
+
if info.is_inside_work_tree:
|
|
333
|
+
info.commit_and_tag(
|
|
334
|
+
f"initialized {info.git_prefix} to release {info.semver}"
|
|
335
|
+
)
|
|
336
|
+
else:
|
|
337
|
+
log.warning(f"{info.path} is not inside a git workspace")
|
|
338
|
+
|
|
339
|
+
return True
|
|
340
|
+
|
|
341
|
+
def process_pre_tag_command(self):
|
|
342
|
+
result = self.pre_tag_command.replace("@@RELEASE@@", self.semver)
|
|
343
|
+
result = result.replace("@@TAG@@", self.tag)
|
|
344
|
+
return result.replace("@@BASE_TAG@@", self.base_tag)
|
|
345
|
+
|
|
346
|
+
def exec_pre_tag_command(self):
|
|
347
|
+
if self.dry_run and self.pre_tag_command:
|
|
348
|
+
log.debug(f"$ {self.pre_tag_command}")
|
|
349
|
+
return
|
|
350
|
+
|
|
351
|
+
if self.pre_tag_command:
|
|
352
|
+
cmd = self.process_pre_tag_command()
|
|
353
|
+
process = subprocess.Popen(
|
|
354
|
+
cmd,
|
|
355
|
+
shell=True,
|
|
356
|
+
cwd=self.directory,
|
|
357
|
+
stdout=subprocess.PIPE,
|
|
358
|
+
stderr=subprocess.PIPE,
|
|
359
|
+
)
|
|
360
|
+
out = process.communicate()
|
|
361
|
+
if process.returncode != 0:
|
|
362
|
+
log.error(
|
|
363
|
+
f"{self.pre_tag_command} in {self.directory}, returned {process.returncode}, output {out[1]}"
|
|
364
|
+
)
|
|
365
|
+
exit(1)
|
|
366
|
+
return out[0]
|
|
367
|
+
|
|
368
|
+
@staticmethod
|
|
369
|
+
def validate(release_infos: List["ReleaseInfo"]) -> bool:
|
|
370
|
+
result = True
|
|
371
|
+
base_tags = {}
|
|
372
|
+
for release_info in release_infos:
|
|
373
|
+
base_tag = release_info.base_tag
|
|
374
|
+
existing = base_tags.get(base_tag)
|
|
375
|
+
if release_info.base_tag in base_tags:
|
|
376
|
+
log.error(
|
|
377
|
+
f"{release_info.path} has the same base tag as {existing.path}: {base_tag}"
|
|
378
|
+
)
|
|
379
|
+
result = False
|
|
380
|
+
else:
|
|
381
|
+
base_tags[base_tag] = release_info
|
|
382
|
+
|
|
383
|
+
if not release_info.is_inside_work_tree:
|
|
384
|
+
log.error(f"{release_info.directory} is not inside a git workspace")
|
|
385
|
+
result = False
|
|
386
|
+
else:
|
|
387
|
+
if release_info.tag not in release_info.all_tags:
|
|
388
|
+
log.error(
|
|
389
|
+
f"tag {release_info.tag} in {release_info.path} does not exist in repository"
|
|
390
|
+
)
|
|
391
|
+
result = False
|
|
392
|
+
|
|
393
|
+
return result
|
|
394
|
+
|
|
395
|
+
# staticmethod
|
|
396
|
+
def find_all(
|
|
397
|
+
directories: Optional[List[str]], recursive: bool, dry_run: bool
|
|
398
|
+
) -> List["ReleaseInfo"]:
|
|
399
|
+
"""
|
|
400
|
+
filters all directories with a .release configuration and returns a list of ReleaseInfo.
|
|
401
|
+
if recursive is specified the directories are traversed to find all subdirectories with a .release.
|
|
402
|
+
.release files ignored by git are skipped, see is_ignored_by_git.
|
|
403
|
+
If no directories are specified, the current working directory is used.
|
|
404
|
+
The resulting list is sorted depth first, to ensure that parent directories are processed last.
|
|
405
|
+
"""
|
|
406
|
+
result = []
|
|
407
|
+
if not directories:
|
|
408
|
+
directories = ["."]
|
|
409
|
+
|
|
410
|
+
if recursive:
|
|
411
|
+
for dir in directories:
|
|
412
|
+
for root, _, files in os.walk(dir, topdown=False):
|
|
413
|
+
for item in fnmatch.filter(files, ".release"):
|
|
414
|
+
if is_ignored_by_git(os.path.join(root, item), dir):
|
|
415
|
+
log.debug(
|
|
416
|
+
f"skipping {os.path.join(root, item)}, ignored by git"
|
|
417
|
+
)
|
|
418
|
+
continue
|
|
419
|
+
info = ReleaseInfo(path=os.path.join(root), dry_run=dry_run)
|
|
420
|
+
info.read()
|
|
421
|
+
result.append(info)
|
|
422
|
+
else:
|
|
423
|
+
for dir in directories:
|
|
424
|
+
result.append(ReleaseInfo(dir, dry_run=dry_run))
|
|
425
|
+
|
|
426
|
+
return order_release_infos(result)
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
def order_release_infos(release_infos: [ReleaseInfo]) -> [ReleaseInfo]:
|
|
430
|
+
"""
|
|
431
|
+
sort the release infos in the order in which they can be processed without causing an
|
|
432
|
+
endless tagging loop due to the tag_on_changes_in directory.
|
|
433
|
+
"""
|
|
434
|
+
infos = {os.path.abspath(r.directory): r for r in release_infos}
|
|
435
|
+
|
|
436
|
+
graph = {}
|
|
437
|
+
for directory, info in infos.items():
|
|
438
|
+
graph[directory] = []
|
|
439
|
+
for dependent_directory in map(
|
|
440
|
+
lambda d: os.path.abspath(os.path.join(directory, d)),
|
|
441
|
+
info.tag_on_changes_in,
|
|
442
|
+
):
|
|
443
|
+
if dependent_directory not in infos.keys():
|
|
444
|
+
graph[dependent_directory] = []
|
|
445
|
+
if dependent_directory != directory:
|
|
446
|
+
graph[directory].append(dependent_directory)
|
|
447
|
+
|
|
448
|
+
def visit(directory, stack, visited):
|
|
449
|
+
visited.add(directory)
|
|
450
|
+
for dep in graph[directory]:
|
|
451
|
+
if dep not in visited:
|
|
452
|
+
visit(dep, stack, visited)
|
|
453
|
+
else:
|
|
454
|
+
raise ValueError(f"cycle detected on {dep} from {directory}")
|
|
455
|
+
visited.remove(directory)
|
|
456
|
+
if directory not in stack:
|
|
457
|
+
stack.append(directory)
|
|
458
|
+
|
|
459
|
+
stack = []
|
|
460
|
+
visited = set()
|
|
461
|
+
sorted_on_depth = sorted(graph.keys(), key=lambda x: -len(x.split("/")))
|
|
462
|
+
|
|
463
|
+
for directory in sorted_on_depth:
|
|
464
|
+
if directory in infos:
|
|
465
|
+
visit(directory, stack, visited)
|
|
466
|
+
|
|
467
|
+
return [infos[p] for p in filter(lambda p: p in infos, stack)]
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
def is_ignored_by_git(path: str, start: str) -> bool:
|
|
471
|
+
"""
|
|
472
|
+
returns True if git ignores `path`, either in the repository that contains it, or because
|
|
473
|
+
that repository is a nested repository (such as a worktree) in a directory that an
|
|
474
|
+
enclosing repository below `start` ignores. Paths outside a git repository and paths in
|
|
475
|
+
submodules are not ignored.
|
|
476
|
+
"""
|
|
477
|
+
start = os.path.realpath(start)
|
|
478
|
+
path = os.path.realpath(path)
|
|
479
|
+
while True:
|
|
480
|
+
directory = os.path.dirname(path)
|
|
481
|
+
_, process = git.exec(
|
|
482
|
+
["git", "check-ignore", "--quiet", "--", path],
|
|
483
|
+
directory,
|
|
484
|
+
fail_on_error=False,
|
|
485
|
+
)
|
|
486
|
+
if process.returncode == 0:
|
|
487
|
+
return True
|
|
488
|
+
|
|
489
|
+
toplevel = ReleaseInfo.git_top_level(directory)
|
|
490
|
+
if not toplevel or toplevel == start:
|
|
491
|
+
return False
|
|
492
|
+
if os.path.commonpath([toplevel, start]) != start:
|
|
493
|
+
return False
|
|
494
|
+
path = toplevel
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
def add_arguments(command: [str], arguments: [str]) -> [str]:
|
|
498
|
+
"""
|
|
499
|
+
appends the arguments to the command
|
|
500
|
+
"""
|
|
501
|
+
from copy import copy
|
|
502
|
+
|
|
503
|
+
result = copy(command)
|
|
504
|
+
result.extend(arguments)
|
|
505
|
+
return result
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: git-release-tag
|
|
3
|
+
Version: 0.8.1
|
|
4
|
+
Summary: semantic version tag support for components git repositories
|
|
5
|
+
Author-email: Mark van Holsteijn <mark@binx.io>
|
|
6
|
+
License: BSD
|
|
7
|
+
Project-URL: Homepage, https://github.com/binxio/git-release-tag
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
12
|
+
Classifier: Operating System :: POSIX
|
|
13
|
+
Classifier: Operating System :: MacOS
|
|
14
|
+
Classifier: Operating System :: Unix
|
|
15
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: click
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# git release tag
|
|
25
|
+
semantic versioning support for components in git repositories.
|
|
26
|
+
|
|
27
|
+
With the advent of continuous integration and continuous delivery, every commit to the source code repository delivers
|
|
28
|
+
a new version of the software. The git source code repository system uses a 40 character long revision number, which
|
|
29
|
+
very accurately point at a specific version of the source code. However, these revision number are hard to read
|
|
30
|
+
for humans. This tool allows you to combine the best of both worlds: human readable version numbers while still being
|
|
31
|
+
able to uniquely identify a specific commit of the source code.
|
|
32
|
+
|
|
33
|
+
## How do I use this?
|
|
34
|
+
First you initialize the release configuration as follows:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
git-release-tag initialize --initial-release 1.0.0 --tag-prefix v .
|
|
38
|
+
>>INFO: commit changes to .release in .
|
|
39
|
+
>>INFO: release 1.0.0 of . tagged by v1.0.0
|
|
40
|
+
```
|
|
41
|
+
This will add a file called `.release` to the repository. It contains both the release and tag of the component
|
|
42
|
+
and place the tag.
|
|
43
|
+
|
|
44
|
+
Now you can show the current version of the source code:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
git-release-tag show
|
|
48
|
+
>> 1.0.0
|
|
49
|
+
```
|
|
50
|
+
If you have outstanding changes in your workspace, the version is appended with the first 8 digits of the git revision number and
|
|
51
|
+
`dirty`:
|
|
52
|
+
```bash
|
|
53
|
+
git-release-tag show
|
|
54
|
+
>> 1.0.0-81aca04e-dirty
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
If you commit changes to the repository, the version just shows the commit indicating a new version of the component
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
git-release-tag show
|
|
61
|
+
>> 1.0.0-63a8d99
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## bumping the version
|
|
66
|
+
If you want to release the latest commit as a new version, type:
|
|
67
|
+
```bash
|
|
68
|
+
git-release-tag bump --level patch
|
|
69
|
+
>> INFO: commit changes to .release in .
|
|
70
|
+
>> INFO: release 1.0.1 of . tagged by v1.0.1
|
|
71
|
+
```
|
|
72
|
+
If there are no changes since the last version. bump with not change anything:
|
|
73
|
+
```bash
|
|
74
|
+
git-release-tag bump --level patch
|
|
75
|
+
>>INFO: . has no changes since 1.1.1.
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## multiple components in a single repository
|
|
79
|
+
If you have multiple components in a single repository, initialize the repository as follows:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
git-release-tag initialize --initial-release 1.0.0 ui backend .
|
|
83
|
+
>> INFO: commit changes to .release in ui
|
|
84
|
+
>> INFO: release 1.0.0 of ui tagged by ui-1.0.0
|
|
85
|
+
>> INFO: commit changes to .release in backend
|
|
86
|
+
>> INFO: release 1.0.0 of backend tagged by backend-1.0.0
|
|
87
|
+
>> INFO: commit changes to .release in .
|
|
88
|
+
>> INFO: release 1.0.0 of . tagged by api-1.0.0
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
When you want to release a new version of the component, type:
|
|
92
|
+
```bash
|
|
93
|
+
git-release-tag bump --recursive --level patch .
|
|
94
|
+
>> INFO: commit changes to .release in ./ui
|
|
95
|
+
>> INFO: release 1.0.1 of ./ui tagged by ui-1.0.1
|
|
96
|
+
>> INFO: ./backend has no changes since 1.0.0.
|
|
97
|
+
>> INFO: commit changes to .release in .
|
|
98
|
+
>> INFO: release 1.0.1 of . tagged by api-1.0.1
|
|
99
|
+
```
|
|
100
|
+
As you can see, the ui now has version 1.0.1, the backend version is unchanged and the application
|
|
101
|
+
has bumped to 1.0.1 too, because of the changes to the ui.
|
|
102
|
+
|
|
103
|
+
## dependencies between multiple components in a single repository
|
|
104
|
+
When you need to bump the version of a component when there are changes in other components in the
|
|
105
|
+
same repository, specify the dependency in the field `tag_on_changes_in` in the .release file.
|
|
106
|
+
|
|
107
|
+
So let's say that the UI always has to change when the api changes, change the .release as follows:
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
release=1.0.1
|
|
111
|
+
tag=ui-1.0.1
|
|
112
|
+
tag_on_changes_in=../api
|
|
113
|
+
```
|
|
114
|
+
Now, when there are changes in the ../api directory with respect to the tag in the ui directory,
|
|
115
|
+
a new release will be created.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
## validating your configuration
|
|
119
|
+
As tags are not part of the commit, it sometimes happens that somebody forgets to push the tags along with the
|
|
120
|
+
commits. To validate the integrity of your release configuration, type:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
git-release-tag validate --recursive .
|
|
124
|
+
>> INFO: ok
|
|
125
|
+
```
|
|
126
|
+
It reports an error if the configuration:
|
|
127
|
+
- references tags which are not in the repository.
|
|
128
|
+
- use the same tag for different components.
|
|
129
|
+
|
|
130
|
+
## including the current version in your application
|
|
131
|
+
To include the version of the release in the source code you can add a pre-tag-command to your configuration. This
|
|
132
|
+
is a command that is executed before the changes are committed.
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
git-release-tag initialize \
|
|
136
|
+
--initial-release 1.0.0 \
|
|
137
|
+
--tag-prefix v \
|
|
138
|
+
--pre-tag-command 'sed -i "" -e "s/^version = .*/version = \"@@RELEASE@@\"/g" pyproject.toml' \
|
|
139
|
+
.
|
|
140
|
+
>> INFO: commit changes to .release, pyproject.toml in .
|
|
141
|
+
>> INFO: release 1.0.0 of . tagged by v1.0.0
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The content of pyproject.toml now reflects the released version and is included in the commit:
|
|
145
|
+
```bash
|
|
146
|
+
grep ^version pyproject.toml
|
|
147
|
+
>> version = "1.0.0"
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## installing the utility
|
|
151
|
+
To install the utility, type:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
pip install git-release-tag # or: uv tool install git-release-tag
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## inspired by native git describe
|
|
158
|
+
If you use a single git repository for each deliverable that you produce in the build process, you may use
|
|
159
|
+
`git-describe` instead. How does it work? Well you create a tag on a particular commit, and then type:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
git tag 1.0.0
|
|
163
|
+
git describe --tags --dirty
|
|
164
|
+
>> 1.0.0
|
|
165
|
+
```
|
|
166
|
+
If you add something to the repository, it will append the number of commits since the tag and first 8 digits of the
|
|
167
|
+
revision number:
|
|
168
|
+
```bash
|
|
169
|
+
git describe --tags --dirty
|
|
170
|
+
>> 1.0.0-1-g6123dd2
|
|
171
|
+
```
|
|
172
|
+
If you have uncommited changes in the staging area, it will append `dirty` to it:
|
|
173
|
+
```bash
|
|
174
|
+
git describe --tags --dirty
|
|
175
|
+
>> 1.0.0-1-g6123dd2-dirty
|
|
176
|
+
```
|
|
177
|
+
If you commit your changes and place a new tag it show a clean tag again. git-describe does not work for the situation
|
|
178
|
+
where you have multiple artifacts in a single repository.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
git_release_tag/__init__.py,sha256=vBM3LIkiqpkGzHueLhKGpSgSsNJWW0XTMzQDuaf22jg,16
|
|
2
|
+
git_release_tag/__main__.py,sha256=5ugWBRy-ovG5lPqi_FFjShQtRkZc-tCfhOfwKYD_1pU,6893
|
|
3
|
+
git_release_tag/click_parameter_types.py,sha256=VcRgX0riiw4He_EpqonO9dhrSJUvn7uJ_xsqgbMr9m0,2032
|
|
4
|
+
git_release_tag/git.py,sha256=Wxj67c8dU_6WYzg9-RfDo7jy1XV9j_FruVq7F35p2qI,887
|
|
5
|
+
git_release_tag/logger.py,sha256=1dOModbv8dzzyaUlQYstVSmbwEGa6nz5e3ikm7NdLP4,253
|
|
6
|
+
git_release_tag/release_info.py,sha256=LXSalliXrz1PkTYDI7WI7cwmL0uRVzWuMWVHWEBtl60,17295
|
|
7
|
+
git_release_tag-0.8.1.dist-info/licenses/LICENSE,sha256=IiV49ofQoxZKb836Tv2lu-jAzPLm26mJbcOQEeYeoL0,11342
|
|
8
|
+
git_release_tag-0.8.1.dist-info/METADATA,sha256=4y2Nog2d6-lOSbqfMhLIaZQubQOY0dnqOXkyfRvFvrQ,6351
|
|
9
|
+
git_release_tag-0.8.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
10
|
+
git_release_tag-0.8.1.dist-info/entry_points.txt,sha256=Fsk6oP09aK81hrgB50YHuRuE_FAg3VRImtJEUTGIRj0,66
|
|
11
|
+
git_release_tag-0.8.1.dist-info/top_level.txt,sha256=vlPnjFXC7jtu7BwPRIv2aaODr0KxQ1dk1yZfnNYZ2nM,16
|
|
12
|
+
git_release_tag-0.8.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2020 binx.io B.V.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
git_release_tag
|