-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathgit_tag_macro.py
More file actions
31 lines (27 loc) · 741 Bytes
/
git_tag_macro.py
File metadata and controls
31 lines (27 loc) · 741 Bytes
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
import subprocess
subprocess.run(["git", "fetch", "--unshallow"])
branch = (
subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"])
.strip()
.decode("utf-8")
)
#try:
# subprocess.check_call(["git", "describe", "--tags"])
#except:
# tag = (
# subprocess.check_output(["git", "describe", "--abbrev=0" "--tags"])
# .strip()
# .decode("utf-8")
# )
#else:
tag = (
subprocess.check_output(["git", "describe", "--tags", "--always"])
.strip()
.decode("utf-8")
)
if branch != "master":
tag_parts = tag.split("-")
tag = "%s-%s" % (tag_parts[0], branch)
if len(tag_parts) > 1:
tag = "%s-%s" % (tag, "-".join(tag_parts[1:]))
print("-DFIRMWARE_VERSION='\"%s\"'" % tag)