v0.13.9-ha_addon
This commit is contained in:
Executable
+79
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
if [[ -f "$SCRIPT_DIR/.env" ]]; then
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
source "$SCRIPT_DIR/.env"
|
||||
set +a
|
||||
fi
|
||||
|
||||
HA_REPO_PATH="${HA_REPO_PATH:-../gree-controller-ha-addon}"
|
||||
HA_REPO_BRANCH="${HA_REPO_BRANCH:-master}"
|
||||
|
||||
if [[ "$HA_REPO_PATH" != /* ]]; then
|
||||
HA_REPO_PATH="$PROJECT_ROOT/$HA_REPO_PATH"
|
||||
fi
|
||||
|
||||
HA_REPO_PATH="$(realpath -m "$HA_REPO_PATH")"
|
||||
|
||||
VERSION="$(
|
||||
awk -F '"' '/^version = "/ {print $2; exit}' \
|
||||
"$PROJECT_ROOT/Cargo.toml"
|
||||
)"
|
||||
|
||||
[[ -n "$VERSION" ]] || {
|
||||
echo "Cannot determine version from Cargo.toml" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
[[ -d "$HA_REPO_PATH/.git" ]] || {
|
||||
echo "HA_REPO_PATH is not a Git repository: $HA_REPO_PATH" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "==> Building and pushing OCI image ${VERSION}"
|
||||
"$SCRIPT_DIR/build.sh" push
|
||||
|
||||
echo "==> Syncing Home Assistant repository"
|
||||
rsync -a --delete \
|
||||
--exclude='.git/' \
|
||||
"$SCRIPT_DIR/repository/" \
|
||||
"$HA_REPO_PATH/"
|
||||
|
||||
cd "$HA_REPO_PATH"
|
||||
|
||||
echo "==> Updating branch ${HA_REPO_BRANCH}"
|
||||
git checkout "$HA_REPO_BRANCH"
|
||||
|
||||
git add -A
|
||||
|
||||
if git diff --cached --quiet; then
|
||||
echo "No Home Assistant repository changes to publish."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "==> Committing Home Assistant add-on ${VERSION}"
|
||||
git commit -m "GREE Controller ${VERSION}"
|
||||
|
||||
echo "==> Pushing to Gitea"
|
||||
git push origin "$HA_REPO_BRANCH"
|
||||
|
||||
echo
|
||||
echo "Published:"
|
||||
echo " image version: ${VERSION}"
|
||||
echo " HA repository: ${HA_REPO_PATH}"
|
||||
echo " branch: ${HA_REPO_BRANCH}"
|
||||
Reference in New Issue
Block a user