forked from dagster-io/dagster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_tag.py
70 lines (60 loc) · 2.22 KB
/
git_tag.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
import re
import subprocess
def get_git_tag():
try:
git_tag = str(
subprocess.check_output(
['git', 'describe', '--exact-match', '--abbrev=0'], stderr=subprocess.STDOUT
)
).strip('\'b\\n')
except subprocess.CalledProcessError as exc_info:
match = re.search(
'fatal: no tag exactly matches \'(?P<commit>[a-z0-9]+)\'', str(exc_info.output)
)
if match:
raise Exception(
'Bailing: there is no git tag for the current commit, {commit}'.format(
commit=match.group('commit')
)
)
raise Exception(str(exc_info.output))
return git_tag
def get_most_recent_git_tag():
try:
git_tag = str(
subprocess.check_output(['git', 'describe', '--abbrev=0'], stderr=subprocess.STDOUT)
).strip('\'b\\n')
except subprocess.CalledProcessError as exc_info:
raise Exception(str(exc_info.output))
return git_tag
def set_git_tag(tag, signed=False, dry_run=True):
try:
if signed:
if not dry_run:
subprocess.check_output(
['git', 'tag', '-s', '-m', tag, tag], stderr=subprocess.STDOUT
)
else:
if not dry_run:
subprocess.check_output(
['git', 'tag', '-a', '-m', tag, tag], stderr=subprocess.STDOUT
)
except subprocess.CalledProcessError as exc_info:
match = re.search('error: gpg failed to sign the data', str(exc_info.output))
if match:
raise Exception(
'Bailing: cannot sign tag. You may find '
'https://stackoverflow.com/q/39494631/324449 helpful. Original error '
'output:\n{output}'.format(output=str(exc_info.output))
)
match = re.search(
r'fatal: tag \'(?P<tag>[\.a-z0-9]+)\' already exists', str(exc_info.output)
)
if match:
raise Exception(
'Bailing: cannot release version tag {tag}: already exists'.format(
tag=match.group('tag')
)
)
raise Exception(str(exc_info.output))
return tag