build-hass/.pipeline/version.sh

52 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
set -e
HASS_REPO="core"
# ALTERNATIVE: USE GITHUB API
#
# $ curl -s https://api.github.com/repos/home-assistant/core/releases/latest | jq .name
# "2024.2.5"
#
# Open in Firefox, check the JSON. Lots of fields, and several fields with the version number.
# DO NOT IGNORE.
if [[ -n "${HASS_VERSION}" ]]; then
echo "environment var 'HASS_VERSION' is alrady set, this probably means that a specific/version tag is being built manually" >&2
echo "HASS_VERSION: ${HASS_VERSION}'" >&2
echo >&2
echo "will use this value and not look for tha latest git tag" >&2
sleep 5
else
PWD_REPO_NAME=$(basename $(git rev-parse --show-toplevel))
if [[ "$PWD_REPO_NAME" != "${HASS_REPO}" ]]; then
GIT_CHDIR_OPT="-C ${HASS_REPO}/"
fi
git $GIT_CHDIR_OPT fetch --tags
# gets all tags without sorting
# git tag -l --sort=-creatordate | head -n 1
# gets all tags
#LATEST_TAG=$(git $GIT_CHDIR_OPT tag -l --sort=-creatordate | head -n 1)
# gets annotated tags (releases)
# This seems to only be .0 releases (2024.7.0, but not 2024.7.1)
#LATEST_TAG=$(git $GIT_CHDIR_OPT describe --tags --abbrev=0)
# This gets 2024.7.2 etc, unclear if it cats ..b0, ..b1, tags or not (i think it does)
LATEST_TAG=$(git $GIT_CHDIR_OPT describe --tags $(git $GIT_CHDIR_OPT rev-list --tags --max-count=1))
HASS_VERSION=$LATEST_TAG
# the version is also in pyproject.toml and homeassistant/setup.py (not 100% sure anout setup.py)
# but that is the version of the current branch, not
# the most recent stable
export HASS_VERSION
fi
if [[ -t 1 ]]; then
echo "version: '${HASS_VERSION}'"
else
echo $HASS_VERSION
fi