1+ #! /bin/bash
2+
3+ # Change to the root directory
4+ cd " $( dirname " $0 " ) /.."
5+
6+ # Define ANSI color codes
7+ ORANGE=' \033[0;33m'
8+ NC=' \033[0m' # No Color
9+
10+ # Function to handle errors and exit
11+ error_exit () {
12+ echo -e " ❌ Error: $1 " >&2
13+ exit 1
14+ }
15+
16+ # Function to get the package version from pubspec.yaml
17+ get_package_version () {
18+ local version=$( yq .version pubspec.yaml | tr -d ' "' )
19+ echo " $version "
20+ }
21+
22+ # Function to get the current Git branch
23+ get_current_branch () {
24+ git rev-parse --abbrev-ref HEAD
25+ }
26+
27+ # Function to run git status
28+ run_git_status () {
29+ git status
30+ }
31+
32+ # Function to add all changes and commit with message including version
33+ add_commit () {
34+ local version=" $1 "
35+ git add -A
36+ git commit -m " 🚀 $version "
37+ }
38+
39+ # Function to merge the current branch into master
40+ merge_into_master () {
41+ local branch=$( get_current_branch)
42+ git checkout master
43+ git merge --no-ff " $branch "
44+ git push origin master
45+ git checkout " $branch "
46+ }
47+
48+ # Function to install GitHub CLI if not already installed
49+ install_gh_cli () {
50+ if ! which gh > /dev/null 2>&1 ; then
51+ echo -e " ${ORANGE} ⚠️ Installing GitHub CLI...${NC} "
52+ brew install gh || error_exit " Failed to install GitHub CLI. Please install it manually and retry."
53+ fi
54+ }
55+
56+ # Function to create GitHub release
57+ create_github_release () {
58+ local version=" $1 "
59+ echo -e " ${ORANGE} ⚠️ Creating GitHub release for version $version ...${NC} \n"
60+ gh release create " $version " --notes " Release for version $version "
61+ echo " ✅ GitHub release $version created\n"
62+ }
63+
64+ # Main script execution
65+ # Check if GitHub CLI is installed
66+ install_gh_cli
67+
68+ # Get the package version from pubspec.yaml
69+ current_version=$( get_package_version)
70+ echo " Current version is $current_version "
71+
72+ # Ask for confirmation to merge into master with versioned commit
73+ read -p " Merge into master and create release with commit: '🚀 $current_version '? (y/n): " confirmation
74+
75+ if [[ $confirmation == " y" || $confirmation == " Y" ]]; then
76+ # Perform the Git operations
77+ run_git_status
78+ add_commit " $current_version "
79+ merge_into_master
80+
81+ # Tag the new version
82+ git tag " $current_version "
83+ git push --tags
84+
85+ # Create the GitHub release
86+ create_github_release " $current_version "
87+ else
88+ echo " Merge and release process canceled."
89+ fi
0 commit comments