2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-01-08 12:17:57 +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

@@ -65,6 +65,8 @@ jobs:
run: cd src/backend/InvenTree/web/static/web/.vite && echo "${REF_NAME}" > tag.txt
env:
REF_NAME: ${{ github.ref_name }}
- name: Write version file - SOURCE
run: cd src/backend/InvenTree/web/static/web/.vite && echo "GitHub Actions build on $(date --utc +%Y-%m-%dT%H:%M:%SZ)" > source.txt
- name: Zip frontend
run: |
cd src/backend/InvenTree/web/static/web

View File

@@ -12,6 +12,8 @@ import sys
from datetime import datetime as dt
from datetime import timedelta as td
from django.conf import settings
from .api_version import INVENTREE_API_TEXT, INVENTREE_API_VERSION
# InvenTree software version
@@ -22,6 +24,7 @@ MIN_PYTHON_VERSION = (3, 11)
logger = logging.getLogger('inventree')
warning_txt = 'INVE-W3: Could not detect git information.'
# Discover git
try:
@@ -33,8 +36,11 @@ try:
main_repo = Repo(pathlib.Path(__file__).parent.parent.parent.parent.parent)
main_commit = main_repo[main_repo.head()]
except NotGitRepository:
# If we are running in a docker container, the repo may not be available
logger.warning('INVE-W3: Could not detect git information.')
# If we are running in a docker container, the repo may not be available, only logging as warning if not in docker
if settings.DOCKER:
logger.info(warning_txt)
else:
logger.warning(warning_txt)
main_repo = None
main_commit = None
@@ -51,7 +57,7 @@ except ImportError:
main_commit = None
main_branch = None
except Exception as exc:
logger.warning('INVE-W3: Could not detect git information.', exc_info=exc)
logger.warning(warning_txt, exc_info=exc)
main_repo = None
main_commit = None
main_branch = None

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')