Skip to content

Commit 437da63

Browse files
alucardzomCopilot
andauthored
feat(gh-action): align version management mobile and extension (#73)
* 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. * chore: add conditional for updating the spreadsheet For testing, we don't wanna execute the spreadsheet step, just create the commits csv file. * chore: set ref code to call * chore: conditional to skip update GC document * chore: improve conditionals To allow to re-run the workflow, in case there aren't changes to push to remote * chore: check if pr already exists * chore: improve inputs * chore: restore step removed for test * chore: remove repeated steps, and improve script This will tackle the same things for mobile and extensions, adding the conditionals to execute mobile specific steps * chore: control changelog branch already exists on remote * chore: more checks * chore(inputs): print inputs values * chore: fix linter and remove unused commented lines * chore: update .github/scripts/create-platform-release-pr.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 1c38c80 commit 437da63

3 files changed

Lines changed: 195 additions & 82 deletions

File tree

Lines changed: 114 additions & 58 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,52 +124,78 @@ 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
131-
git commit -m "bump semvar version to ${NEW_VERSION} && build version to ${NEW_VERSION_NUMBER}"
145+
if ! git commit -m "bump semvar version to ${NEW_VERSION} && build version to ${NEW_VERSION_NUMBER}"; then
146+
echo "No changes to commit for mobile version bump"
147+
fi
132148
elif [ "$PLATFORM" = "extension" ]; then
133-
git commit -m "bump semvar version to ${NEW_VERSION}"
149+
if ! git commit -m "bump semvar version to ${NEW_VERSION}"; then
150+
echo "No changes to commit for extension version bump"
151+
fi
134152
fi
135153

136-
154+
# Push Changes and Create Release PR
155+
# ---------------------------------
137156
echo "Pushing changes to the remote.."
138-
git push --set-upstream origin "${RELEASE_BRANCH_NAME}"
139-
140-
echo Creating release PR..
141-
142-
gh pr create \
143-
--draft \
144-
--title "feat: ${NEW_VERSION}" \
145-
--body "${RELEASE_BODY}" \
146-
--head "${RELEASE_BRANCH_NAME}";
157+
if ! git push --set-upstream origin "${RELEASE_BRANCH_NAME}"; then
158+
echo "No changes to push to ${RELEASE_BRANCH_NAME}"
159+
# Check if branch exists remotely
160+
if git ls-remote --heads origin "${RELEASE_BRANCH_NAME}" | grep -q "${RELEASE_BRANCH_NAME}"; then
161+
echo "Branch ${RELEASE_BRANCH_NAME} already exists remotely"
162+
else
163+
echo "Error: Failed to push and branch doesn't exist remotely"
164+
exit 1
165+
fi
166+
fi
147167

148-
echo "Release PR Created"
168+
echo "Creating release PR.."
169+
# Check if PR already exists
170+
if gh pr list --head "${RELEASE_BRANCH_NAME}" --json number --jq 'length' | grep -q "1"; then
171+
echo "PR for branch ${RELEASE_BRANCH_NAME} already exists"
172+
else
173+
gh pr create \
174+
--draft \
175+
--title "feat: ${NEW_VERSION}" \
176+
--body "${RELEASE_BODY}" \
177+
--head "${RELEASE_BRANCH_NAME}"
178+
echo "Release PR Created"
179+
fi
149180

150-
echo "Checking out ${CHANGELOG_BRANCH_NAME}"
151-
git checkout -b "${CHANGELOG_BRANCH_NAME}"
152-
echo "Changelog Branch Created"
181+
# Changelog Branch Setup
182+
# ---------------------
183+
echo "Checking for existing changelog branch ${CHANGELOG_BRANCH_NAME}"
184+
185+
# Check if branch exists locally or remotely
186+
if git show-ref --verify --quiet refs/heads/"${CHANGELOG_BRANCH_NAME}" || git ls-remote --heads origin "${CHANGELOG_BRANCH_NAME}" | grep -q "${CHANGELOG_BRANCH_NAME}"; then
187+
echo "Branch ${CHANGELOG_BRANCH_NAME} already exists, checking it out"
188+
git fetch origin "${CHANGELOG_BRANCH_NAME}"
189+
git checkout "${CHANGELOG_BRANCH_NAME}"
190+
else
191+
echo "Creating new branch ${CHANGELOG_BRANCH_NAME}"
192+
git checkout -b "${CHANGELOG_BRANCH_NAME}"
193+
fi
194+
echo "Changelog Branch Ready"
153195

196+
# Generate Changelog and Test Plan
197+
# ------------------------------
154198
echo "Generating changelog via auto-changelog.."
155-
156199
npx @metamask/auto-changelog@4.1.0 update --rc --repo "${GITHUB_REPOSITORY_URL}" --currentVersion "${NEW_VERSION}" --autoCategorize
157200

158201
# Need to run from .github-tools context to inherit it's dependencies/environment
@@ -163,14 +206,19 @@ ls -ltra
163206
corepack prepare yarn@4.5.1 --activate
164207
# This can't be done from the actions context layer due to the upstream repository having it's own context set with yarn
165208
yarn --cwd install
209+
166210
echo "Generating test plan csv.."
167211
yarn run gen:commits "${PLATFORM}" "${PREVIOUS_VERSION}" "${RELEASE_BRANCH_NAME}" "${PROJECT_GIT_DIR}"
168212

169-
echo "Updating release sheet.."
170-
# Create a new Release Sheet Page for the new version with our commits.csv content
171-
yarn run update-release-sheet "${PLATFORM}" "${NEW_VERSION}" "${GOOGLE_DOCUMENT_ID}" "./commits.csv" "${PROJECT_GIT_DIR}" "${MOBILE_TEMPLATE_SHEET_ID}" "${EXTENSION_TEMPLATE_SHEET_ID}"
213+
if [[ "${TEST_ONLY:-false}" == 'false' ]]; then
214+
echo "Updating release sheet.."
215+
# Create a new Release Sheet Page for the new version with our commits.csv content
216+
yarn run update-release-sheet "${PLATFORM}" "${NEW_VERSION}" "${GOOGLE_DOCUMENT_ID}" "./commits.csv" "${PROJECT_GIT_DIR}" "${MOBILE_TEMPLATE_SHEET_ID}" "${EXTENSION_TEMPLATE_SHEET_ID}"
217+
fi
172218
cd ../
173219

220+
# Commit and Push Changelog Changes
221+
# -------------------------------
174222
echo "Adding and committing changes.."
175223
git add ./commits.csv
176224

@@ -186,12 +234,20 @@ PR_BODY="This PR updates the change log for ${NEW_VERSION} and generates the tes
186234
echo "Pushing changes to the remote.."
187235
git push --set-upstream origin "${CHANGELOG_BRANCH_NAME}"
188236

189-
echo Creating release PR..
190-
gh pr create \
191-
--draft \
192-
--title "chore: ${CHANGELOG_BRANCH_NAME}" \
193-
--body "${PR_BODY}" \
194-
--base "${RELEASE_BRANCH_NAME}" \
195-
--head "${CHANGELOG_BRANCH_NAME}";
237+
# Create Changelog PR
238+
# -----------------
239+
echo "Creating changelog PR.."
240+
# Check if PR already exists
241+
if gh pr list --search "head:${CHANGELOG_BRANCH_NAME}" --json number --jq 'length' | grep -q "1"; then
242+
echo "Changelog PR for branch ${CHANGELOG_BRANCH_NAME} already exists"
243+
else
244+
gh pr create \
245+
--draft \
246+
--title "chore: ${CHANGELOG_BRANCH_NAME}" \
247+
--body "${PR_BODY}" \
248+
--base "${RELEASE_BRANCH_NAME}" \
249+
--head "${CHANGELOG_BRANCH_NAME}"
250+
echo "Changelog PR Created"
251+
fi
196252

197-
echo "Changelog PR Created"
253+
echo "Changelog PR Ready"

0 commit comments

Comments
 (0)