Skip to content

Commit

Permalink
Improved use of semver
Browse files Browse the repository at this point in the history
This changes the use of git describe to generate (v-prefixed) semver versions, moving the build information to a + block. It also enhances the version parsing in ota to more closely match semver.
  • Loading branch information
MatthewWilkes authored and thinkl33t committed Jun 19, 2024
1 parent 63569c2 commit 6c2564a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
7 changes: 5 additions & 2 deletions components/st3m/host-tools/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
def get_git_based_version():
root = os.environ.get('GITHUB_WORKSPACE', '/firmware')
os.chdir(root)
return subprocess.check_output(
version = subprocess.check_output(
["git", "describe", "--tags", "--always"]
).decode().strip()

if '-' in version:
version = version.replace("-", "+", 1)
version = version.replace("-", ".")
return version

fmt = None
if len(sys.argv) > 1:
Expand Down
45 changes: 27 additions & 18 deletions modules/system/ota/ota.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@


def parse_version(version):
pre_components = ["final"]
build_components = ["0", "000000z"]
build = ""
components = []
if "+" in version:
version, build = version.split("+", 1)
build_components = build.split(".")
if "-" in version:
version, ahead, _ = version.split("-")
ahead = int(ahead)
else:
ahead = 0
version, pre_release = version.split("-", 1)
if pre_release.startswith("rc"):
# Re-write rc as c, to support a1, b1, rc1, final ordering
pre_release = pre_release[1:]
pre_components = pre_release.split(".")
version = version.strip("v").split(".")
major, minor, patch = version
if "rc" in patch:
patch, rc = patch.split("rc")
patch = int(patch) - 1
patch = patch + float(rc) / 10
else:
patch = int(patch)
major = int(major)
minor = int(minor)
patch = float(patch)
return major, minor, patch, ahead
components = [int(item) if item.isdigit() else item for item in version]
components.append(
[int(item) if item.isdigit() else item for item in pre_components]
)
components.append(
[int(item) if item.isdigit() else item for item in build_components]
)
return components


class OtaUpdate(App):
Expand Down Expand Up @@ -202,9 +207,13 @@ def progress(self, version, val):
if not self.confirmed:
if len(version) > 0:
self.new_version.value = version
if parse_version(version) <= parse_version(ota.get_version()):
self.status.value = "No update needed"
return False
try:
if parse_version(version) <= parse_version(ota.get_version()):
self.status.value = "No update needed"
return False
except Exception:
# Any problems parsing or getting version, allow the update
pass

print("New version:")
print(version)
Expand Down
2 changes: 1 addition & 1 deletion tildagon/mpconfigboard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ file(
BASE_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
)
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags --always
COMMAND "python" "components/st3m/host-tools/version.py"
WORKING_DIRECTORY "${FIRMWARE_ROOT}"
RESULT_VARIABLE res
OUTPUT_VARIABLE TILDAGON_GIT_VERSION
Expand Down

0 comments on commit 6c2564a

Please sign in to comment.