forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use git describe to determine the version
- Loading branch information
Showing
1 changed file
with
14 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |