Last active
January 16, 2019 09:01
-
-
Save EkkoG/3c69ae99c2b8c70c667a150e911b9641 to your computer and use it in GitHub Desktop.
git flow publish script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
git_current_branch () { | |
local ref | |
ref=$(command git symbolic-ref --quiet HEAD 2> /dev/null) | |
local ret=$? | |
if [[ $ret != 0 ]] | |
then | |
[[ $ret == 128 ]] && return | |
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return | |
fi | |
echo ${ref#refs/heads/} | |
} | |
current_branch=$(git_current_branch) | |
echo "当前分支 $current_branch" | |
echo "切换到 develop 分支" | |
git checkout develop | |
echo "更新 master 和 develop" | |
git pull origin master:master | |
git pull origin develop:develop | |
echo "合并 master 到 develop" | |
git merge master | |
echo "fetch 所有,包含所有 tag" | |
git fetch --all | |
latest_tag=$(git describe --abbrev=0) | |
latest_tag_number=$(echo $latest_tag | tr -cd "[0-9]") | |
bump_version=$(($latest_tag_number+1)); | |
echo "当前最新版本 $latest_tag_number" | |
echo "开始发布 $bump_version" | |
if [ ! -n "$1" ] ;then | |
git tag "v$bump_version" -m "bump version $bump_version" | |
else | |
git tag "v$bump_version" -m $1 | |
fi | |
echo "发布完成" | |
git push --tags origin | |
git push origin master:master | |
git push origin develop:develop | |
echo "推送到远程成功" | |
echo "切换到原分支" | |
git checkout $current_branch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment