From 5efaa0338edf081d607f562b41ed048690f41d3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Tue, 18 Jun 2024 08:24:59 +0200 Subject: [PATCH] Install the frontend wheel from GitHub (#3778) --- scripts/install/frontend | 41 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/scripts/install/frontend b/scripts/install/frontend index ec15633ab..646215895 100755 --- a/scripts/install/frontend +++ b/scripts/install/frontend @@ -6,6 +6,41 @@ cd "$(dirname "$0")/../.." FRONTEND_VERSION="20240528140736" -rm -rf ./custom_components/hacs/hacs_frontend -scripts/install/pip_packages --target=./custom_components/hacs "hacs_frontend==${FRONTEND_VERSION}" -rm -rf ./custom_components/hacs/*.dist-info +function installFrontendFromGitHub() { + # Temporarily disable exit on error + set +e + # Attempt to install the specified frontend version from GitHub + scripts/install/pip_packages \ + --target=./custom_components/hacs \ + "https://github.com/hacs/frontend/releases/download/${FRONTEND_VERSION}/hacs_frontend-${FRONTEND_VERSION}-py3-none-any.whl" + # Re-enable exit on error + set -e +} + +function installFrontend() { + # Remove existing frontend installation + rm -rf ./custom_components/hacs/hacs_frontend + installFrontendFromGitHub + + # Check if the installation from GitHub was successful + if [[ ! -f "./custom_components/hacs/hacs_frontend/version.py" ]]; then + echo "Failed to install from GitHub, trying PyPI" + # If not, install from PyPI + scripts/install/pip_packages \ + --target=./custom_components/hacs \ + "hacs_frontend==${FRONTEND_VERSION}" + fi + + # Clean up any leftover metadata files + rm -rf ./custom_components/hacs/*.dist-info +} + +# Get current version if any +CURRENT_VERSION=$(grep "VERSION" ./custom_components/hacs/hacs_frontend/version.py -s | cut -d '"' -f 2) + +# Install the frontend if the current version is different from the desired version +if [[ "${CURRENT_VERSION}" != "${FRONTEND_VERSION}" ]]; then + installFrontend +else + echo "Frontend version is the same (${FRONTEND_VERSION}), skipping download" +fi