Merge pull request #6160 from zmstone/chore-check-version-before-build

build: ensure git tag matches release version
This commit is contained in:
Zaiming (Stone) Shi 2021-11-15 09:07:37 +01:00 committed by GitHub
commit 7dc944a154
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 3 deletions

View File

@ -15,9 +15,21 @@ fi
## emqx_release.hrl is the single source of truth for release version
RELEASE="$(grep -E "define.+EMQX_RELEASE.+${EDITION}" include/emqx_release.hrl | cut -d '"' -f2)"
## git commit hash is added as suffix in case the git tag and release version is not an exact match
if [ -d .git ] && ! git describe --tags --match "[e|v]${RELEASE}" --exact >/dev/null 2>&1; then
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
SUFFIX="-$(git rev-parse HEAD | cut -b1-8)"
fi
echo "${RELEASE}${SUFFIX:-}"
echo "${RELEASE}${SUFFIX}"