|
12 | 12 | # |
13 | 13 | # Parameters: |
14 | 14 | # platform - 'mobile' or 'extension' |
15 | | -# previous_version_ref - Previous release version tag or branch name (e.g., v7.7.0) |
| 15 | +# previous_version_ref - Previous release version branch name, tag or commit hash (e.g., release/7.7.0, v7.7.0, or 76fbc500034db9779e9ff7ce637ac5be1da0493d) |
16 | 16 | # new_version - New semantic version (e.g., 7.8.0) |
17 | 17 | # new_version_number - Build version for mobile platform (optional, required for mobile) |
18 | 18 | # git_user_name - Git user name for commits (optional, defaults to 'metamaskbot') |
@@ -307,14 +307,27 @@ create_changelog_pr() { |
307 | 307 | echo "Current Directory: $(pwd)" |
308 | 308 | PROJECT_GIT_DIR=$(pwd) |
309 | 309 |
|
310 | | - # Resolve previous_version_ref when it's a branch name: fetch and use origin/<branch>. This enables branch names to be used as previous version references. |
| 310 | + # By default, DIFF_BASE is set to the provided `previous_version_ref` (which can be a branch name, tag, or commit hash). |
| 311 | + # If `previous_version_ref` matches a remote branch on origin, we fetch it and update DIFF_BASE to the fully qualified remote ref (`origin/<branch>`). |
| 312 | + # This is required for the `generate-rc-commits.mjs` script to resolve the branch and successfully run the `git log` command. |
| 313 | + # Otherwise, DIFF_BASE remains unchanged. |
311 | 314 | DIFF_BASE="${previous_version_ref}" |
312 | | - if git ls-remote --heads origin "${previous_version_ref}" | grep -qE "\srefs/heads/${previous_version_ref}$"; then |
313 | | - echo "Detected remote branch for previous version: ${previous_version_ref}" |
314 | | - git fetch origin "${previous_version_ref}" |
315 | | - DIFF_BASE="origin/${previous_version_ref}" |
| 315 | + |
| 316 | + # Only consider known release branch patterns to avoid regex pitfalls: |
| 317 | + # - Extension: Version-vx.y.z |
| 318 | + # - Mobile: release/x.y.z |
| 319 | + if [[ "${previous_version_ref}" =~ ^Version-v[0-9]+\.[0-9]+\.[0-9]+$ || "${previous_version_ref}" =~ ^release/[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 320 | + echo "Previous version looks like a release branch: ${previous_version_ref}" |
| 321 | + # Check if the exact branch exists on origin without interpolating into a regex |
| 322 | + if git ls-remote --heads origin "${previous_version_ref}" | grep -q "."; then |
| 323 | + echo "Detected remote branch for previous version: ${previous_version_ref}" |
| 324 | + git fetch origin "${previous_version_ref}" |
| 325 | + DIFF_BASE="origin/${previous_version_ref}" |
| 326 | + else |
| 327 | + echo "Remote branch not found on origin: ${previous_version_ref}. Will use as-is." |
| 328 | + fi |
316 | 329 | else |
317 | | - echo "No remote branch detected for previous version: ${previous_version_ref}" |
| 330 | + echo "Previous version is not a recognized release branch pattern. Treating as tag or SHA: ${previous_version_ref}" |
318 | 331 | fi |
319 | 332 |
|
320 | 333 | # Switch to github-tools directory |
|
0 commit comments