Skip to content

Commit 8f7f267

Browse files
committed
feat(gh-action): align version management mobile and extension
These changes are for unifying the release process between extension and mobile, including made the same release version branch, which is different at the moment. It will create `"release/${new_version}"` branches as a pattern.
1 parent eeb5a4a commit 8f7f267

2 files changed

Lines changed: 98 additions & 56 deletions

File tree

.github/scripts/create-platform-release-pr.sh

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
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+
39
set -e
410
set -u
511
set -o pipefail
612

13+
# Input validation
714
PLATFORM="${1}"
815
PREVIOUS_VERSION="${2}"
916
NEW_VERSION="${3}"
1017
NEW_VERSION_NUMBER="${4:-}"
1118

19+
# Validate required parameters
1220
if [[ -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
2533
fi
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}
4561
get_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
7285
RELEASE_BRANCH_NAME=$(get_release_branch_name $PLATFORM $NEW_VERSION)
7386
CHANGELOG_BRANCH_NAME="chore/${NEW_VERSION}-Changelog"
7487

88+
# Prepare release PR body with team sign-off checklist
7589
RELEASE_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+
# ----------------
94110
echo "Configuring git.."
95111
git config user.name metamaskbot
96112
git config user.email metamaskbot@users.noreply.github.com
97113

98114
echo "Fetching from remote..."
99115
git fetch
100116

101-
# Check out the existing release branch from the remote
117+
# Release Branch Setup
118+
# -------------------
102119
echo "Checking out the release branch: ${RELEASE_BRANCH_NAME}"
103120
git checkout "${RELEASE_BRANCH_NAME}"
104121

@@ -107,38 +124,35 @@ echo "Release Branch Checked Out"
107124
echo "version : ${NEW_VERSION}"
108125
echo "platform : ${PLATFORM}"
109126

127+
# Version Updates
128+
# --------------
110129
echo "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+
# -------------
119135
changed_files=$(get_expected_changed_files "$PLATFORM")
120-
121-
# Echo the files to be added
122136
echo "Files to be staged for commit: $changed_files"
123137

124138
echo "Adding and committing changes.."
125139

126140
# Track our changes
127141
git add $changed_files
128142

129-
# Generate a commit based on PLATFORM
143+
# Generate commit message based on platform
130144
if [ "$PLATFORM" = "mobile" ]; then
131145
git commit -m "bump semvar version to ${NEW_VERSION} && build version to ${NEW_VERSION_NUMBER}"
132146
elif [ "$PLATFORM" = "extension" ]; then
133147
git commit -m "bump semvar version to ${NEW_VERSION}"
134148
fi
135149

136-
150+
# Push Changes and Create Release PR
151+
# ---------------------------------
137152
echo "Pushing changes to the remote.."
138153
git push --set-upstream origin "${RELEASE_BRANCH_NAME}"
139154

140-
echo Creating release PR..
141-
155+
echo "Creating release PR.."
142156
gh pr create \
143157
--draft \
144158
--title "feat: ${NEW_VERSION}" \
@@ -147,12 +161,15 @@ gh pr create \
147161

148162
echo "Release PR Created"
149163

164+
# Changelog Branch Setup
165+
# ---------------------
150166
echo "Checking out ${CHANGELOG_BRANCH_NAME}"
151167
git checkout -b "${CHANGELOG_BRANCH_NAME}"
152168
echo "Changelog Branch Created"
153169

170+
# Generate Changelog and Test Plan
171+
# ------------------------------
154172
echo "Generating changelog via auto-changelog.."
155-
156173
npx @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
163180
corepack 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
165182
yarn --cwd install
183+
166184
echo "Generating test plan csv.."
167185
yarn run gen:commits "${PLATFORM}" "${PREVIOUS_VERSION}" "${RELEASE_BRANCH_NAME}" "${PROJECT_GIT_DIR}"
168186

@@ -171,6 +189,8 @@ echo "Updating release sheet.."
171189
yarn run update-release-sheet "${PLATFORM}" "${NEW_VERSION}" "${GOOGLE_DOCUMENT_ID}" "./commits.csv" "${PROJECT_GIT_DIR}" "${MOBILE_TEMPLATE_SHEET_ID}" "${EXTENSION_TEMPLATE_SHEET_ID}"
172190
cd ../
173191

192+
# Commit and Push Changelog Changes
193+
# -------------------------------
174194
echo "Adding and committing changes.."
175195
git add ./commits.csv
176196

@@ -186,7 +206,9 @@ PR_BODY="This PR updates the change log for ${NEW_VERSION} and generates the tes
186206
echo "Pushing changes to the remote.."
187207
git push --set-upstream origin "${CHANGELOG_BRANCH_NAME}"
188208

189-
echo Creating release PR..
209+
# Create Changelog PR
210+
# -----------------
211+
echo "Creating changelog PR.."
190212
gh pr create \
191213
--draft \
192214
--title "chore: ${CHANGELOG_BRANCH_NAME}" \

.github/scripts/set-semvar-version.sh

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,97 @@
11
#!/usr/bin/env bash
22

3+
# Script to update semantic versioning across MetaMask platform files
4+
# This script handles version updates for both mobile and extension platforms
5+
# For mobile: Updates package.json, Android build.gradle, Bitrise config, and iOS project files
6+
# For extension: Updates package.json only
7+
38
set -e
49
set -u
510
set -o pipefail
611

7-
# Check if exactly 2 arguments are provided
12+
# Input validation
813
if [[ $# -ne 2 ]]; then
9-
echo "Usage: $0 <new_semvar_version>"
14+
echo "Usage: $0 <new_semvar_version> <platform>"
1015
exit 1
1116
fi
1217

18+
# Script parameters
1319
SEMVER_VERSION=$1
1420
PLATFORM=$2
1521

16-
NAT='0|[1-9][0-9]*'
17-
ALPHANUM='[0-9]*[A-Za-z-][0-9A-Za-z-]*'
18-
IDENT="$NAT|$ALPHANUM"
19-
FIELD='[0-9A-Za-z-]+'
22+
# Regular expression patterns for semantic version validation
23+
NAT='0|[1-9][0-9]*' # Non-negative integer
24+
ALPHANUM='[0-9]*[A-Za-z-][0-9A-Za-z-]*' # Alphanumeric identifier
25+
IDENT="$NAT|$ALPHANUM" # Identifier (number or alphanumeric)
26+
FIELD='[0-9A-Za-z-]+' # Field (alphanumeric with hyphens)
2027

28+
# Full semantic version regex pattern
29+
# Matches: v1.2.3-alpha.1+build.123
2130
SEMVER_REGEX="\
2231
^[vV]?\
2332
($NAT)\\.($NAT)\\.($NAT)\
2433
(\\-(${IDENT})(\\.(${IDENT}))*)?\
2534
(\\+${FIELD}(\\.${FIELD})*)?$"
2635

36+
# File paths for version updates
2737
PACKAGE_JSON_FILE=package.json
2838
ANDROID_BUILD_GRADLE_FILE=android/app/build.gradle
2939
BITRISE_YML_FILE=bitrise.yml
3040
IOS_PROJECT_FILE=ios/MetaMask.xcodeproj/project.pbxproj
3141

42+
# Helper Functions
43+
# ---------------
44+
45+
# Converts semantic version to numeric format (e.g., 1.2.3 -> 123)
3246
semver_to_nat () {
3347
echo "${1//./}"
3448
}
3549

50+
# Logs error message and exits with status code 1
3651
log_and_exit () {
3752
echo "$1" && exit 1
3853
}
3954

55+
# Updates version in package.json using jq
4056
package_json() {
41-
42-
# update package.json
57+
# Create temporary file for jq operation
4358
tmp="${PACKAGE_JSON_FILE}_temp"
4459
jq ".version = \"$SEMVER_VERSION\"" $PACKAGE_JSON_FILE > "$tmp"
4560
mv "$tmp" $PACKAGE_JSON_FILE
4661
echo "- $PACKAGE_JSON_FILE updated"
47-
4862
}
4963

64+
# Updates version in mobile-specific files
65+
# Handles both macOS and Linux environments
5066
update_mobile_files () {
51-
5267
# Check operating system and execute platform-specific sed commands
5368
if [[ "$OSTYPE" == "darwin"* ]]; then
54-
# macOS
55-
56-
# update android/app/build.gradle
69+
# macOS specific updates
70+
71+
# Update Android version in build.gradle
5772
echo "Updating Android build.gradle file..."
5873
sed -i '' 's/\(\s*versionName \)".*"/\1"'"$SEMVER_VERSION"'"/' "$ANDROID_BUILD_GRADLE_FILE"
5974
echo "- $ANDROID_BUILD_GRADLE_FILE successfully updated"
6075

61-
# update bitrise.yml
76+
# Update version in Bitrise configuration
6277
echo "Updating Bitrise configuration files..."
6378
sed -i '' 's/\(\s*VERSION_NAME: \).*/\1'"$SEMVER_VERSION"'/' "$BITRISE_YML_FILE"
6479
echo "- $BITRISE_YML_FILE successfully updated"
6580

81+
# Update iOS marketing version
6682
echo "Updating iOS project settings..."
6783
sed -i '' 's/\(\s*MARKETING_VERSION = \).*/\1'"$SEMVER_VERSION;"'/' "$IOS_PROJECT_FILE"
6884
echo "- $IOS_PROJECT_FILE successfully updated"
6985

7086
else
71-
# Linux
72-
73-
# update android/app/build.gradle
87+
# Linux specific updates
88+
89+
# Update Android version in build.gradle
7490
echo "Updating Android build.gradle file..."
7591
sed -i 's/\(\s*versionName \)".*"/\1"'"$SEMVER_VERSION"'"/' "$ANDROID_BUILD_GRADLE_FILE"
7692
echo "- $ANDROID_BUILD_GRADLE_FILE updated"
7793

78-
# update bitrise.yml
94+
# Update version in Bitrise configuration
7995
echo "Updating Bitrise configuration files..."
8096
sed -i 's/\(\s*VERSION_NAME: \).*/\1'"$SEMVER_VERSION"'/' "$BITRISE_YML_FILE"
8197
echo "- $BITRISE_YML_FILE updated"
@@ -84,9 +100,9 @@ update_mobile_files () {
84100
echo "Updating iOS project settings..."
85101
sed -i 's/\(\s*MARKETING_VERSION = \).*/\1'"$SEMVER_VERSION;"'/' "$IOS_PROJECT_FILE"
86102
echo "- $IOS_PROJECT_FILE updated"
87-
88103
fi
89104

105+
# Print summary of updates
90106
echo "- $ANDROID_BUILD_GRADLE_FILE updated"
91107
echo "- $BITRISE_YML_FILE updated"
92108
echo "- $IOS_PROJECT_FILE updated"
@@ -96,12 +112,15 @@ update_mobile_files () {
96112
echo "SEMVER version: $SEMVER_VERSION"
97113
}
98114

99-
# abort if values are empty
115+
# Main Script
116+
# ----------
117+
118+
# Validate input parameters
100119
if [[ -z $SEMVER_VERSION ]]; then
101120
log_and_exit "SEMVER_VERSION not specified, aborting!"
102121
fi
103122

104-
# check if SEMVER_VERSION is not valid semver
123+
# Validate semantic version format
105124
if ! [[ $SEMVER_VERSION =~ $SEMVER_REGEX ]]; then
106125
log_and_exit "$SEMVER_VERSION is invalid semver!"
107126
fi
@@ -114,6 +133,7 @@ echo "Updating files:"
114133
# Update the version in the package.json file
115134
package_json
116135

136+
# Platform-specific updates
117137
if [[ $PLATFORM == "mobile" ]]; then
118138
update_mobile_files
119139
fi

0 commit comments

Comments
 (0)