2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-13 18:45:40 +00:00

Optimize PUI package delivery for package installs (#7655)

* Package frontend in deb

* Add artifact download

* remove 0.8.0 check

* remove array casting

* fix format once more

* another try

* add brackets again

* add version

* and bash

* and shell

* more debuging

* various style fixes

* small fixes

* and ls for prosperity

* debug

* maybe git as source?

* fix download cmd?

* debug a bit

* debug a bit more

* remove sha download - is not working with GHA restrictions

* write version number

* check if a new frontend must be dowloaded

* write versions into frontend packages

* Matmair/issue7338 (#205)

* Package frontend in deb

* Add artifact download

* remove 0.8.0 check

* remove array casting

* fix format once more

* another try

* add brackets again

* add version

* and bash

* and shell

* more debuging

* various style fixes

* small fixes

* and ls for prosperity

* debug

* maybe git as source?

* fix download cmd?

* debug a bit

* debug a bit more

* remove sha download - is not working with GHA restrictions

* write version number

* check if a new frontend must be dowloaded

* write versions into frontend packages

* change ref dir for tests

* add better build logging

* extend task to get ref from package

* fix downloading syntax

* fix name ref

* make more robust

* more logging

* move import

* turn down unzipping noise

* strip content (spaces, newlines)

* add info what happens now

* fix quite flag

* adjust publisher
This commit is contained in:
Matthias Mair
2024-07-18 07:35:09 +02:00
committed by GitHub
parent c6d310caf7
commit 105dd7152e
4 changed files with 93 additions and 14 deletions

View File

@ -1272,6 +1272,34 @@ def frontend_download(
handle_extract(dst.name)
def check_already_current(tag=None, sha=None):
"""Check if the currently available frontend is already the requested one."""
ref = 'tag' if tag else 'commit'
if tag:
current = managePyDir().joinpath('web', 'static', 'web', '.vite', 'tag.txt')
elif sha:
current = managePyDir().joinpath('web', 'static', 'web', '.vite', 'sha.txt')
else:
raise ValueError('Either tag or sha needs to be set')
if not current.exists():
print(
f'Current frontend information for {ref} is not available - this is expected in some cases'
)
return False
current_content = current.read_text().strip()
ref_value = tag or sha
if current_content == ref_value:
print(f'Frontend {ref} is already `{ref_value}`')
return True
else:
print(
f'Frontend {ref} is not expected `{ref_value}` but `{current_content}` - new version will be downloaded'
)
return False
# if zip file is specified, try to extract it directly
if file:
handle_extract(file)
@ -1288,8 +1316,24 @@ def frontend_download(
['git', 'rev-parse', 'HEAD'], encoding='utf-8'
).strip()
except Exception:
print("[ERROR] Cannot get current ref via 'git rev-parse HEAD'")
return
# .deb Packages contain extra information in the VERSION file
version_file = localDir().joinpath('VERSION')
if not version_file.exists():
return
from dotenv import dotenv_values # noqa: WPS433
content = dotenv_values(version_file)
if (
'INVENTREE_PKG_INSTALLER' in content
and content['INVENTREE_PKG_INSTALLER'] == 'PKG'
):
ref = content.get('INVENTREE_COMMIT_SHA')
print(
f'[INFO] Running in package environment, got commit "{ref}" from VERSION file'
)
else:
print("[ERROR] Cannot get current ref via 'git rev-parse HEAD'")
return
if ref is None and tag is None:
print('[ERROR] Either ref or tag needs to be set.')
@ -1297,6 +1341,8 @@ def frontend_download(
if tag:
tag = tag.lstrip('v')
try:
if check_already_current(tag=tag):
return
handle_download(
f'https://github.com/{repo}/releases/download/{tag}/frontend-build.zip'
)
@ -1312,6 +1358,8 @@ Then try continuing by running: invoke frontend-download --file <path-to-downloa
return
if ref:
if check_already_current(sha=ref):
return
# get workflow run from all workflow runs on that particular ref
workflow_runs = requests.get(
f'https://api.github.com/repos/{repo}/actions/runs?head_sha={ref}',