Skip to content

Commit d15d786

Browse files
authored
INFRA-2867-Fix workflow inputs to allow branch name (#108)
* INFRA-2867-Fix workflow inputs to allow branch name Signed-off-by: Pavel Dvorkin <pavel.dvorkin@consensys.net> * INFRA-2867-Updated branch variable names to make it clearer Signed-off-by: Pavel Dvorkin <pavel.dvorkin@consensys.net> * INFRA-2867: Updated comments set previous branch regex Signed-off-by: Pavel Dvorkin <pavel.dvorkin@consensys.net> --------- Signed-off-by: Pavel Dvorkin <pavel.dvorkin@consensys.net>
1 parent 95fbc50 commit d15d786

File tree

3 files changed

+51
-25
lines changed

3 files changed

+51
-25
lines changed

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

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88
# 3. A version bump PR for the main branch
99
#
1010
# Usage:
11-
# create-platform-release-pr.sh <platform> <previous_version> <new_version> [new_version_number] [git_user_name] [git_user_email]
11+
# create-platform-release-pr.sh <platform> <previous_version_ref> <new_version> [new_version_number] [git_user_name] [git_user_email]
1212
#
1313
# Parameters:
14-
# platform - 'mobile' or 'extension'
15-
# previous_version - Previous release version tag (e.g., v7.7.0)
16-
# new_version - New semantic version (e.g., 7.8.0)
17-
# new_version_number - Build version for mobile platform (optional, required for mobile)
18-
# git_user_name - Git user name for commits (optional, defaults to 'metamaskbot')
19-
# git_user_email - Git user email for commits (optional, defaults to 'metamaskbot@users.noreply.github.com')
14+
# platform - 'mobile' or 'extension'
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+
# new_version - New semantic version (e.g., 7.8.0)
17+
# new_version_number - Build version for mobile platform (optional, required for mobile)
18+
# git_user_name - Git user name for commits (optional, defaults to 'metamaskbot')
19+
# git_user_email - Git user email for commits (optional, defaults to 'metamaskbot@users.noreply.github.com')
2020

2121
set -e
2222
set -u
2323
set -o pipefail
2424

2525
# Input validation
2626
PLATFORM="${1}"
27-
PREVIOUS_VERSION="${2}"
27+
PREVIOUS_VERSION_REF="${2}"
2828
NEW_VERSION="${3}"
2929
NEW_VERSION_NUMBER="${4:-}"
3030
GIT_USER_NAME="${5:-metamaskbot}"
@@ -292,7 +292,7 @@ create_release_pr() {
292292
create_changelog_pr() {
293293
local platform="$1"
294294
local new_version="$2"
295-
local previous_version="$3"
295+
local previous_version_ref="$3"
296296
local release_branch_name="$4"
297297
local changelog_branch_name="$5"
298298

@@ -306,15 +306,40 @@ create_changelog_pr() {
306306
# Need to run from .github-tools context to inherit it's dependencies/environment
307307
echo "Current Directory: $(pwd)"
308308
PROJECT_GIT_DIR=$(pwd)
309+
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.
314+
DIFF_BASE="${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
329+
else
330+
echo "Previous version is not a recognized release branch pattern. Treating as tag or SHA: ${previous_version_ref}"
331+
fi
332+
333+
# Switch to github-tools directory
309334
cd ./github-tools/
310335
ls -ltra
311336
corepack prepare yarn@4.5.1 --activate
312337
# This can't be done from the actions context layer due to the upstream repository having it's own context set with yarn
313338
yarn --cwd install
314339

315340
echo "Generating test plan csv.."
316-
yarn run gen:commits "${platform}" "${previous_version}" "${release_branch_name}" "${PROJECT_GIT_DIR}"
317-
341+
yarn run gen:commits "${platform}" "${DIFF_BASE}" "${release_branch_name}" "${PROJECT_GIT_DIR}"
342+
318343
# Skipping Google Sheets update since there is no need for it anymore
319344
# TODO: Remove this once the current post-main validation approach is stable
320345
# if [[ "${TEST_ONLY:-false}" == 'false' ]]; then
@@ -435,7 +460,7 @@ main() {
435460
if [ "$TEST_ONLY" == "true" ]; then
436461
echo "Skipping changelog generation in test mode"
437462
else
438-
create_changelog_pr "$PLATFORM" "$NEW_VERSION" "$PREVIOUS_VERSION" "$release_branch_name" "$changelog_branch_name"
463+
create_changelog_pr "$PLATFORM" "$NEW_VERSION" "$PREVIOUS_VERSION_REF" "$release_branch_name" "$changelog_branch_name"
439464
fi
440465

441466
# Step 3: Create version bump PR for main branch

.github/scripts/generate-rc-commits.mjs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ async function getTeam(repository, prNumber) {
5959
}
6060

6161
// Function to filter commits based on unique commit messages and group by teams
62-
async function filterCommitsByTeam(platform, branchA, branchB) {
62+
// Input parameters refA and refB can be a branch name, a tag or a commit hash (e.g., release/7.7.0, v7.7.0, or 76fbc500034db9779e9ff7ce637ac5be1da0493d)
63+
async function filterCommitsByTeam(platform, refA, refB) {
6364

6465
const MAX_COMMITS = 500; // Limit the number of commits to process
6566
console.log('Filtering commits by team...');
@@ -81,8 +82,8 @@ async function filterCommitsByTeam(platform, branchA, branchB) {
8182
const git = simpleGit();
8283

8384
const logOptions = {
84-
from: branchB,
85-
to: branchA,
85+
from: refB,
86+
to: refA,
8687
format: {
8788
hash: '%H',
8889
author: '%an',
@@ -92,7 +93,7 @@ async function filterCommitsByTeam(platform, branchA, branchB) {
9293

9394
const log = await git.log(logOptions);
9495

95-
console.log(`Total commits between ${branchA} and ${branchB}: ${log.total}`);
96+
console.log(`Total commits between ${refA} and ${refB}: ${log.total}`);
9697
console.log(`Processing up to ${Math.min(log.all.length, MAX_COMMITS)} commits...`);
9798

9899
const commitsByTeam = {};
@@ -204,26 +205,26 @@ async function main() {
204205

205206
if (args.length !== 4) {
206207
console.error(
207-
'Usage: node generate-rc-commits.mjs platform branchA branchB',
208+
'Usage: node generate-rc-commits.mjs platform refA refB',
208209
);
209210
console.error('Received:', args, ' with length:', args.length);
210211
process.exit(1);
211212
}
212213

213214
const platform = args[0];
214-
const branchA = args[1];
215-
const branchB = args[2];
215+
const refA = args[1];
216+
const refB = args[2];
216217
const gitDir = args[3];
217218

218219
// Change the working directory to the git repository path
219220
// Since this is invoked by a shared workflow, the working directory is not guaranteed to be the repository root
220221
process.chdir(gitDir);
221222

222223
console.log(
223-
`Generating CSV file for commits between ${branchA} and ${branchB} on ${platform} platform...`,
224+
`Generating CSV file for commits between ${refA} and ${refB} on ${platform} platform...`,
224225
);
225226

226-
const commitsByTeam = await filterCommitsByTeam(platform, branchA, branchB);
227+
const commitsByTeam = await filterCommitsByTeam(platform, refA, refB);
227228

228229
if (Object.keys(commitsByTeam).length === 0) {
229230
console.log('No commits found.');

.github/workflows/create-release-pr.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ on:
1919
required: false
2020
type: string
2121
description: 'The build version for the mobile platform.'
22-
previous-version-tag:
22+
previous-version-ref:
2323
required: true
2424
type: string
25-
description: 'Previous release version tag. eg: v7.7.0'
25+
description: 'Previous release version branch name, tag or commit hash (e.g., release/7.7.0, v7.7.0, or 76fbc500034db9779e9ff7ce637ac5be1da0493d)'
2626
# Flag to indicate if the release is a test release for development purposes only
2727
mobile-template-sheet-id:
2828
required: false
@@ -108,7 +108,7 @@ jobs:
108108
echo "Checkout Base Branch: ${{ inputs.checkout-base-branch }}"
109109
echo "Release PR Base Branch: ${{ inputs.release-pr-base-branch }}"
110110
echo "Semver Version: ${{ inputs.semver-version }}"
111-
echo "Previous Version Tag: ${{ inputs.previous-version-tag }}"
111+
echo "Previous Version Reference: ${{ inputs.previous-version-ref }}"
112112
echo "Test Only Mode: ${{ inputs.test-only }}"
113113
if [[ "${{ inputs.platform }}" == "mobile" ]]; then
114114
echo "Mobile Build Version: ${{ inputs.mobile-build-version }}"
@@ -140,7 +140,7 @@ jobs:
140140
# Execute the script from github-tools
141141
./github-tools/.github/scripts/create-platform-release-pr.sh \
142142
${{ inputs.platform }} \
143-
${{ inputs.previous-version-tag }} \
143+
${{ inputs.previous-version-ref }} \
144144
${{ inputs.semver-version }} \
145145
${{ inputs.mobile-build-version }} \
146146
${{ inputs.git-user-name }} \

0 commit comments

Comments
 (0)