2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-01-10 21:28:01 +00:00

Matmair/issue10740 (#497)

* reduce noise in docker

* refactor path infos

* add more info during local frontend build

* add frontend info during release build
This commit is contained in:
Matthias Mair
2025-12-26 16:46:49 +01:00
committed by GitHub
parent 97dd664073
commit 415c52813b
3 changed files with 59 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
"""Tasks for automating certain actions and interacting with InvenTree from the CLI."""
import datetime
import json
import os
import pathlib
@@ -357,6 +358,26 @@ def manage_py_path():
return manage_py_dir().joinpath('manage.py')
def _frontend_info():
"""Return the path of the frontend info directory."""
return manage_py_dir().joinpath('web', 'static', 'web', '.vite')
def version_target_pth():
"""Return the path of the target version file."""
return _frontend_info().joinpath('tag.txt')
def version_sha_pth():
"""Return the path of the SHA version file."""
return _frontend_info().joinpath('sha.txt')
def version_source_pth():
"""Return the path of the source version file."""
return _frontend_info().joinpath('source.txt')
# endregion
if __name__ in ['__main__', 'tasks']:
@@ -1664,6 +1685,31 @@ def frontend_build(c):
info('Building frontend')
yarn(c, 'yarn run build')
def write_info(path: Path, content: str):
"""Helper function to write version content to file after cleaning it if it exists."""
if path.exists():
path.unlink()
path.write_text(content, encoding='utf-8')
# Write version marker
try:
import src.backend.InvenTree.InvenTree.version as InvenTreeVersion
if version_hash := InvenTreeVersion.inventreeCommitHash():
write_info(version_sha_pth(), version_hash)
elif version_tag := InvenTreeVersion.inventreeVersion():
write_info(version_target_pth(), version_tag)
else:
warning('No version information available to write frontend version marker')
# Write source marker
write_info(
version_source_pth(),
f'local build on {datetime.datetime.now().isoformat()}',
)
except Exception:
warning('Failed to write frontend version marker')
@task
def frontend_server(c):
@@ -1788,13 +1834,9 @@ def frontend_download(
ref = 'tag' if tag else 'commit'
if tag:
current = manage_py_dir().joinpath(
'web', 'static', 'web', '.vite', 'tag.txt'
)
current = version_target_pth()
elif sha:
current = manage_py_dir().joinpath(
'web', 'static', 'web', '.vite', 'sha.txt'
)
current = version_sha_pth()
else:
raise ValueError('Either tag or sha needs to be set')