Version file added dynamically (workaround as uv does not have this feature yet)
All checks were successful
/ test (push) Successful in 17s
/ build (push) Successful in 19s

Tag container image with playbook
Importable module with python -m treetrail
This commit is contained in:
phil 2024-11-04 03:58:58 +01:00
parent 2d0b788728
commit 1693662e75
11 changed files with 66 additions and 29 deletions

View file

@ -84,3 +84,28 @@ def mkdir(dir: Path | str) -> Path:
logger.info(f'Create directory {path}')
path.mkdir(parents=True, exist_ok=True)
return path
def get_version() -> str:
version_file_src = Path(__file__).parent / 'version.txt'
version_file_in_container = Path("/app") / 'version.txt'
if version_file_src.exists():
with open(version_file_src) as version:
return version.read().strip()
if version_file_in_container.exists():
with open(version_file_in_container) as version:
return version.read().strip()
else:
logger.debug('No version file, using git')
try:
from subprocess import run
git_version_cmd = run(['git', 'describe', '--broken', '--tags', '--always', '--dirty'],
capture_output=True)
if git_version_cmd.returncode == 0:
return git_version_cmd.stdout.strip().decode()
else:
logger.debug('git returns with the error below, version set as 0.0.0')
logger.debug(git_version_cmd.stderr.decode())
return '0.0.0'
except FileNotFoundError as err:
logger.debug('git not found: version set as 0.0.0')
return '0.0.0'