2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-01-09 04:38:00 +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 run: cd src/backend/InvenTree/web/static/web/.vite && echo "${REF_NAME}" > tag.txt
env: env:
REF_NAME: ${{ github.ref_name }} 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 - name: Zip frontend
run: | run: |
cd src/backend/InvenTree/web/static/web cd src/backend/InvenTree/web/static/web

View File

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

View File

@@ -1,5 +1,6 @@
"""Tasks for automating certain actions and interacting with InvenTree from the CLI.""" """Tasks for automating certain actions and interacting with InvenTree from the CLI."""
import datetime
import json import json
import os import os
import pathlib import pathlib
@@ -357,6 +358,26 @@ def manage_py_path():
return manage_py_dir().joinpath('manage.py') 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 # endregion
if __name__ in ['__main__', 'tasks']: if __name__ in ['__main__', 'tasks']:
@@ -1664,6 +1685,31 @@ def frontend_build(c):
info('Building frontend') info('Building frontend')
yarn(c, 'yarn run build') 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 @task
def frontend_server(c): def frontend_server(c):
@@ -1788,13 +1834,9 @@ def frontend_download(
ref = 'tag' if tag else 'commit' ref = 'tag' if tag else 'commit'
if tag: if tag:
current = manage_py_dir().joinpath( current = version_target_pth()
'web', 'static', 'web', '.vite', 'tag.txt'
)
elif sha: elif sha:
current = manage_py_dir().joinpath( current = version_sha_pth()
'web', 'static', 'web', '.vite', 'sha.txt'
)
else: else:
raise ValueError('Either tag or sha needs to be set') raise ValueError('Either tag or sha needs to be set')