generate-version: handle git repo not having any tags

This commit is contained in:
Daniel Eklöf 2021-10-11 20:21:00 +02:00
parent 6250360c58
commit 9a1371b96a
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 8 additions and 6 deletions

View file

@ -1,8 +1,3 @@
clone:
git:
image: plugins/git
tags: true
pipeline: pipeline:
codespell: codespell:
when: { branch: master } when: { branch: master }

View file

@ -13,7 +13,14 @@ out_file=${3}
if [ -d "${src_dir}/.git" ] && command -v git > /dev/null; then if [ -d "${src_dir}/.git" ] && command -v git > /dev/null; then
workdir=$(pwd) workdir=$(pwd)
cd "${src_dir}" cd "${src_dir}"
if git describe --tags > /dev/null 2>&1; then
git_version=$(git describe --always --tags) git_version=$(git describe --always --tags)
else
# No tags available, happens in e.g. CI builds
git_version="${default_version}"
fi
git_branch=$(git rev-parse --abbrev-ref HEAD) git_branch=$(git rev-parse --abbrev-ref HEAD)
cd "${workdir}" cd "${workdir}"