Skip to content

Commit c2b76a9

Browse files
MatthewWilkesthinkl33t
authored andcommitted
Fix marking build version segments when there's a pre-release segment
1 parent 1e47239 commit c2b76a9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

components/st3m/host-tools/version.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import subprocess
1212
import sys
1313
import os
14+
import re
1415

1516

1617
def get_git_based_version():
@@ -19,9 +20,14 @@ def get_git_based_version():
1920
version = subprocess.check_output(
2021
["git", "describe", "--tags", "--always"]
2122
).decode().strip()
22-
if '-' in version:
23-
version = version.replace("-", "+", 1)
24-
version = version.replace("-", ".")
23+
commit_hash = subprocess.check_output(
24+
["git", "describe", "--always"]
25+
).decode().strip()
26+
if version.endswith(commit_hash):
27+
build_info = re.compile(f"\-(\d+)\-(.*?{re.escape(commit_hash)})").findall(version)
28+
if build_info:
29+
ahead, commit_hash = build_info[0]
30+
version = version.replace(f"-{ahead}-{commit_hash}", f"+{ahead}.{commit_hash}", 1)
2531
return version
2632

2733
fmt = None

0 commit comments

Comments
 (0)