1717# new_version_number - Build version for mobile platform (optional, required for mobile)
1818# git_user_name - Git user name for commits (optional, defaults to 'metamaskbot')
1919# git_user_email - Git user email for commits (optional, defaults to '[email protected] ')20+ #
21+ # Environment:
22+ # BASE_BRANCH - The base branch for the release PR (defaults to 'main')
23+ # GITHUB_TOKEN - Token for GitHub CLI operations (falls back to gh auth config)
24+ # TEST_ONLY - When set to "true", uses test branch prefixes and skips changelog PR
25+ # GITHUB_REPOSITORY_URL - Full HTTPS URL for the repository (required for changelog generation when TEST_ONLY is not "true")
2026
2127set -e
2228set -u
2329set -o pipefail
2430
31+ # Sourcing helper functions
32+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
33+ # shellcheck source=.github/scripts/utils.sh
34+ source " ${SCRIPT_DIR} /utils.sh"
35+
2536# Input assignments (quoted args prevent shifting). Use defaults only for optional args.
2637PLATFORM=" ${1} "
2738PREVIOUS_VERSION_REF=" ${2:- } "
@@ -32,6 +43,7 @@ NEW_VERSION="${NEW_VERSION//[[:space:]]/}"
3243NEW_VERSION_NUMBER=" ${4:- } "
3344GIT_USER_NAME=" ${5:- metamaskbot} "
3445GIT_USER_EMAIL=" ${6:- metamaskbot@ users.noreply.github.com} "
46+ BASE_BRANCH=" ${BASE_BRANCH:- main} "
3547
3648# Log assigned variables for debugging (after defaults and trimming)
3749echo " Assigned variables:"
@@ -127,101 +139,6 @@ get_version_bump_branch_name() {
127139# Main workflow functions
128140# -----------------------
129141
130- # Helper function to check if branch exists and checkout/create it
131- checkout_or_create_branch () {
132- local branch_name=" $1 "
133- local base_branch=" ${2:- } " # Optional base branch for new branches
134-
135- echo " Checking for existing branch ${branch_name} "
136-
137- if git show-ref --verify --quiet " refs/heads/${branch_name} " || git ls-remote --heads origin " ${branch_name} " | grep -q " ${branch_name} " ; then
138- echo " Branch ${branch_name} already exists, checking it out"
139- if git ls-remote --heads origin " ${branch_name} " | grep -q " ${branch_name} " ; then
140- git fetch origin " ${branch_name} "
141- git checkout " ${branch_name} "
142- else
143- git checkout " ${branch_name} "
144- fi
145- else
146- echo " Creating new branch ${branch_name} "
147- if [[ -n " $base_branch " ]]; then
148- git checkout " $base_branch "
149- git pull origin " $base_branch "
150- fi
151- git checkout -b " ${branch_name} "
152- fi
153-
154- echo " Branch ${branch_name} ready"
155- }
156-
157- # Helper function to push branch with error handling
158- push_branch_with_handling () {
159- local branch_name=" $1 "
160-
161- echo " Pushing changes to the remote.."
162- if ! git push --set-upstream origin " ${branch_name} " ; then
163- echo " No changes to push to ${branch_name} "
164- # Check if branch exists remotely
165- if git ls-remote --heads origin " ${branch_name} " | grep -q " ${branch_name} " ; then
166- echo " Branch ${branch_name} already exists remotely"
167- else
168- echo " Error: Failed to push and branch doesn't exist remotely"
169- exit 1
170- fi
171- fi
172- }
173-
174- # Helper function to create PR if it doesn't exist
175- create_pr_if_not_exists () {
176- local branch_name=" $1 "
177- local title=" $2 "
178- local body=" $3 "
179- local base_branch=" ${4:- main} "
180- local labels=" ${5:- } "
181- local search_method=" ${6:- head} " # "head" or "search"
182-
183- echo " Creating PR for ${branch_name} .."
184-
185- # Check if PR already exists using different methods
186- local pr_exists=false
187- if [[ " $search_method " == " search" ]]; then
188- if gh pr list --search " head:${branch_name} " --json number --jq ' length' | grep -q " 1" ; then
189- pr_exists=true
190- fi
191- else
192- if gh pr list --head " ${branch_name} " --json number --jq ' length' | grep -q " 1" ; then
193- pr_exists=true
194- fi
195- fi
196-
197- if $pr_exists ; then
198- echo " PR for branch ${branch_name} already exists"
199- else
200- # Build command array with conditional label inclusion
201- local gh_cmd=(gh pr create --draft --title " ${title} " --body " ${body} " --base " ${base_branch} " --head " ${branch_name} " )
202-
203- # Add labels only if provided (GitHub CLI doesn't accept empty label values)
204- if [[ -n " ${labels:- } " ]]; then
205- gh_cmd+=(--label " ${labels} " )
206- fi
207-
208- # Execute the command
209- # echo "Executing: ${gh_cmd[@]}"
210- " ${gh_cmd[@]} "
211- echo " PR Created: ${title} "
212- fi
213- }
214-
215- # Configure git for automation
216- configure_git () {
217- echo " Configuring git.."
218- git config user.name " ${GIT_USER_NAME} "
219- git config user.email " ${GIT_USER_EMAIL} "
220-
221- echo " Fetching from remote..."
222- git fetch
223- }
224-
225142# Create release branch, update versions, and create PR
226143create_release_pr () {
227144 local platform=" $1 "
@@ -231,7 +148,7 @@ create_release_pr() {
231148 local changelog_branch_name=" $5 "
232149
233150 echo " Checking out the release branch: ${release_branch_name} "
234- git checkout " ${release_branch_name} "
151+ checkout_or_create_branch " ${release_branch_name} " " ${BASE_BRANCH }"
235152
236153 echo " Release Branch Checked Out"
237154 echo " version : ${new_version} "
@@ -342,19 +259,6 @@ create_changelog_pr() {
342259 local release_branch_name=" $4 "
343260 local changelog_branch_name=" $5 "
344261
345- # Use helper function for branch checkout/creation
346- checkout_or_create_branch " ${changelog_branch_name} "
347-
348- # Generate Changelog and Test Plan
349- echo " Generating changelog for ${platform} .."
350- yarn auto-changelog update --rc \
351- --repo " ${GITHUB_REPOSITORY_URL} " \
352- --currentVersion " ${new_version} " \
353- --autoCategorize \
354- --useChangelogEntry \
355- --useShortPrLink \
356- --requirePrNumbers
357-
358262 # Skip commits.csv for hotfix releases (previous_version_ref is literal "null")
359263 # - When we create a new major/minor release, we fetch all commits included in the release, by fetching the diff between HEAD and previous version reference.
360264 # - When we create a new hotfix release, there are no commits included in the release by default (they will be cherry-picked one by one). So we don't have previous version reference, which is why the value is set to 'null'.
@@ -399,33 +303,22 @@ create_changelog_pr() {
399303 cd ../
400304 fi
401305
402- # Skipping Google Sheets update since there is no need for it anymore
403- # TODO: Remove this once the current post-main validation approach is stable
404- # if [[ "${TEST_ONLY:-false}" == 'false' ]]; then
405- # echo "Updating release sheet.."
406- # # Create a new Release Sheet Page for the new version with our commits.csv content
407- # yarn run update-release-sheet "${platform}" "${new_version}" "${GOOGLE_DOCUMENT_ID}" "./commits.csv" "${PROJECT_GIT_DIR}" "${MOBILE_TEMPLATE_SHEET_ID}" "${EXTENSION_TEMPLATE_SHEET_ID}"
408- # fi
409- # Note: Only change directories when we actually entered ./github-tools/
410-
411- # Commit and Push Changelog Changes (exclude commits.csv)
412- echo " Adding and committing changes.."
413- local commit_msg=" update changelog for ${new_version} "
414- if [[ " ${previous_version_ref,,} " == " null" ]]; then
415- commit_msg=" ${commit_msg} (hotfix - no test plan)"
416- fi
417- if ! (git commit -am " ${commit_msg} " ); then
418- echo " No changes detected; skipping commit."
419- fi
420-
421- local pr_body=" This PR updates the change log for ${new_version} ."
422- if [[ " ${previous_version_ref,,} " == " null" ]]; then
423- pr_body=" ${pr_body} (Hotfix - no test plan generated.)"
424- fi
425-
426- # Use helper functions for push and PR creation
427- push_branch_with_handling " ${changelog_branch_name} "
428- create_pr_if_not_exists " ${changelog_branch_name} " " release: ${changelog_branch_name} " " ${pr_body} " " ${release_branch_name} " " " " search"
306+ # Delegate changelog update and PR creation to the shared update-release-changelog.sh script
307+ echo " Updating changelog and creating PR.."
308+
309+ # Export git identity for the shared script
310+ export GIT_AUTHOR_NAME=" ${GIT_USER_NAME} "
311+ export GIT_AUTHOR_EMAIL=" ${GIT_USER_EMAIL} "
312+
313+ # Call the shared script
314+ # The script is located in the same directory as this one
315+ " ${SCRIPT_DIR} /update-release-changelog.sh" \
316+ " ${release_branch_name} " \
317+ " ${platform} " \
318+ " ${GITHUB_REPOSITORY_URL} " \
319+ " ${previous_version_ref} " \
320+ " ${changelog_branch_name} " \
321+ " ${new_version} "
429322
430323 echo " Changelog PR Ready"
431324}
@@ -547,7 +440,7 @@ main() {
547440 release_branch_name=$( get_release_branch_name " $NEW_VERSION " )
548441 changelog_branch_name=" release/${NEW_VERSION} -Changelog"
549442 version_bump_branch_name=$( get_version_bump_branch_name " $next_version " ) # Execute main workflow
550- configure_git
443+ configure_git " ${GIT_USER_NAME} " " ${GIT_USER_EMAIL} "
551444
552445 # Step 1: Create release branch and PR
553446 create_release_pr " $PLATFORM " " $NEW_VERSION " " $NEW_VERSION_NUMBER " " $release_branch_name " " $changelog_branch_name "
0 commit comments