-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcmd_git_semver.py
executable file
·76 lines (66 loc) · 2.59 KB
/
cmd_git_semver.py
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
#!/usr/bin/env python3
# Copyright 2013 Tomo Krajina
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import argparse
from . import git
from . import semver
from typing import *
git.assert_in_git_repository()
parser = argparse.ArgumentParser(description='List / update semver tags')
parser.add_argument('--major', action='store_true', default=False, help='Increase major version')
parser.add_argument('--minor', action='store_true', default=False, help='Increase minor version')
parser.add_argument('--patch', action='store_true', default=False, help='Increase patch version')
parser.add_argument('--suffix', type=str, default="", help='Suffix (for example v1.2.3-suffix)')
args = parser.parse_args()
incr_major: bool = args.major
incr_minor: bool = args.minor
incr_patch: bool = args.patch
suffix: str = args.suffix
versions = semver.get_all_versions_ordered(output_non_versions=True)
max_version = versions[-1] if versions else semver.Version("v0.0.0", "v", 0, 0, 0, "")
if not versions:
print("No tags")
sys.exit(0)
if incr_major or incr_minor or incr_patch:
if incr_patch:
max_version.patch += 1
if incr_minor:
max_version.minor += 1
max_version.patch = 0
if incr_major:
max_version.major += 1
max_version.minor = 0
max_version.patch = 0
new_tag = f'{max_version.prefix}{max_version.major}.{max_version.minor}.{max_version.patch}'
if suffix:
new_tag += "-" + suffix
print(f"Creating new version/tag: {new_tag}")
success, output = git.execute_git(f"tag {new_tag}")
if not success:
print(f'Error creating tag: {output}')
sys.exit(1)
print(f'Tag {new_tag} created, you can push it now')
else:
for n, version in enumerate(versions):
if n > 0:
previous_ver = versions[n-1]
if previous_ver.major != version.major:
print(f"New major: {version.major}")
if previous_ver.minor != version.minor:
print(f"New minor: {version.major}.{version.minor}")
print(f" * {version.tag}")
print()
print(f"Last version: {max_version.tag}")
print()