Skip to content

Commit

Permalink
Fix build system exception
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Oct 8, 2024
1 parent 20914f5 commit 14efa86
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions scripts/embed_env_vars.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Mapping
from utils import pioenv, sysenv, dotenv, shorthands
import git
import re

# This file is invoked by PlatformIO during build.
# See 'extra_scripts' in 'platformio.ini'.
Expand Down Expand Up @@ -41,9 +42,10 @@ def get_git_repo():
except git.exc.InvalidGitRepositoryError:
return None

import re

def sort_semver(versions):
if not versions or len(versions) == 0:
return []

def parse_semver(v):
# Split version into main, prerelease, and build metadata parts
match = re.match(r'^v?(\d+(?:\.\d+)*)(?:-([0-9A-Za-z-.]+))?(?:\+([0-9A-Za-z-.]+))?$', v)
Expand All @@ -67,10 +69,13 @@ def version_key(version):
# Sort by version key
return sorted(clean_only, key=lambda v: version_key(v))

def last_element(arr):
return arr[-1] if len(arr) > 0 else None

git_repo = get_git_repo()
git_commit = git_repo.head.object.hexsha if git_repo is not None else None
git_tags = [tag.name for tag in git_repo.tags] if git_repo is not None else []
latest_git_tag = sort_semver(git_tags)[-1] if len(git_tags) > 0 else None
git_latest_clean_tag = last_element(sort_semver(git_tags))

# Find env variables based on only the pioenv and sysenv.
def get_pio_firmware_vars() -> dict[str, str | int | bool]:
Expand Down Expand Up @@ -188,7 +193,7 @@ def print_dump(name: str, map: Mapping[str, str | int | bool]) -> None:
raise ValueError('OPENSHOCK_FW_VERSION must be set in environment variables for CI builds.')

# If latest_git_tag is set, use it, else use 0.0.0, assign to variable.
version = (latest_git_tag if latest_git_tag is not None else '0.0.0') + '-local'
version = (git_latest_clean_tag if git_latest_clean_tag is not None else '0.0.0') + '-local'

# If git_commit is set, append it to the version.
if git_commit is not None:
Expand Down

0 comments on commit 14efa86

Please sign in to comment.