Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

Commit

Permalink
Added checks for upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-scott committed Nov 23, 2023
1 parent 8beb5e4 commit b64d159
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ jobs:
with:
ref: ${{ github.head_ref }}
path: "clone"
submodules: "recursive"

- name: "Checkout Git https://github.com/home-assistant/core/"
uses: actions/checkout@v3
with:
repository: "home-assistant/core"
path: "core"
path: "upstream"

- name: Update files via script
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.history
cloud.code-workspace
core
upstream
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "core"]
path = core
url = https://github.com/home-assistant/core
37 changes: 25 additions & 12 deletions bin/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,25 @@ set -e -o pipefail

# Get the latest tag from the GitHub API.
HOME_ASSISTANT_CORE_LATEST_TAG="$(curl -Ls https://api.github.com/repos/home-assistant/core/tags | jq '.[].name' | sed 's/"//g' | grep -Ev '[[:alpha:]]' | sort -V | tail -n 1)"
echo "latest_tag=${HOME_ASSISTANT_CORE_LATEST_TAG}" >>"$GITHUB_ENV"
if [[ -n "${GITHUB_ENV}" ]]; then
echo "latest_tag=${HOME_ASSISTANT_CORE_LATEST_TAG}" >>"$GITHUB_ENV"
fi

# If we haven't already checked out the repo, do so now.
if [[ ! -d core ]]; then
if [[ ! -d upstream ]]; then

# Clone the repo max-depth of 1 commit as we only need the latest.
git clone --depth 1 https://github.com/home-assistant/core/
git clone --depth 1 https://github.com/home-assistant/core/ upstream

# Ensure that the core directory gets cleaned up on exit.
trap "rm -rf "${START_DIR}/core"" EXIT
trap "rm -rf "${START_DIR}/upstream"" EXIT

fi

if [[ -d core ]]; then
cd core
git pull --depth 1
cd "${START_DIR}"
fi

# Create a variable for the source directory we are using.
Expand All @@ -33,14 +41,19 @@ if [[ ! -d custom_components/default_config ]]; then
mkdir -p custom_components/default_config
fi

# Copy over the upstream files
rsync -avz "${START_DIR}/core/homeassistant/components/default_config" "${START_DIR}/custom_components"
# Check for changed files
if [[ $(rsync -avz --checksum --dry-run ${START_DIR}/upstream/homeassistant/components/default_config ${START_DIR}/core/homeassistant/components | grep -c default_config) -gt 1 ]]; then

# Add in required data for the component to get loaded
cat <<<$(jq ". + { "version": \"${HOME_ASSISTANT_CORE_LATEST_TAG}.1\" }" ${START_DIR}/custom_components/default_config/manifest.json) >${START_DIR}/custom_components/default_config/manifest.json
# Copy over the upstream files
rsync -avz "${START_DIR}/core/homeassistant/components/default_config" "${START_DIR}/custom_components"

# Disable the 'cloud' integration.
cat <<<$(jq 'del(.dependencies[] | select(. == "cloud"))' ${START_DIR}/custom_components/default_config/manifest.json) >${START_DIR}/custom_components/default_config/manifest.json
# Add in required data for the component to get loaded
cat <<<$(jq ". + { "version": \"${HOME_ASSISTANT_CORE_LATEST_TAG}.1\" }" ${START_DIR}/custom_components/default_config/manifest.json) >${START_DIR}/custom_components/default_config/manifest.json

# Update hacs.json with the minimum homeassistant value for the latest release
cat <<<$(jq ".homeassistant = \"${HOME_ASSISTANT_CORE_LATEST_TAG}\"" ${START_DIR}/hacs.json) >${START_DIR}/hacs.json
# Disable the 'cloud' integration.
cat <<<$(jq 'del(.dependencies[] | select(. == "cloud"))' ${START_DIR}/custom_components/default_config/manifest.json) >${START_DIR}/custom_components/default_config/manifest.json

# Update hacs.json with the minimum homeassistant value for the latest release
cat <<<$(jq ".homeassistant = \"${HOME_ASSISTANT_CORE_LATEST_TAG}\"" ${START_DIR}/hacs.json) >${START_DIR}/hacs.json

fi
1 change: 1 addition & 0 deletions core
Submodule core added at a1f7f8

0 comments on commit b64d159

Please sign in to comment.