v0.13.9-rework_ha_addon
This commit is contained in:
Executable
+70
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
ENV_FILE="${HA_ADDON_ENV_FILE:-$SCRIPT_DIR/.env}"
|
||||
|
||||
[[ -f "$ENV_FILE" ]] || {
|
||||
echo "Missing $ENV_FILE. Copy $SCRIPT_DIR/.env.example to $SCRIPT_DIR/.env and edit it." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
set -a
|
||||
# shellcheck disable=SC1090
|
||||
source "$ENV_FILE"
|
||||
set +a
|
||||
|
||||
required=(HA_REPO_URL HA_REPO_BRANCH HA_REPO_PATH ADDON_DIR INTEGRATION_DOMAIN)
|
||||
for name in "${required[@]}"; do
|
||||
[[ -n "${!name:-}" ]] || { echo "Missing $name in $ENV_FILE" >&2; exit 1; }
|
||||
done
|
||||
|
||||
command -v git >/dev/null 2>&1 || { echo "git is required" >&2; exit 1; }
|
||||
command -v rsync >/dev/null 2>&1 || { echo "rsync is required" >&2; exit 1; }
|
||||
|
||||
if [[ "$HA_REPO_PATH" != /* ]]; then
|
||||
HA_REPO_PATH="$PROJECT_ROOT/$HA_REPO_PATH"
|
||||
fi
|
||||
HA_REPO_PATH="$(realpath -m "$HA_REPO_PATH")"
|
||||
INTEGRATION_SOURCE="$SCRIPT_DIR/home-assistant/custom_components/$INTEGRATION_DOMAIN"
|
||||
|
||||
[[ -d "$SCRIPT_DIR/repository/$ADDON_DIR" ]] || { echo "Missing add-on source" >&2; exit 1; }
|
||||
[[ -d "$INTEGRATION_SOURCE" ]] || { echo "Missing integration source: $INTEGRATION_SOURCE" >&2; exit 1; }
|
||||
|
||||
"$SCRIPT_DIR/build.sh" render
|
||||
|
||||
if [[ ! -e "$HA_REPO_PATH" ]]; then
|
||||
git clone --branch "$HA_REPO_BRANCH" "$HA_REPO_URL" "$HA_REPO_PATH"
|
||||
elif [[ ! -d "$HA_REPO_PATH/.git" ]]; then
|
||||
echo "HA_REPO_PATH exists but is not a Git repository: $HA_REPO_PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n "$(git -C "$HA_REPO_PATH" status --porcelain)" ]]; then
|
||||
echo "HA repository has uncommitted changes: $HA_REPO_PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git -C "$HA_REPO_PATH" checkout "$HA_REPO_BRANCH"
|
||||
git -C "$HA_REPO_PATH" pull --ff-only origin "$HA_REPO_BRANCH"
|
||||
|
||||
STAGE="$(mktemp -d)"
|
||||
trap 'rm -rf "$STAGE"' EXIT
|
||||
rsync -a "$SCRIPT_DIR/repository/" "$STAGE/"
|
||||
mkdir -p "$STAGE/custom_components/$INTEGRATION_DOMAIN"
|
||||
rsync -a "$INTEGRATION_SOURCE/" "$STAGE/custom_components/$INTEGRATION_DOMAIN/"
|
||||
rsync -a --delete --exclude='.git/' "$STAGE/" "$HA_REPO_PATH/"
|
||||
|
||||
git -C "$HA_REPO_PATH" add -A
|
||||
if git -C "$HA_REPO_PATH" diff --cached --quiet; then
|
||||
echo "HA repository is already synchronized."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
VERSION="$(awk -F '"' '/^version = "/ {print $2; exit}' "$PROJECT_ROOT/Cargo.toml")"
|
||||
[[ -n "$VERSION" ]] || { echo "Cannot determine version from Cargo.toml" >&2; exit 1; }
|
||||
|
||||
git -C "$HA_REPO_PATH" commit -m "GREE Controller ${VERSION}"
|
||||
git -C "$HA_REPO_PATH" push origin "$HA_REPO_BRANCH"
|
||||
printf 'Synchronized add-on + custom integration -> %s (%s)\n' "$HA_REPO_URL" "$HA_REPO_BRANCH"
|
||||
Reference in New Issue
Block a user