3030# the Netherlands
3131#
3232
33+ # Function to show usage information
34+ show_usage () {
35+ echo " Usage: ./release_to_github.sh [OPTIONS]"
36+ echo " Options:"
37+ echo " --version MAJOR.MINOR.PATCH Set version number (required)"
38+ echo " --stage Stage changes in release branch"
39+ echo " --release Perform release merge and tagging"
40+ echo " "
41+ echo " Example:"
42+ echo " ./release_to_github.sh --version 4.0.1 --stage # Stage changes"
43+ echo " ./release_to_github.sh --version 4.0.1 --release # Perform release"
44+ }
3345
34- if [ $# -eq 0 ]; then
35- echo " Please provice version number: \" ./release_to_github.sh X.Y.Z\" "
36- else
37- git fetch --prune
46+ # Function to parse and validate version
47+ parse_version () {
48+ if ! echo " $1 " | grep -E " ^[0-9]+\.[0-9]+\.[0-9]+$" > /dev/null; then
49+ echo " Error: Version must be in format MAJOR.MINOR.PATCH"
50+ exit 1
51+ fi
3852
39- git checkout develop
40- git pull
41- git push github develop
53+ VERSION_MAJOR=$( echo " $1 " | cut -d. -f1)
54+ VERSION_MINOR=$( echo " $1 " | cut -d. -f2)
55+ VERSION_PATCH=$( echo " $1 " | cut -d. -f3)
56+ }
4257
43- git checkout master
44- git pull
45- git push github master
58+ # Function to update version files
59+ update_version_files () {
60+ # Update Version.h
61+ sed -i " s/#define EMBEDDEDPROTO_VERSION_MAJOR [0-9]*/#define EMBEDDEDPROTO_VERSION_MAJOR $VERSION_MAJOR /" src/Version.h
62+ sed -i " s/#define EMBEDDEDPROTO_VERSION_MINOR [0-9]*/#define EMBEDDEDPROTO_VERSION_MINOR $VERSION_MINOR /" src/Version.h
63+ sed -i " s/#define EMBEDDEDPROTO_VERSION_PATCH [0-9]*/#define EMBEDDEDPROTO_VERSION_PATCH $VERSION_PATCH /" src/Version.h
64+ sed -i " s/#define EMBEDDEDPROTO_VERSION_STRING \" .*\" /#define EMBEDDEDPROTO_VERSION_STRING \" $VERSION \" /" src/Version.h
65+
66+ # Update version.json
67+ echo " {" > EmbeddedProto/version.json
68+ echo " \" version\" : \" $VERSION \" " >> EmbeddedProto/version.json
69+ echo " }" >> EmbeddedProto/version.json
70+ }
4671
72+ # Function to create staging branch
73+ create_stage () {
74+ BRANCH=" release/$VERSION "
75+
76+ # Create and switch to release branch
77+ git checkout -b " $BRANCH "
78+
79+ # Update version files
80+ update_version_files
81+
82+ # Stage and commit changes
83+ git add src/Version.h EmbeddedProto/version.json
84+ git commit -m " Preparing for release $VERSION "
85+
86+ # Push to both remotes
87+ git push origin " $BRANCH "
88+ git push github " $BRANCH "
89+ }
90+
91+ # Function to perform release
92+ perform_release () {
93+ BRANCH=" release/$VERSION "
94+
95+ # Ensure we're on the release branch
96+ git checkout " $BRANCH "
97+
98+ # Merge into master
99+ git checkout master
100+ git merge --no-ff " $BRANCH " -m " Merge release $VERSION into master"
101+
102+ # Merge into develop
103+ git checkout develop
104+ git merge --no-ff " $BRANCH " -m " Merge release $VERSION into develop"
105+
106+ # Create version tag
47107 git tag -d latest
48108 git push --delete origin latest
49109 git push --delete github latest
50-
110+
51111 git tag latest
52112 git push origin latest
53113 git push github latest
114+
115+ git tag " $VERSION "
116+ git push origin " $VERSION "
117+ git push github " $VERSION "
118+
119+ # Push master and develop
120+ git checkout master
121+ git push origin master
122+ git push github master
123+
124+ git checkout develop
125+ git push origin develop
126+ git push github develop
127+
128+ # Clean up release branch
129+ git branch -d " $BRANCH "
130+ git push origin --delete " $BRANCH "
131+ git push github --delete " $BRANCH "
132+ }
133+
134+ # Parse command line arguments
135+ VERSION=" "
136+ DO_STAGE=false
137+ DO_RELEASE=false
138+
139+ while [ " $# " -gt 0 ]; do
140+ case " $1 " in
141+ --version)
142+ VERSION=" $2 "
143+ shift 2
144+ ;;
145+ --stage)
146+ DO_STAGE=true
147+ shift
148+ ;;
149+ --release)
150+ DO_RELEASE=true
151+ shift
152+ ;;
153+ --help)
154+ show_usage
155+ exit 0
156+ ;;
157+ * )
158+ echo " Unknown option: $1 "
159+ show_usage
160+ exit 1
161+ ;;
162+ esac
163+ done
164+
165+ # Validate arguments
166+ if [ -z " $VERSION " ]; then
167+ echo " Error: Version is required"
168+ show_usage
169+ exit 1
170+ fi
171+
172+ # Parse version into components
173+ parse_version " $VERSION "
174+
175+ # Fetch latest changes
176+ git fetch --prune
177+
178+ # Execute requested operations
179+ if [ " $DO_STAGE " = true ]; then
180+ create_stage
181+ fi
182+
183+ if [ " $DO_RELEASE " = true ]; then
184+ perform_release
185+ fi
54186
55- git tag " $1 "
56- git push origin " $1 "
57- git push github " $1 "
58- fi
187+ # If no operation specified, show usage
188+ if [ " $DO_STAGE " = false ] && [ " $DO_RELEASE " = false ]; then
189+ echo " Error: Either --stage or --release must be specified"
190+ show_usage
191+ exit 1
192+ fi
0 commit comments