#!/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