Skip to content

Commit ea103ad

Browse files
committed
Add release_revert script
1 parent 35f59e7 commit ea103ad

File tree

6 files changed

+370
-89
lines changed

6 files changed

+370
-89
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGELOG
22

3+
> [!NOTE]
4+
> Changes from here on align with the tagged version at surpher/PactSwiftServer
5+
36
## 1.0.0 - v1.0.0
47

58
* d08c413 - chore: Change to use updated package API

Support/Scripts/Config/config.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2034
3+
4+
# Xcode version to use
5+
# Only care about major and minor
6+
MIN_XCODE_VERSION="16.1"
7+
XCODE_VERSION_MIN_SUGGESTED="16.1"
8+
XCODE_VERSION_MIN_SUPPORTED="16.0"
9+
10+
# Project configuration
11+
CONFIGURATION_FILE="Configurations/Project-Shared.xcconfig"
12+
CHANGE_LOG="CHANGELOG.md"
13+
TAG_MESSAGE_FILE="TAG_MESSAGE_FILE.md"
14+
XCFRAMEWORK_NAME="PactSwiftMockServer.xcframework"
15+
16+
REMOTE_NAME="PactSwiftServer"
17+
RELEASE_REPO_NAME="PactSwiftServer"
18+
DEFAULT_REPO_NAME="PactSwiftMockServer"
19+
REPO_OWNER="surpher"
20+
REMOTE_REPO_BASE="[email protected]:$REPO_OWNER"

Support/Scripts/release

Lines changed: 97 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -67,41 +67,36 @@ fi
6767

6868
# "import"
6969
source "$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

7273
SHOULD_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

7977
CURRENT_BRANCH=$(git branch --show-current)
8078
RELEASE_VERSION_PART=""
8179
RELEASE_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-
9080
LATEST_TAG=$(latest_tag)
81+
CHANGE_LOG=${CHANGE_LOG:-}
82+
REMOTE_NAME=${REMOTE_NAME:-}
9183

9284
####################
9385
# Utilities
9486
####################
9587

96-
function die {
97-
echo "🚨 [ERROR] $*"
98-
echo
99-
exit 1
88+
function execute_cmd {
89+
local is_dry_run=$DRY_RUN
90+
if [ "$is_dry_run" = true ]; then
91+
echo -e "${CYAN}DRY RUN:$NOCOLOR $*"
92+
else
93+
executeCommand "$@"
94+
fi
10095
}
10196

10297
function git_clean_orphan {
10398
echo -e "🛀 Cleaning up the branch..."
104-
EXCEPT_FILES="${RELEASE_NOTES} ${XCFRAMEWORK_NAME}"
99+
EXCEPT_FILES="${CHANGE_LOG} ${XCFRAMEWORK_NAME}"
105100
EXCEPT_FILES="${EXCEPT_FILES// /|}"
106101
git ls-files | grep -v -E "$EXCEPT_FILES" | xargs git rm -f
107102
}
@@ -128,11 +123,11 @@ function git_check_remote_branch {
128123
}
129124

130125
function git_checkout_new_release_candidate_branch {
131-
local REMOTE_NAME="$1"
132-
local VERSION_BRANCH="$2"
126+
local remote_name="$1"
127+
local release_version_branch="$2"
133128

134-
git fetch "$REMOTE_NAME"
135-
git checkout --orphan "$VERSION_BRANCH"
129+
git fetch "$remote_name"
130+
git checkout --orphan "$release_version_branch"
136131
}
137132

138133
function github_open_draft_pull_request {
@@ -150,70 +145,85 @@ function github_open_draft_pull_request {
150145

151146
if command -v gh &> /dev/null; then
152147
echo "🗃️ Opening a draft pull request..."
153-
if [ "$DRY_RUN" = false ]; then
154-
for git_command in "${GIT_COMMANDS[@]}"; do
155-
echo "$git_command"
156-
eval "$git_command"
157-
done
158-
else
159-
echo "🍸 Dry run..."
160-
for git_command in "${GIT_COMMANDS[@]}"; do
161-
echo "$git_command"
162-
done
163-
fi
148+
for git_command in "${GIT_COMMANDS[@]}"; do
149+
execute_cmd "$git_command"
150+
done
164151
else
165152
echo "🤷 'gh' not installed."
166-
echo "Open https://github.com/$REPO_OWNER/$RELEASE_REPO_NAME/pulls and open one manually..."
153+
echo " Open https://github.com/$REPO_OWNER/$RELEASE_REPO_NAME/pulls and open one manually..."
154+
echo " See https://cli.github.com/ for more information..."
167155
fi
168156
}
169157

170158
function update_version_file {
171-
local MARKETING_VERSION="MARKETING_VERSION = $*"
172-
sed -i '' "2s/.*/$MARKETING_VERSION/" "$CONFIGURATION_FILE"
159+
local marketing_version="MARKETING_VERSION = $*"
160+
local config_file=$CONFIGURATION_FILE
161+
sed -i '' "2s/.*/$marketing_version/" "$config_file"
173162
}
174163

175164
function git_create_and_push_new_version {
176-
local REMOTE_NAME="$1"
177-
local REMOTE_BRANCH="$2"
178-
local RELEASE_NAME="$3"
179-
180-
local GIT_COMMANDS=(
181-
"git add ${RELEASE_NOTES} ${XCFRAMEWORK_NAME}"
182-
"git commit -S -m \"$RELEASE_NAME\""
165+
local remote_name="$1"
166+
local remote_branch="$2"
167+
local release_name="$3"
168+
local version_tag=$VERSION_TAG
169+
local change_log=$CHANGE_LOG
170+
local xcframework=$XCFRAMEWORK_NAME
171+
172+
# Generate a release changelog for github_open_draft_pull_request function to use
173+
generate_release_changelog
174+
175+
# [NOTE]: ######################################################################################
176+
# The github workflow in surpher/PactSwiftServer repo tags the release when the PR is merged!
177+
################################################################################################
178+
179+
local git_commands=(
180+
"git add ${change_log} ${xcframework}"
181+
"git commit -S -m \"$release_name\""
183182
"git stash -u"
184-
"git merge $REMOTE_NAME/main --allow-unrelated-histories -X theirs -S --no-edit"
183+
"git merge $remote_name/main --allow-unrelated-histories -X theirs -S --no-edit"
185184
"git stash pop"
186-
"git tag $VERSION_TAG -F ${TAG_MESSAGE_FILE}"
187-
"git push $REMOTE_NAME $REMOTE_BRANCH"
185+
"git push $remote_name $remote_branch"
188186
)
189187

190188
git_clean_orphan
191189

192-
if [ "$DRY_RUN" = false ]; then
193-
for command in "${GIT_COMMANDS[@]}"; do
194-
echo "$command"
195-
eval "$command"
196-
done
197-
else
198-
echo "🍸 DRY RUN..."
199-
for command in "${GIT_COMMANDS[@]}"; do
200-
echo "👻 $command"
201-
done
202-
fi
190+
for command in "${git_commands[@]}"; do
191+
execute_cmd "$command"
192+
done
203193
}
204194

205195
function cleanup {
206196
local git_clean="git clean -f -d -x"
197+
local current_branch=$CURRENT_BRANCH
198+
local release_version_branch=$VERSION_BRANCH
199+
207200
echo "🧹 Cleanning up..."
208-
echo "$git_clean"
209-
eval "$git_clean"
201+
execute_cmd "$git_clean"
202+
203+
echo "⏮️ Checking out $current_branch..."
204+
git checkout --force "$current_branch"
210205

211-
echo "⏮️ Checking out $CURRENT_BRANCH..."
212-
git checkout "$CURRENT_BRANCH"
206+
echo -e "🧹 Removing $YELLOW$release_version_branch$NOCOLOR"
207+
git branch -D "$release_version_branch"
213208
}
214209

215-
function generate_changelog {
216-
echo "📝 Generating release notes in $RELEASE_NOTES..."
210+
function generate_release_changelog {
211+
echo "📝 Generating release notes..."
212+
local release_notes_title=
213+
release_notes_title=$(head -n 1 "$CHANGE_LOG")
214+
local release_notes_existing=
215+
release_notes_existing=$(tail -n +2 "$CHANGE_LOG")
216+
217+
{
218+
echo "$release_notes_title"
219+
echo
220+
cat "${TAG_MESSAGE_FILE}"
221+
echo "$release_notes_existing"
222+
} > "$CHANGE_LOG"
223+
}
224+
225+
function update_pactswiftmockserver_changelog {
226+
echo "📝 Generating release notes in $CHANGE_LOG..."
217227

218228
# Prepare the title for this release
219229
echo "## ${VERSION_TAG}" > "${TAG_MESSAGE_FILE}"
@@ -223,28 +233,30 @@ function generate_changelog {
223233
echo -e "🪵 Logging '${LATEST_TAG}..HEAD'..."
224234
git log --pretty='* %h - %s (%an)' "${LATEST_TAG}"..HEAD >> "${TAG_MESSAGE_FILE}"
225235

226-
RELEASE_NOTES_TITLE=$(head -n 1 "$RELEASE_NOTES")
227-
RELEASE_NOTES_EXISTING=$(tail -n +2 "$RELEASE_NOTES")
236+
local release_notes_title=
237+
release_notes_title=$(head -n 1 "$CHANGE_LOG")
238+
local release_notes_existing=
239+
release_notes_existing=$(tail -n +2 "$CHANGE_LOG")
228240

229241
# Inject the new commits between title and last release
230242
{
231-
echo "$RELEASE_NOTES_TITLE"
243+
echo "$release_notes_title"
232244
echo
233245
cat "${TAG_MESSAGE_FILE}"
234-
echo "$RELEASE_NOTES_EXISTING"
235-
} > "$RELEASE_NOTES"
246+
echo "$release_notes_existing"
247+
} > "$CHANGE_LOG"
236248
}
237249

238250
function git_commit_changelog_and_xcconfig {
239251
local marketing_version="${MARKETING_VERSION:-1}"
240-
echo "🩹 Committing $RELEASE_NOTES to git..."
241-
git add "${RELEASE_NOTES}" "${CONFIGURATION_FILE}"
252+
echo "🩹 Committing $CHANGE_LOG to git..."
253+
git add "${CHANGE_LOG}" "${CONFIGURATION_FILE}"
242254
git commit -m "$marketing_version: Release notes"
243255
}
244256

245257
function git_reset_changelog {
246-
echo "🔙 Resetting last commit"
247-
git reset --soft HEAD~1
258+
echo "🔙 Dropping last commit..."
259+
git reset --hard HEAD~1
248260
git status
249261
}
250262

@@ -256,24 +268,30 @@ function git_push_changelog {
256268
##################
257269
# Pre-checks
258270
##################
259-
while getopts ":v:d:-:" opt; do
271+
while getopts ":v:d:h:-:" opt; do
260272
case ${opt} in
261273
v)
262274
RELEASE_VERSION_PART=$OPTARG
263275
;;
264276
d)
265277
RELEASE_DESCRIPTION=$OPTARG
266278
;;
279+
h)
280+
show_help
281+
;;
267282
-)
268283
case "${OPTARG}" in
269284
dry-run)
270285
DRY_RUN=true
271-
shift 2
286+
shift
272287
;;
273288
description)
274289
RELEASE_DESCRIPTION=$1
275290
shift 2
276291
;;
292+
help)
293+
show_help
294+
;;
277295
*)
278296
echo "Invalid option: --${OPTARG}" >&2
279297
show_help
@@ -309,10 +327,10 @@ echo "🌎 Adding '$REMOTE_NAME' remote..."
309327
git_add_remote "$REMOTE_NAME" "$REMOTE_REPO_BASE/$RELEASE_REPO_NAME.git"
310328

311329
# Generate release notes
312-
echo "📝 Generate changelog"
313-
generate_changelog
330+
echo "📝 Update changelog for PactSwiftMockServer"
331+
update_pactswiftmockserver_changelog
314332

315-
# Bump up the MARKETING_VERSION in xcconfig
333+
# Bump up the MARKETING_VERSION in xcconfig so XCFramework uses the right version
316334
echo -e "👊 Bumping up MARKETING_VERSION in xcconfig to $MARKETING_VERSION..."
317335
update_version_file "$MARKETING_VERSION"
318336

@@ -345,12 +363,12 @@ github_open_draft_pull_request "$MARKETING_VERSION" "$VERSION_BRANCH"
345363
# Cleanup
346364
##################
347365
if [ "$DRY_RUN" = true ]; then
348-
cmd="git checkout --force $CURRENT_BRANCH"
366+
cmd="git clean -f -d -x && git checkout --force $CURRENT_BRANCH"
349367
echo "🍸 Dry run done"
350368
read -r -p "Clean up what has been generated during dry run? [Y/n]" -n 1 USER_INPUT
351369
echo
352370
if [[ $USER_INPUT =~ ^[Yy]$ ]]; then
353-
eval "$cmd"
371+
execute_cmd "$cmd"
354372
git_reset_changelog
355373
else
356374
echo "🙌 Leaving everything that's been generated during dry run as is..."

0 commit comments

Comments
 (0)