dgiot/pkg-vsn.sh

36 lines
863 B
Bash
Raw Normal View History

2021-05-18 14:54:48 +08:00
#!/usr/bin/env bash
set -euo pipefail
# This script prints the release version for emqx
# ensure dir
cd -P -- "$(dirname -- "$0")"
if [ -f EMQX_ENTERPRISE ]; then
EDITION='enterprise'
else
EDITION='opensource'
fi
2022-01-07 16:30:56 +08:00
## emqx_release.hrl is the single source of truth for release version
2021-05-18 14:54:48 +08:00
RELEASE="$(grep -E "define.+EMQX_RELEASE.+${EDITION}" include/emqx_release.hrl | cut -d '"' -f2)"
2022-01-07 16:30:56 +08:00
git_exact_vsn() {
local tag
tag="$(git describe --tags --match "[e|v]*" --exact 2>/dev/null)"
echo "$tag" | sed 's/^[v|e]//g'
}
GIT_EXACT_VSN="$(git_exact_vsn)"
if [ "$GIT_EXACT_VSN" != '' ]; then
if [ "$GIT_EXACT_VSN" != "$RELEASE" ]; then
echo "ERROR: Tagged $GIT_EXACT_VSN, but $RELEASE in include/emqx_release.hrl" 1>&2
exit 1
fi
SUFFIX=''
else
2021-05-18 14:54:48 +08:00
SUFFIX="-$(git rev-parse HEAD | cut -b1-8)"
fi
2022-01-07 16:30:56 +08:00
echo "${RELEASE}${SUFFIX}"