11#! /usr/bin/env bash
22
3+ # Script to create platform release PRs for MetaMask
4+ # This script handles the creation of release PRs for both mobile and extension platforms
5+ # It creates two PRs:
6+ # 1. A release PR with version updates
7+ # 2. A changelog PR with updated changelog and test plan
8+
39set -e
410set -u
511set -o pipefail
612
13+ # Input validation
714PLATFORM=" ${1} "
815PREVIOUS_VERSION=" ${2} "
916NEW_VERSION=" ${3} "
1017NEW_VERSION_NUMBER=" ${4:- } "
1118
19+ # Validate required parameters
1220if [[ -z $PLATFORM ]]; then
1321 echo " Error: No platform specified."
1422 exit 1
@@ -24,8 +32,14 @@ if [[ -z $NEW_VERSION_NUMBER && $PLATFORM == "mobile" ]]; then
2432 exit 1
2533fi
2634
27- get_expected_changed_files () {
2835
36+
37+
38+ # Helper Functions
39+ # ---------------
40+
41+ # Returns a space-separated list of files that are expected to change for a given platform
42+ get_expected_changed_files () {
2943 local platform=" $1 "
3044 local expected_changed_files=" "
3145
@@ -41,37 +55,37 @@ get_expected_changed_files() {
4155 echo " $expected_changed_files "
4256}
4357
44- # Returns the release branch name to use for the given platform
58+ # Returns the release branch name based on platform and version
59+ # For all platforms: release/{version}
60+ # If TEST_ONLY=true: release-testing/{version}
4561get_release_branch_name () {
46- # Input arguments
47- local platform=" $1 " # Platform can be 'mobile' or 'extension'
48- local new_version=" $2 " # Semantic version, e.g., '12.9.2'
62+ local platform=" $1 "
63+ local new_version=" $2 "
4964
50- # Check if TEST_ONLY environment variable is set to "true"
51- # This is to run a development version of the release process without impacting downstream automation
52- if [ " $TEST_ONLY " == " true" ]; then
53- echo " release-testing/${new_version} "
54- return 0
65+ # Validate platform
66+ if [[ " $platform " != " mobile" && " $platform " != " extension" ]]; then
67+ echo " Error: Unknown platform '$platform '. Must be 'mobile' or 'extension'."
68+ exit 1
5569 fi
5670
57- # Determine the release branch name based on platform
58- if [ " $platform " == " mobile" ]; then
59- RELEASE_BRANCH_NAME=" release/${new_version} "
60- echo " ${RELEASE_BRANCH_NAME} "
61- elif [ " $platform " == " extension" ]; then
62- RELEASE_BRANCH_NAME=" Version-v${new_version} "
63- echo " ${RELEASE_BRANCH_NAME} "
64- else
65- echo " Error: Unknown platform '$platform '. Must be 'mobile' or 'extension'."
66- exit 1
71+ # Use test branch if TEST_ONLY is true
72+ if [ " $TEST_ONLY " == " true" ]; then
73+ echo " release-testing/${new_version} "
74+ return 0
6775 fi
68- }
6976
77+ # Use consistent release branch naming for all platforms
78+ echo " release/${new_version} "
79+ }
7080
81+ # Main Script
82+ # ----------
7183
84+ # Initialize branch names
7285RELEASE_BRANCH_NAME=$( get_release_branch_name $PLATFORM $NEW_VERSION )
7386CHANGELOG_BRANCH_NAME=" chore/${NEW_VERSION} -Changelog"
7487
88+ # Prepare release PR body with team sign-off checklist
7589RELEASE_BODY=" This is the release candidate for version ${NEW_VERSION} . The changelog will be found in another PR ${CHANGELOG_BRANCH_NAME} .
7690
7791 # Team sign-off checklist
@@ -91,14 +105,17 @@ RELEASE_BODY="This is the release candidate for version ${NEW_VERSION}. The chan
91105 # Reference
92106 - Testing plan sheet - https://docs.google.com/spreadsheets/d/1tsoodlAlyvEUpkkcNcbZ4PM9HuC9cEM80RZeoVv5OCQ/edit?gid=404070372#gid=404070372"
93107
108+ # Git Configuration
109+ # ----------------
94110echo " Configuring git.."
95111git config user.name metamaskbot
96112git config user.email metamaskbot@users.noreply.github.com
97113
98114echo " Fetching from remote..."
99115git fetch
100116
101- # Check out the existing release branch from the remote
117+ # Release Branch Setup
118+ # -------------------
102119echo " Checking out the release branch: ${RELEASE_BRANCH_NAME} "
103120git checkout " ${RELEASE_BRANCH_NAME} "
104121
@@ -107,38 +124,35 @@ echo "Release Branch Checked Out"
107124echo " version : ${NEW_VERSION} "
108125echo " platform : ${PLATFORM} "
109126
127+ # Version Updates
128+ # --------------
110129echo " Running version update scripts.."
111- # Bump versions for the release
112130./github-tools/.github/scripts/set-semvar-version.sh " ${NEW_VERSION} " ${PLATFORM}
113131
114- if [[ " $PLATFORM " == " mobile" ]]; then
115- ./github-tools/.github/scripts/set-mobile-build-version.sh " ${NEW_VERSION_NUMBER} "
116- fi
117-
118132
133+ # Commit Changes
134+ # -------------
119135changed_files=$( get_expected_changed_files " $PLATFORM " )
120-
121- # Echo the files to be added
122136echo " Files to be staged for commit: $changed_files "
123137
124138echo " Adding and committing changes.."
125139
126140# Track our changes
127141git add $changed_files
128142
129- # Generate a commit based on PLATFORM
143+ # Generate commit message based on platform
130144if [ " $PLATFORM " = " mobile" ]; then
131145 git commit -m " bump semvar version to ${NEW_VERSION} && build version to ${NEW_VERSION_NUMBER} "
132146elif [ " $PLATFORM " = " extension" ]; then
133147 git commit -m " bump semvar version to ${NEW_VERSION} "
134148fi
135149
136-
150+ # Push Changes and Create Release PR
151+ # ---------------------------------
137152echo " Pushing changes to the remote.."
138153git push --set-upstream origin " ${RELEASE_BRANCH_NAME} "
139154
140- echo Creating release PR..
141-
155+ echo " Creating release PR.."
142156gh pr create \
143157 --draft \
144158 --title " feat: ${NEW_VERSION} " \
@@ -147,12 +161,15 @@ gh pr create \
147161
148162echo " Release PR Created"
149163
164+ # Changelog Branch Setup
165+ # ---------------------
150166echo " Checking out ${CHANGELOG_BRANCH_NAME} "
151167git checkout -b " ${CHANGELOG_BRANCH_NAME} "
152168echo " Changelog Branch Created"
153169
170+ # Generate Changelog and Test Plan
171+ # ------------------------------
154172echo " Generating changelog via auto-changelog.."
155-
156173npx @metamask/auto-changelog@4.1.0 update --rc --repo " ${GITHUB_REPOSITORY_URL} " --currentVersion " ${NEW_VERSION} " --autoCategorize
157174
158175# Need to run from .github-tools context to inherit it's dependencies/environment
@@ -163,6 +180,7 @@ ls -ltra
163180corepack prepare yarn@4.5.1 --activate
164181# This can't be done from the actions context layer due to the upstream repository having it's own context set with yarn
165182yarn --cwd install
183+
166184echo " Generating test plan csv.."
167185yarn run gen:commits " ${PLATFORM} " " ${PREVIOUS_VERSION} " " ${RELEASE_BRANCH_NAME} " " ${PROJECT_GIT_DIR} "
168186
@@ -171,6 +189,8 @@ echo "Updating release sheet.."
171189yarn run update-release-sheet " ${PLATFORM} " " ${NEW_VERSION} " " ${GOOGLE_DOCUMENT_ID} " " ./commits.csv" " ${PROJECT_GIT_DIR} " " ${MOBILE_TEMPLATE_SHEET_ID} " " ${EXTENSION_TEMPLATE_SHEET_ID} "
172190cd ../
173191
192+ # Commit and Push Changelog Changes
193+ # -------------------------------
174194echo " Adding and committing changes.."
175195git add ./commits.csv
176196
@@ -186,7 +206,9 @@ PR_BODY="This PR updates the change log for ${NEW_VERSION} and generates the tes
186206echo " Pushing changes to the remote.."
187207git push --set-upstream origin " ${CHANGELOG_BRANCH_NAME} "
188208
189- echo Creating release PR..
209+ # Create Changelog PR
210+ # -----------------
211+ echo " Creating changelog PR.."
190212gh pr create \
191213 --draft \
192214 --title " chore: ${CHANGELOG_BRANCH_NAME} " \
0 commit comments