From d8e67ab2356c49b4ecd3552d4bdce24926dfa6b8 Mon Sep 17 00:00:00 2001 From: Jason Daniels Date: Sun, 1 Jul 2018 15:10:21 -0500 Subject: [PATCH] now retrieving version from a file, and building that file from the repo.version. --- build/build.sh | 4 ++++ repo.version | 2 +- src/git-ver | 3 ++- src/git-ver.bashlib | 42 +++++++++++++++++++++++------------------- src/git-ver.version | 1 + 5 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 build/build.sh create mode 100644 src/git-ver.version diff --git a/build/build.sh b/build/build.sh new file mode 100644 index 0000000..5fca198 --- /dev/null +++ b/build/build.sh @@ -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 \ No newline at end of file diff --git a/repo.version b/repo.version index 6e8bf73..17e51c3 100644 --- a/repo.version +++ b/repo.version @@ -1 +1 @@ -0.1.0 +0.1.1 diff --git a/src/git-ver b/src/git-ver index 314ae1e..cf1be2d 100644 --- a/src/git-ver +++ b/src/git-ver @@ -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 diff --git a/src/git-ver.bashlib b/src/git-ver.bashlib index 961a833..ed93b79 100644 --- a/src/git-ver.bashlib +++ b/src/git-ver.bashlib @@ -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 @@ -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" } @@ -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)" diff --git a/src/git-ver.version b/src/git-ver.version new file mode 100644 index 0000000..c03d421 --- /dev/null +++ b/src/git-ver.version @@ -0,0 +1 @@ +v0.1.1-alpha