branch_info.sh 797 Bytes
Newer Older
“李磊”'s avatar
“李磊” committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash

branch=`git branch --show-current`
if [ -n "$BRANCH_NAME" ]; then # 通过环境变量传入
    branch=$BRANCH_NAME
fi
version=$branch-`date +%Y-%m-%d-%H`
spcode=""

if [[ $branch =~ ^release/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then                # match release/5.1.3
    version=${BASH_REMATCH[1]}
elif [[ $branch =~ ^(sp[0-9]+)/release/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then   # match sp96/release/5.2.0
    spcode=${BASH_REMATCH[1]}
    version=${BASH_REMATCH[2]}
else
    version=`echo "$version" | sed 's#/#-#g;s#%2F#-#g'`
fi

case "$1" in
get_version)
    echo $version
    ;;
get_spcode)
    echo $spcode
    ;;
*)
    if [ -z "$1" ]; then
        echo "version: $version"
        echo "spcode:  $spcode"
    else
        echo "usage: $0 [get_version|get_spcode]"
    fi
    ;;
esac