Skip to content

Commit

Permalink
now retrieving version from a file, and building that file from the r…
Browse files Browse the repository at this point in the history
…epo.version.
  • Loading branch information
jason-c-daniels committed Jul 1, 2018
1 parent cb725eb commit d8e67ab
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
4 changes: 4 additions & 0 deletions build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
export BUILD_SCRIPT_DIR=$(dirname $(readlink -f $0))
$BUILD_SCRIPT_DIR/../src/git-ver get-version bump patch > $BUILD_SCRIPT_DIR/../repo.version
$BUILD_SCRIPT_DIR/../src/git-ver get-semver bump patch > $BUILD_SCRIPT_DIR/../src/git-ver.version
2 changes: 1 addition & 1 deletion repo.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.1.1
3 changes: 2 additions & 1 deletion src/git-ver
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash
set -e
export GIT_VER_APP_VERSION="0.1.0-alpha"
export GIT_VER_APP_DIR=$(dirname $(readlink -f $0))
export GIT_VER_APP_VERSION="$(cat $GIT_VER_APP_DIR/git-ver.version)"

main () {
source "$GIT_VER_APP_DIR/git-ver.bashlib" #include the common library so everything in here can execute.
if [[ $1 == version || $1 == help ]]; then
Expand Down
42 changes: 23 additions & 19 deletions src/git-ver.bashlib
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ get_version() {
ver="$(get_major bump).0.0"
elif [[ $2 == minor ]]; then
ver="$(get_major).$(get_minor bump).0"
elif [[ $2 == minor ]]; then
elif [[ $2 == patch ]]; then
ver="$(get_major).$(get_minor).$(get_patch bump)";
fi
fi
Expand All @@ -122,23 +122,27 @@ get_suffix() {

get_rev() {
local rev=0
# count commits since last tag in this branch
local suffix=$(get_branch_suffix)
local last_tag="$(get_tag)"
local last_tag_ref=$(git rev-list --no-walk --max-count=1 --tags=v*$suffix*)

if [[ "$last_tag_ref" == "" ]]; then
rev=0
else
# count commits since last tag.
local rsl=$(git rev-list $last_tag_ref..HEAD --count)

#extract the rev (if any) from the current tag.
local rft=$(echo $last_tag | sed -e 's/\(.*[-].*\)\([r][0-9]\)/\2/' | sed -e 's/[^0-9]//g')
if [[ "$rft" == "" ]]; then rft=0; fi
rev=$(expr $rsl + $rft)
if [[ "$APPVEYOR" == "true" ]]; then
rev=$APPVEYOR_PULL_REQUEST_NUMBER
fi


if [[ $rev -eq 0 ]]; then
# count commits since last tag in this branch
local suffix=$(get_branch_suffix)
local last_tag="$(get_tag)"
local last_tag_ref=$(git rev-list --no-walk --max-count=1 --tags=v*$suffix*)

if [[ "$last_tag_ref" != "" ]]; then
# count commits since last tag.
local rsl=$(git rev-list $last_tag_ref..HEAD --count)

#extract the rev (if any) from the current tag.
local rft=$(echo $last_tag | sed -e 's/\(.*[-].*\)\([r][0-9]\)/\2/' | sed -e 's/[^0-9]//g')
if [[ "$rft" == "" ]]; then rft=0; fi
rev=$(expr $rsl + $rft)
fi
fi
echo "$rev"
}

Expand Down Expand Up @@ -183,10 +187,10 @@ get_semver() {
elif [[ $2 == "-d" || $2 == "--date" ]]; then
suffix_params="$suffix_params -d"
prefix_params="${*:3}"
elif [[ $suffix_params != "" ]]; then
prefix_params="${*:2}"
elif [[ $suffix_params == "" ]]; then
prefix_params="$*"
else
prefix_params="$*"
prefix_params="${*:2}"
fi

local suffix="$(get_suffix $suffix_params)"
Expand Down
1 change: 1 addition & 0 deletions src/git-ver.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.1.1-alpha

0 comments on commit d8e67ab

Please sign in to comment.