6767
6868# "import"
6969source " $RELEASE_SOURCE_DIR /utils.sh"
70- source " $RELEASE_SOURCE_DIR /CI/version_numbers"
70+ source " $RELEASE_SOURCE_DIR /CI/version_numbers.sh"
71+ source " $RELEASE_SOURCE_DIR /Config/config.sh"
7172
7273SHOULD_BUILD_RUST_BIN=${SHOULD_BUILD_RUST_BIN:- true}
7374
74- CONFIGURATION_FILE=" Configurations/Project-Shared.xcconfig"
75- RELEASE_NOTES=" CHANGELOG.md"
76- TAG_MESSAGE_FILE=" TAG_MESSAGE_FILE.md"
77- XCFRAMEWORK_NAME=" PactSwiftMockServer.xcframework"
75+ DRY_RUN=false
7876
7977CURRENT_BRANCH=$( git branch --show-current)
8078RELEASE_VERSION_PART=" "
8179RELEASE_DESCRIPTION=" "
82- DRY_RUN=false
83-
84- REMOTE_NAME=" releases"
85- RELEASE_REPO_NAME=" PactSwiftServer"
86- DEFAULT_REPO_NAME=" PactSwiftMockServer"
87- REPO_OWNER=" surpher"
88- REMOTE_REPO_BASE=
" [email protected] :$REPO_OWNER " 89-
9080LATEST_TAG=$( latest_tag)
9181
9282# ###################
9383# Utilities
9484# ###################
9585
96- function die {
97- echo " 🚨 [ERROR] $* "
98- echo
99- exit 1
100- }
101-
10286function git_clean_orphan {
10387 echo -e " 🛀 Cleaning up the branch..."
104- EXCEPT_FILES=" ${RELEASE_NOTES } ${XCFRAMEWORK_NAME} "
88+ EXCEPT_FILES=" ${CHANGE_LOG } ${XCFRAMEWORK_NAME} "
10589 EXCEPT_FILES=" ${EXCEPT_FILES// / |} "
10690 git ls-files | grep -v -E " $EXCEPT_FILES " | xargs git rm -f
10791}
@@ -163,7 +147,8 @@ function github_open_draft_pull_request {
163147 fi
164148 else
165149 echo " 🤷 'gh' not installed."
166- echo " Open https://github.com/$REPO_OWNER /$RELEASE_REPO_NAME /pulls and open one manually..."
150+ echo " Open https://github.com/$REPO_OWNER /$RELEASE_REPO_NAME /pulls and open one manually..."
151+ echo " See https://cli.github.com/ for more information..."
167152 fi
168153}
169154
@@ -177,8 +162,10 @@ function git_create_and_push_new_version {
177162 local REMOTE_BRANCH=" $2 "
178163 local RELEASE_NAME=" $3 "
179164
165+ generate_changelog
166+
180167 local GIT_COMMANDS=(
181- " git add ${RELEASE_NOTES } ${XCFRAMEWORK_NAME} "
168+ " git add ${CHANGE_LOG } ${XCFRAMEWORK_NAME} "
182169 " git commit -S -m \" $RELEASE_NAME \" "
183170 " git stash -u"
184171 " git merge $REMOTE_NAME /main --allow-unrelated-histories -X theirs -S --no-edit"
@@ -204,16 +191,20 @@ function git_create_and_push_new_version {
204191
205192function cleanup {
206193 local git_clean=" git clean -f -d -x"
194+
207195 echo " 🧹 Cleanning up..."
208196 echo " $git_clean "
209197 eval " $git_clean "
210198
211199 echo " ⏮️ Checking out $CURRENT_BRANCH ..."
212- git checkout " $CURRENT_BRANCH "
200+ git checkout --force " $CURRENT_BRANCH "
201+
202+ echo " 🧹 Removing $YELLOW$VERSION_BRANCH$NOCOLOR "
203+ git branch -D " $VERSION_BRANCH "
213204}
214205
215206function generate_changelog {
216- echo " 📝 Generating release notes in $RELEASE_NOTES ..."
207+ echo " 📝 Generating release notes in $CHANGE_LOG ..."
217208
218209 # Prepare the title for this release
219210 echo " ## ${VERSION_TAG} " > " ${TAG_MESSAGE_FILE} "
@@ -223,28 +214,30 @@ function generate_changelog {
223214 echo -e " 🪵 Logging '${LATEST_TAG} ..HEAD'..."
224215 git log --pretty=' * %h - %s (%an)' " ${LATEST_TAG} " ..HEAD >> " ${TAG_MESSAGE_FILE} "
225216
226- RELEASE_NOTES_TITLE=$( head -n 1 " $RELEASE_NOTES " )
227- RELEASE_NOTES_EXISTING=$( tail -n +2 " $RELEASE_NOTES " )
217+ local RELEASE_NOTES_TITLE=
218+ RELEASE_NOTES_TITLE=$( head -n 1 " $CHANGE_LOG " )
219+ local RELEASE_NOTES_EXISTING=
220+ RELEASE_NOTES_EXISTING=$( tail -n +2 " $CHANGE_LOG " )
228221
229222 # Inject the new commits between title and last release
230223 {
231224 echo " $RELEASE_NOTES_TITLE "
232225 echo
233226 cat " ${TAG_MESSAGE_FILE} "
234227 echo " $RELEASE_NOTES_EXISTING "
235- } > " $RELEASE_NOTES "
228+ } > " $CHANGE_LOG "
236229}
237230
238231function git_commit_changelog_and_xcconfig {
239232 local marketing_version=" ${MARKETING_VERSION:- 1} "
240- echo " 🩹 Committing $RELEASE_NOTES to git..."
241- git add " ${RELEASE_NOTES } " " ${CONFIGURATION_FILE} "
233+ echo " 🩹 Committing $CHANGE_LOG to git..."
234+ git add " ${CHANGE_LOG } " " ${CONFIGURATION_FILE} "
242235 git commit -m " $marketing_version : Release notes"
243236}
244237
245238function git_reset_changelog {
246- echo " 🔙 Resetting last commit"
247- git reset --soft HEAD~1
239+ echo " 🔙 Dropping last commit... "
240+ git reset --hard HEAD~1
248241 git status
249242}
250243
@@ -256,24 +249,30 @@ function git_push_changelog {
256249# #################
257250# Pre-checks
258251# #################
259- while getopts " :v:d:-:" opt; do
252+ while getopts " :v:d:h: -:" opt; do
260253 case ${opt} in
261254 v)
262255 RELEASE_VERSION_PART=$OPTARG
263256 ;;
264257 d)
265258 RELEASE_DESCRIPTION=$OPTARG
266259 ;;
260+ h)
261+ show_help
262+ ;;
267263 -)
268264 case " ${OPTARG} " in
269265 dry-run)
270266 DRY_RUN=true
271- shift 2
267+ shift
272268 ;;
273269 description)
274270 RELEASE_DESCRIPTION=$1
275271 shift 2
276272 ;;
273+ help)
274+ show_help
275+ ;;
277276 * )
278277 echo " Invalid option: --${OPTARG} " >&2
279278 show_help
@@ -312,7 +311,7 @@ git_add_remote "$REMOTE_NAME" "$REMOTE_REPO_BASE/$RELEASE_REPO_NAME.git"
312311echo " 📝 Generate changelog"
313312generate_changelog
314313
315- # Bump up the MARKETING_VERSION in xcconfig
314+ # Bump up the MARKETING_VERSION in xcconfig so XCFramework uses the right version
316315echo -e " 👊 Bumping up MARKETING_VERSION in xcconfig to $MARKETING_VERSION ..."
317316update_version_file " $MARKETING_VERSION "
318317
@@ -345,7 +344,7 @@ github_open_draft_pull_request "$MARKETING_VERSION" "$VERSION_BRANCH"
345344# Cleanup
346345# #################
347346if [ " $DRY_RUN " = true ]; then
348- cmd=" git checkout --force $CURRENT_BRANCH "
347+ cmd=" git clean -f -d -x && git checkout --force $CURRENT_BRANCH "
349348 echo " 🍸 Dry run done"
350349 read -r -p " Clean up what has been generated during dry run? [Y/n]" -n 1 USER_INPUT
351350 echo
0 commit comments