Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion to update BUILD_VERSION policy #1733

Merged
merged 12 commits into from
Jul 9, 2023
48 changes: 43 additions & 5 deletions Translations/make_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,18 +1263,56 @@ def get_translation_sanity_checks_text(defs: dict) -> str:
return sanity_checks_text


def get_version_suffix(ver) -> str:
suffix = str("")
try:
# Use commands _hoping_ they won't be too new for one environments nor deprecated for another ones:
## - get commit id; --short=7 - the shorted hash with 7 digits (increase/decrease if needed!)
sha_id = f"{subprocess.check_output(['git', 'rev-parse', '--short=8', 'HEAD']).strip().decode('ascii').upper()}"
## - if the exact commit relates to tag, then this command should return one-line tag name:
tag = f"{subprocess.check_output(['git', 'tag', '--points-at', '%s' % sha_id]).strip().decode('ascii')}"
## - get short "traditional" branch name (as in `git branch` for that one with asterisk):
branch = f"{subprocess.check_output(['git', 'symbolic-ref', '--short', 'HEAD']).strip().decode('ascii')}"
if tag and "" != tag:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably such kind of extra checks is too much but since we work with strings I thought it's better to double-check (not sure it makes sense in Python though).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it has no runtime cost, check as much as possible is my personal belief :)

# _Speculate_ on tag that it's Release...
if ver == tag:
# ... but only if double-check for tag is matched
suffix = "R"
else:
# ... otherwise it's tagged but not a release version!
suffix = "T"
elif branch and "" != branch:
# _Hardcoded_ current main development branch...
if "dev" == branch:
suffix = "D"
# ... or some other branch
else:
suffix = "B"
else:
# Something else but from Git
suffix = "G"
# Attach SHA commit to ID a build since it's from git anyway
suffix += "." + sha_id
except subprocess.CalledProcessError:
# No git tree so _probably_ Homebrew build from source
suffix = "H"
except OSError:
# Something _special_?
suffix = "S"
if "" == suffix:
# Something _very_ special!
suffix = "V"
return suffix


def read_version() -> str:
with open(HERE.parent / "source" / "version.h") as version_file:
for line in version_file:
if re.findall(r"^.*(?<=(#define)).*(?<=(BUILD_VERSION))", line):
matches = re.findall(r"\"(.+?)\"", line)
if matches:
version = matches[0]
try:
version += f".{subprocess.check_output(['git', 'rev-parse', '--short=7', 'HEAD']).strip().decode('ascii').upper()}"
# --short=7: the shorted hash with 7 digits. Increase/decrease if needed!
except OSError:
version += " git"
version += get_version_suffix(version)
return version


Expand Down
25 changes: 21 additions & 4 deletions source/version.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
/**
* Firmware build version - format: xx.yy.zzzzzz
* x: Major - y: Minor - z: git short hash generated automaticaly from git
* i.e.: BUILD_VERSION = 'Rel. v2.08' --> Will generated to: 'v2.08.1a2b3c4'
* Firmware build version - format: xx.yy+[.zzzzzzz]
*
* x: major version
* y: minor version
* +: build type:
* * R - git-related release tag vXX.YY
* * T - git-related release tag but version is not vXX.YY !
* * D - git-related dev branch
* * B - git-related custom branch
* * G - neither above but git-related
* * H - build outside of a git tree (i.e. release tarball)
* * S - something special (should not happen?)
* * V - something very special (should not happen!)
* z: short commit ID hash generated automaticaly from git
* * (for git-related build types only)
*
* i.e.:
* * BUILD_VERSION = 'v2.22' -> from tarball: 'v2.22H'
* * BUILD_VERSION = 'v2.22' -> from git dev branch: 'v2.22D.1A2B3C4D'
* * BUILD_VERSION = 'v2.22' -> from stable git release: 'v2.22R.5E6F7G8H'
*/

#define BUILD_VERSION "v2.21"
#define BUILD_VERSION "v2.22"