-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-git
More file actions
executable file
·44 lines (33 loc) · 1.26 KB
/
check-git
File metadata and controls
executable file
·44 lines (33 loc) · 1.26 KB
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
#!/usr/bin/env python
# Looks at the local git working copy and determines…
# - Whether this is a release branch: creates `release_build` (empty) if it is
# - What tag should be assigned to the build: creates `build_tag` containing the tag
from operator import contains
import re
import subprocess
import os
import os.path
def write(name, str):
f = open(name, 'w')
f.write(str)
f.close()
def clean_files():
for name in ['release_build', 'build_tag']:
if os.path.isfile(name):
os.remove(name)
# '1.1.3-4-g2c1a80f'
git_describe = subprocess.check_output('git describe --tags',
shell=True).decode("utf-8").rstrip()
# 'master', 'HEAD', ...
git_branch = subprocess.check_output('git rev-parse --abbrev-ref HEAD',
shell=True).decode("utf-8").rstrip()
print(git_describe)
print(git_branch)
# We either a) are @ a tag, in which case we have a release build under us
# b) are somewhere post a tag, in which case no release must be made
clean_files()
# Might this be a release branch/tag? If so, touch the file `release_build`
possible_release_branch = contains(['master', 'HEAD'], git_branch)
if re.match('^\d{1,}\.\d{1,}\.\d{1,}$', git_describe) and possible_release_branch:
write('release_build', '')
write('build_tag', git_describe)