1#!/bin/sh 2 3set -e 4 5##################################### util ####################################### 6 7COLOR_RED='\033[0;31m' # Red 8COLOR_GREEN='\033[0;32m' # Green 9COLOR_PURPLE='\033[0;35m' # Purple 10COLOR_OFF='\033[0m' # Reset 11 12note() { 13 printf '\n%b\n' "${COLOR_RED}$*${COLOR_OFF}" 14} 15 16run() { 17 printf '%b\n' "${COLOR_PURPLE}==>${COLOR_OFF} ${COLOR_GREEN}$*${COLOR_OFF}" 18 eval "$*" 19} 20 21##################################### main ####################################### 22 23base=5.9 24cal=$(date +%Y%m%d) 25chicken=0 26new_tagname="p${base}.${cal}.${chicken}" 27 28run git --version 29 30case "$(git describe --tags --exact-match HEAD 2>/dev/null || true)" in 31 p*.0) 32 note "do nothing. because there are no commits since the latest tag." 33 exit 0 34 ;; 35 '') ;; 36 *) echo "found a tag but it is not periodical one; create a periodical tag" 37esac 38 39for old_tagname in $(git tag --list) 40do 41 if [ "$old_tagname" = "$new_tagname" ] ; then 42 note "do nothing. because $new_tagname tag already exists." 43 exit 0 44 fi 45done 46 47run git tag "$new_tagname" 48run git push origin "$new_tagname" 49