Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions src/backend/InvenTree/InvenTree/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
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
Expand All @@ -22,6 +24,7 @@

logger = logging.getLogger('inventree')

git_warning_txt = 'INVE-W3: Could not detect git information.'

# Discover git
try:
Expand All @@ -33,8 +36,11 @@
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(git_warning_txt)
else:
logger.warning(git_warning_txt)
main_repo = None
main_commit = None

Expand All @@ -51,7 +57,7 @@
main_commit = None
main_branch = None
except Exception as exc:
logger.warning('INVE-W3: Could not detect git information.', exc_info=exc)
logger.warning(git_warning_txt, exc_info=exc)
main_repo = None
main_commit = None
main_branch = None
Expand Down
54 changes: 48 additions & 6 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tasks for automating certain actions and interacting with InvenTree from the CLI."""

import datetime
import json
import os
import pathlib
Expand Down Expand Up @@ -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']:
Expand Down Expand Up @@ -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 # type: ignore[import]

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):
Expand Down Expand Up @@ -1788,13 +1834,9 @@ def check_already_current(tag=None, sha=None):
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')

Expand Down
Loading