一直使用命令行操作git, 发现处理发布流程还是贼费劲, 今天写个bash
版的一键发布, 解放下git checkout/merge/tag
。
bash版本
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
| #!/bin/bash
help() { echo -e "\t Used: gitman branch environment\n" echo -e "\t branch: feature/xxx" echo -e "\t environment: [beta/online/gray]" exit 1 } if [ ! $# -eq 2 ]; then help fi
feature_branch=$1 environment=$2
if [ ! -z "${feature_branch##*/*}" ];then echo "branch must be feature/xxx format!" exit 1 fi
case $environment in "beta") beta="git fetch && git checkout $feature_branch && git pull && git checkout beta && git pull && git merge $feature_branch && git push" eval $beta ;; "online")
relese_branch="release/"$(echo $feature_branch | cut -d "/" -f2) while ((1)) do read -r -p "use $release_branch? [Y/N]" ok case $ok in "N") read -r -p "Please input your release branch name: " release_branch ;; "Y") break ;; esac done
merge_cmd="git fetch && git checkout $feature_branch && git pull && git checkout develop && git pull && git merge $feature_branch && git checkout -b $release_branch && git checkout master && git pull && git merge $release_branch && git push" eval $merge_cmd if [ ! $? -eq 0 ];then echo "merge code failture." exit 1 fi
declare deploy_tag last_tag=$("git tag | grep v | sort -r | sed -n '1p'") echo echo "current tag: $last_tag" while ((1)) do read -r -p "Please input your tag:" deploy_tag echo "confirm $deploy_tag" read -r -p "use this tag? [Y/N]" confirm case $confirm in Y) break esac done echo "this deploy use $deploy_tag" echo tag_cmd="git tag $deploy_tag -am `date '+%F:%T'` && git push origin $deploy_tag" eval $tag_cmd
if [ ! $? -eq 0 ];then echo "build tag failture." exit 1 fi
read -r -p "delete local and remote branch" ok case $ok in Y) delete_cmd="git branch -d $release_branch && git branch -d $feature_branch && git push origin $feature_branch --delete" eval $delete_cmd ;; esac ;; "gray")
relese_branch="release/"$(echo $feature_branch | cut -d "/" -f2) echo "release branch: $release_branch" echo while ((1)) do read -r -p "use $release_branch? [Y/N]" ok case $ok in N) read -r -p "Please input your release branch name!" release_branch ;; Y) break ;; esac done
merge_cmd="git fetch && git checkout $feature_branch && git pull && git checkout master && git pull && git branch -D huidu && git checkout huidu && git pull && git merge $feature_branch && git push " eval $merge_cmd if [ ! $? -eq 0 ];then echo "merge code failture." exit 1 fi
declare deploy_tag last_tag=$("git tag | grep x | sort -r | sed -n '1p'") echo echo "current tag: $last_tag" while ((1)) do read -r -p "Please input your tag:" deploy_tag echo "confirm $deploy_tag" read -r -p "use this tag? [Y/N]" confirm case $confirm in Y) break esac done echo "this deploy use $deploy_tag" echo tag_cmd="git tag $read -am `date '+%F:%T'`" eval $tag_cmd
if [ ! $? -eq 0 ];then echo "build tag failture." exit 1 fi
delete_cmd="git branch -d $release_branch && git branch -d $feature_branch && git push origin $feature_branch --delete" eval $delete_cmd ;; *) help ;; esac
|