github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/script/version.sh (about) 1 #!/usr/bin/env bash 2 3 # exit by command return non-zero exit code 4 set -o errexit 5 # Indicate an error when it encounters an undefined variable 6 set -o nounset 7 # Fail on any error. 8 set -o pipefail 9 # set -o xtrace 10 11 12 function get_version_from_git() { 13 GIT="git" 14 GIT_COMMIT=$("${GIT}" rev-parse "HEAD^{commit}") 15 GIT_TAG=$(git describe --long --tags --dirty --tags --always) 16 GIT_BUILD_TIME=$(TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ') 17 18 19 GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true) 20 21 GIT_TREE_STATE=${GIT_TREE_STATE-} 22 if git_status=$("${GIT}" status --porcelain) && [[ -z ${git_status} ]]; then 23 GIT_TREE_STATE="clean" 24 else 25 GIT_TREE_STATE="dirty" 26 fi 27 } 28 29 function gitinfos() { 30 get_version_from_git 31 32 local -a gitinfos 33 function add_gitinfo() { 34 local key=${1} 35 local val=${2} 36 37 # update the list github.com/kaydxh/golang/pkg/app. 38 gitinfos+=( 39 "${key}=${val}" 40 ) 41 } 42 43 add_gitinfo "buildDate" "${GIT_BUILD_TIME}" 44 add_gitinfo "gitVersion" "${GIT_TAG}" 45 add_gitinfo "gitCommit" "${GIT_COMMIT}" 46 add_gitinfo "gitTreeState" "${GIT_TREE_STATE}" 47 48 # "$*" => get arg1 arg2 arg3 as a single argument "a1 a2 a3" 49 # "$@" => gets arg1, arg2 and arg3 as a separate arguments "a1" "a2" "a3" 50 # if no quotes, $* is the same to $@, as a separate arguments "a1" "a2" "a3" 51 for gitinfo in "${gitinfos[@]}" 52 do 53 echo ${gitinfo} 54 done 55 } 56 57 # Allows to call a function based on arguments passed to the script 58 $*