-
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathgit_tag_macro.py
More file actions
28 lines (23 loc) · 806 Bytes
/
Copy pathgit_tag_macro.py
File metadata and controls
28 lines (23 loc) · 806 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
import os
import subprocess
tag = os.environ.get("SS2K_FIRMWARE_VERSION")
if os.environ.get("GITHUB_ACTIONS") == "true" and not tag:
raise RuntimeError("SS2K_FIRMWARE_VERSION must be set for GitHub Actions builds")
if not tag:
subprocess.run(["git", "fetch", "--unshallow"])
branch = (
subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"])
.strip()
.decode("utf-8")
)
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)