forked from wayne-love/ESPySpa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_version.py
More file actions
43 lines (38 loc) · 1.69 KB
/
get_version.py
File metadata and controls
43 lines (38 loc) · 1.69 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
import subprocess
from datetime import datetime
from SCons.Script import Import
Import("env")
def get_git_version():
try:
# Check if the current commit is exactly on a tag
version = subprocess.check_output(
["git", "describe", "--tags", "--exact-match"],
stderr=subprocess.DEVNULL
).strip().decode("utf-8")
except subprocess.CalledProcessError:
try:
# If no exact match, get the latest tag with commit info
version = subprocess.check_output(
["git", "describe", "--tags", "--always"],
stderr=subprocess.DEVNULL
).strip().decode("utf-8")
# Append "-nightly" and date to indicate it's not an exact tag
version += f"-nightly-{datetime.now().strftime('%Y-%m-%d')}"
except subprocess.CalledProcessError:
try:
# If no tags exist, get the short commit hash
version = subprocess.check_output(
["git", "rev-parse", "--short", "HEAD"],
stderr=subprocess.DEVNULL
).strip().decode("utf-8")
version += f"-nightly-{datetime.now().strftime('%Y-%m-%d')}"
except subprocess.CalledProcessError:
version = f"unknown-{datetime.now().strftime('%Y-%m-%d')}" # fallback if git fails entirely
return version
build_info = get_git_version()
# Append the version to build flags
env.Append(CPPDEFINES=[("BUILD_INFO", f'"{build_info}"')])
env.Append(CPPDEFINES=[("PIOENV", f'"{env["PIOENV"]}"')])
# Output the values to the console
print(f"BUILD_INFO: {build_info}")
print(f"PIOENV: {env['PIOENV']}")