Skip to content

Commit

Permalink
Use git describe to determine the version
Browse files Browse the repository at this point in the history
  • Loading branch information
certik committed Aug 28, 2020
1 parent 3878937 commit e30aed0
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions ci/version.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
#!/bin/bash

# This script extracts the project's current version from git. If there is a
# tag attached to the current commit (of the form "v1.0.1"), then it will be
# used ("1.0.1"), otherwise the first 7 characters of the hash of the current
# commit will be used ("eb757a8"). The result will be saved to a "version"
# file.
# This script extracts the project's current version from git using
# `git describe`, which determines the version based on the latest tag, such as:
#
# $ git describe --tags --dirty
# v0.6.0-37-g3878937f-dirty
#
# Each tag starts with "v", so we strip the "v", and the final version becomes:
#
# 0.6.0-37-g3878937f-dirty
#

set -e
set -x
set -ex

if [[ $CI_COMMIT_SHA == "" ]]; then
# Use sha and tag values provided by git (requires git to be installed)
COMMIT_TAG=$(git tag -l --points-at HEAD)
COMMIT_SHA=$(git rev-parse HEAD)
else
# Use sha and tag variables provides by the CI
COMMIT_TAG=${CI_COMMIT_TAG}
COMMIT_SHA=${CI_COMMIT_SHA}
fi

if [[ $COMMIT_TAG == "" ]]; then
# The commit is not tagged, use the first 7 chars of git commit hash
version="0.0+git${COMMIT_SHA:0:7}"
else
# The commit is tagged, convert tag version properly:v1.0.1 -> "1.0.1"
version=${COMMIT_TAG:1}
fi

echo ${version} > version
version=$(git describe --tags --dirty)
version="${version:1}"
echo $version > version

0 comments on commit e30aed0

Please sign in to comment.