@@ -89,21 +89,23 @@ check_git_status() {
8989 if ! git diff-index --quiet HEAD --; then
9090 error " Uncommitted changes found. Please commit them first."
9191 fi
92+ }
9293
93- local branch=$( git rev-parse --abbrev-ref HEAD)
94- if [[ " $branch " != " master" && " $branch " != " main" ]]; then
95- warning " Current branch is '$branch '. You are trying to create a tag on a branch other than master/main."
96- read -p " Continue? (y/N): " -n 1 -r
97- echo
98- if [[ ! $REPLY =~ ^[Yy]$ ]]; then
99- error " Processing interrupted"
100- fi
94+ get_main_branch () {
95+ if git rev-parse --verify main > /dev/null 2>&1 ; then
96+ echo " main"
97+ elif git rev-parse --verify master > /dev/null 2>&1 ; then
98+ echo " master"
99+ else
100+ error " Neither 'main' nor 'master' branch found"
101101 fi
102102}
103103
104104create_tag () {
105105 local version=$1
106106 local tag_name=" v$version "
107+ local current_branch=$( git rev-parse --abbrev-ref HEAD)
108+ local main_branch=$( get_main_branch)
107109
108110 if git rev-parse " $tag_name " > /dev/null 2>&1 ; then
109111 error " Tag '$tag_name ' already exists"
@@ -114,15 +116,39 @@ create_tag() {
114116 git commit -m " chore: bump version to $version "
115117 success " Changes committed"
116118
119+ # If current branch is not main/master, execute PR workflow
120+ if [[ " $current_branch " != " $main_branch " ]]; then
121+ info " Pushing branch '$current_branch '..."
122+ git push origin " $current_branch "
123+ success " Branch pushed"
124+
125+ info " Merging PR with gh command..."
126+ if gh pr merge --auto --squash --delete-branch 2> /dev/null; then
127+ success " PR merged and branch deleted"
128+ else
129+ warning " Failed to auto-merge. Attempting manual merge..."
130+ if gh pr merge --squash --delete-branch; then
131+ success " PR merged and branch deleted"
132+ else
133+ error " Failed to merge PR. Please merge manually and run this script again."
134+ fi
135+ fi
136+
137+ info " Switching to $main_branch branch..."
138+ git checkout " $main_branch "
139+ success " Switched to $main_branch "
140+
141+ info " Pulling latest changes..."
142+ git pull origin " $main_branch "
143+ success " Pulled latest changes"
144+ fi
145+
117146 git tag -a " $tag_name " -m " Release $version "
118147 success " Tag '$tag_name ' created"
119148
120- info " "
121- info " You can push the tag with the following command:"
122- info " git push origin $tag_name "
123- info " "
124- info " Or push all tags:"
125- info " git push origin --tags"
149+ info " Pushing tag to origin..."
150+ git push origin " $tag_name "
151+ success " Tag '$tag_name ' pushed"
126152}
127153
128154main () {
0 commit comments