|
1 | 1 | """Tasks for automating certain actions and interacting with InvenTree from the CLI.""" |
2 | 2 |
|
| 3 | +import datetime |
3 | 4 | import json |
4 | 5 | import os |
5 | 6 | import pathlib |
@@ -357,6 +358,26 @@ def manage_py_path(): |
357 | 358 | return manage_py_dir().joinpath('manage.py') |
358 | 359 |
|
359 | 360 |
|
| 361 | +def _frontend_info(): |
| 362 | + """Return the path of the frontend info directory.""" |
| 363 | + return manage_py_dir().joinpath('web', 'static', 'web', '.vite') |
| 364 | + |
| 365 | + |
| 366 | +def version_target_pth(): |
| 367 | + """Return the path of the target version file.""" |
| 368 | + return _frontend_info().joinpath('tag.txt') |
| 369 | + |
| 370 | + |
| 371 | +def version_sha_pth(): |
| 372 | + """Return the path of the SHA version file.""" |
| 373 | + return _frontend_info().joinpath('sha.txt') |
| 374 | + |
| 375 | + |
| 376 | +def version_source_pth(): |
| 377 | + """Return the path of the source version file.""" |
| 378 | + return _frontend_info().joinpath('source.txt') |
| 379 | + |
| 380 | + |
360 | 381 | # endregion |
361 | 382 |
|
362 | 383 | if __name__ in ['__main__', 'tasks']: |
@@ -1664,6 +1685,31 @@ def frontend_build(c): |
1664 | 1685 | info('Building frontend') |
1665 | 1686 | yarn(c, 'yarn run build') |
1666 | 1687 |
|
| 1688 | + def write_info(path: Path, content: str): |
| 1689 | + """Helper function to write version content to file after cleaning it if it exists.""" |
| 1690 | + if path.exists(): |
| 1691 | + path.unlink() |
| 1692 | + path.write_text(content, encoding='utf-8') |
| 1693 | + |
| 1694 | + # Write version marker |
| 1695 | + try: |
| 1696 | + import src.backend.InvenTree.InvenTree.version as InvenTreeVersion # type: ignore[import] |
| 1697 | + |
| 1698 | + if version_hash := InvenTreeVersion.inventreeCommitHash(): |
| 1699 | + write_info(version_sha_pth(), version_hash) |
| 1700 | + elif version_tag := InvenTreeVersion.inventreeVersion(): |
| 1701 | + write_info(version_target_pth(), version_tag) |
| 1702 | + else: |
| 1703 | + warning('No version information available to write frontend version marker') |
| 1704 | + |
| 1705 | + # Write source marker |
| 1706 | + write_info( |
| 1707 | + version_source_pth(), |
| 1708 | + f'local build on {datetime.datetime.now().isoformat()}', |
| 1709 | + ) |
| 1710 | + except Exception: |
| 1711 | + warning('Failed to write frontend version marker') |
| 1712 | + |
1667 | 1713 |
|
1668 | 1714 | @task |
1669 | 1715 | def frontend_server(c): |
@@ -1788,13 +1834,9 @@ def check_already_current(tag=None, sha=None): |
1788 | 1834 | ref = 'tag' if tag else 'commit' |
1789 | 1835 |
|
1790 | 1836 | if tag: |
1791 | | - current = manage_py_dir().joinpath( |
1792 | | - 'web', 'static', 'web', '.vite', 'tag.txt' |
1793 | | - ) |
| 1837 | + current = version_target_pth() |
1794 | 1838 | elif sha: |
1795 | | - current = manage_py_dir().joinpath( |
1796 | | - 'web', 'static', 'web', '.vite', 'sha.txt' |
1797 | | - ) |
| 1839 | + current = version_sha_pth() |
1798 | 1840 | else: |
1799 | 1841 | raise ValueError('Either tag or sha needs to be set') |
1800 | 1842 |
|
|
0 commit comments