From 326205c1c63e848a20825bca81e728aaed2c8581 Mon Sep 17 00:00:00 2001 From: Alejandro Som <560018+alucardzom@users.noreply.github.com> Date: Fri, 4 Jul 2025 17:35:44 +0200 Subject: [PATCH 1/8] feat: improve the call to execute the script in gh tools --- .github/workflows/stable-sync.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/stable-sync.yml b/.github/workflows/stable-sync.yml index 555f5ef6..853deef9 100644 --- a/.github/workflows/stable-sync.yml +++ b/.github/workflows/stable-sync.yml @@ -20,6 +20,11 @@ on: type: string description: 'The name of the stable branch to sync to (e.g., stable, master, main)' default: 'stable' + github-tools-version: + required: false + type: string + description: 'The version of github-tools to use. Defaults to main.' + default: ${{ github.action_ref }} workflow_call: inputs: semver-version: @@ -45,6 +50,13 @@ jobs: with: fetch-depth: 0 + - name: Checkout github-tools repository + uses: actions/checkout@v4 + with: + repository: MetaMask/github-tools + ref: ${{ inputs.github-tools-version }} + path: github-tools + - name: Setup Node.js Mobile if: ${{ inputs.repo-type == 'mobile' }} uses: actions/setup-node@v4 @@ -93,7 +105,8 @@ jobs: REPO: ${{ inputs.repo-type }} # Default to 'mobile' if not specified BASE_BRANCH: ${{ inputs.stable-branch-name }} run: | - node .github/scripts/stable-sync.js "stable-main-${{ inputs.semver-version }}" + # Execute the script from github-tools + node .github_tools/.github/scripts/stable-sync.js "stable-main-${{ inputs.semver-version }}" # Check if branch exists remotely BRANCH_NAME="stable-main-${{ inputs.semver-version }}" if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then From a762625a23bb1afab7d13229c40aef9aa497863e Mon Sep 17 00:00:00 2001 From: Alejandro Som <560018+alucardzom@users.noreply.github.com> Date: Fri, 4 Jul 2025 17:38:45 +0200 Subject: [PATCH 2/8] chore: test --- .github/workflows/stable-sync.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/stable-sync.yml b/.github/workflows/stable-sync.yml index 853deef9..c39e7420 100644 --- a/.github/workflows/stable-sync.yml +++ b/.github/workflows/stable-sync.yml @@ -24,7 +24,7 @@ on: required: false type: string description: 'The version of github-tools to use. Defaults to main.' - default: ${{ github.action_ref }} + default: 'main' workflow_call: inputs: semver-version: @@ -41,6 +41,11 @@ on: type: string description: 'The name of the stable branch to sync to (e.g., stable, master, main)' default: 'stable' + github-tools-version: + required: false + type: string + description: 'The version of github-tools to use. Defaults to main.' + default: ${{ github.action_ref }} jobs: stable-sync: From 743b5d0513c8e7b116c9529094b3a3c2fa711938 Mon Sep 17 00:00:00 2001 From: Alejandro Som <560018+alucardzom@users.noreply.github.com> Date: Fri, 4 Jul 2025 17:56:18 +0200 Subject: [PATCH 3/8] chore: fix path --- .github/workflows/stable-sync.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stable-sync.yml b/.github/workflows/stable-sync.yml index c39e7420..4e38fe73 100644 --- a/.github/workflows/stable-sync.yml +++ b/.github/workflows/stable-sync.yml @@ -111,7 +111,7 @@ jobs: BASE_BRANCH: ${{ inputs.stable-branch-name }} run: | # Execute the script from github-tools - node .github_tools/.github/scripts/stable-sync.js "stable-main-${{ inputs.semver-version }}" + node ./github_tools/.github/scripts/stable-sync.js "stable-main-${{ inputs.semver-version }}" # Check if branch exists remotely BRANCH_NAME="stable-main-${{ inputs.semver-version }}" if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then From dbcee8b6348b54a628d9b46f852fea15d5c06168 Mon Sep 17 00:00:00 2001 From: Alejandro Som <560018+alucardzom@users.noreply.github.com> Date: Fri, 4 Jul 2025 18:00:22 +0200 Subject: [PATCH 4/8] chore: test --- .github/workflows/stable-sync.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/stable-sync.yml b/.github/workflows/stable-sync.yml index 4e38fe73..1dbef466 100644 --- a/.github/workflows/stable-sync.yml +++ b/.github/workflows/stable-sync.yml @@ -110,6 +110,7 @@ jobs: REPO: ${{ inputs.repo-type }} # Default to 'mobile' if not specified BASE_BRANCH: ${{ inputs.stable-branch-name }} run: | + ls -la # Execute the script from github-tools node ./github_tools/.github/scripts/stable-sync.js "stable-main-${{ inputs.semver-version }}" # Check if branch exists remotely From 4798a541cb35688a107c0edc06a606854157b9cd Mon Sep 17 00:00:00 2001 From: Alejandro Som <560018+alucardzom@users.noreply.github.com> Date: Fri, 4 Jul 2025 18:03:30 +0200 Subject: [PATCH 5/8] chore: fix typo oin path --- .github/workflows/stable-sync.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/stable-sync.yml b/.github/workflows/stable-sync.yml index 1dbef466..dca8a08c 100644 --- a/.github/workflows/stable-sync.yml +++ b/.github/workflows/stable-sync.yml @@ -110,9 +110,8 @@ jobs: REPO: ${{ inputs.repo-type }} # Default to 'mobile' if not specified BASE_BRANCH: ${{ inputs.stable-branch-name }} run: | - ls -la # Execute the script from github-tools - node ./github_tools/.github/scripts/stable-sync.js "stable-main-${{ inputs.semver-version }}" + node ./github-tools/.github/scripts/stable-sync.js "stable-main-${{ inputs.semver-version }}" # Check if branch exists remotely BRANCH_NAME="stable-main-${{ inputs.semver-version }}" if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then From ffb19a85a5f12add82bdf70a2c8763e0b3a5a916 Mon Sep 17 00:00:00 2001 From: Alejandro Som <560018+alucardzom@users.noreply.github.com> Date: Tue, 8 Jul 2025 10:49:46 +0200 Subject: [PATCH 6/8] chore: standarize the file --- .github/scripts/stable-sync.js | 59 ++++++++++++++-------------------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/.github/scripts/stable-sync.js b/.github/scripts/stable-sync.js index 26a9341f..103d23fd 100644 --- a/.github/scripts/stable-sync.js +++ b/.github/scripts/stable-sync.js @@ -20,8 +20,8 @@ async function runGitCommands() { // Get branch name from command line arguments or use default const branchName = process.argv[2] || 'stable-main'; - // Get base stable branch from environment variable (defaults to 'master' for backward compatibility of extension) - const baseBranch = process.env.BASE_BRANCH || 'master'; + // Get base stable branch from environment variable (defaults to 'stable' for backward compatibility for mobile) + const baseBranch = process.env.BASE_BRANCH || 'stable'; // Check if CREATE_BRANCH environment variable exists and is set to true const shouldPushBranch = (process.env.CREATE_BRANCH || 'false').toLowerCase() === 'true'; @@ -29,40 +29,29 @@ async function runGitCommands() { try { try { // Check if the branch already exists - const { stdout: branchExists } = await exec( - //`git rev-parse --quiet --verify ${branchName}`, - `git ls-remote origin ${branchName}`, - ); + const { stdout: branchExists } = await exec(`git ls-remote origin ${branchName}`); if (branchExists.trim()) { - // Branch exists, so simply check it out + // Branch exists, check it out await exec(`git checkout ${branchName}`); await exec(`git pull origin ${branchName}`); console.log(`Checked out branch: ${branchName}`); } else { - throw new Error( - 'git rev-parse --quiet --verify failed. Branch hash empty', - ); - } - } catch (error) { - if (error.stdout === '') { - console.warn( - `Branch does not exist, creating new ${branchName} branch.`, - ); - - // Branch does not exist, create and check it out + // Branch doesn't exist, create it + console.warn(`Branch does not exist, creating new ${branchName} branch.`); await exec(`git checkout -b ${branchName}`); console.log(`Created and checked out branch: ${branchName}`); - } else { - console.error(`Error: ${error.message}`); - process.exit(1); } + } catch (error) { + // Handle actual git command errors + console.error(`Error: ${error.message}`); + process.exit(1); } await exec('git fetch'); console.log('Executed: git fetch'); - await exec('git reset --hard origin/stable'); - console.log('Executed: git reset --hard origin/stable'); + await exec(`git reset --hard origin/${baseBranch}`); + console.log(`Executed: git reset --hard origin/${baseBranch}`); try { await exec('git merge origin/main'); @@ -90,31 +79,31 @@ async function runGitCommands() { await exec('git checkout origin/main -- .'); console.log('Executed: git checkout origin/main -- .'); - await exec('git checkout origin/stable -- CHANGELOG.md'); - console.log('Executed: git checkout origin/stable -- CHANGELOG.md'); + await exec(`git checkout origin/${baseBranch} -- CHANGELOG.md`); + console.log(`Executed: git checkout origin/${baseBranch} -- CHANGELOG.md`); // Execute mobile-specific commands if REPO is 'mobile' if (process.env.REPO === 'mobile') { console.log('Executing mobile-specific commands...'); - await exec('git checkout origin/stable -- bitrise.yml'); - console.log('Executed: git checkout origin/stable -- bitrise.yml'); + await exec(`git checkout origin/${baseBranch} -- bitrise.yml`); + console.log(`Executed: git checkout origin/${baseBranch} -- bitrise.yml`); - await exec('git checkout origin/stable -- android/app/build.gradle'); - console.log('Executed: git checkout origin/stable -- android/app/build.gradle'); + await exec(`git checkout origin/${baseBranch} -- android/app/build.gradle`); + console.log(`Executed: git checkout origin/${baseBranch} -- android/app/build.gradle`); - await exec('git checkout origin/stable -- ios/MetaMask.xcodeproj/project.pbxproj'); - console.log('Executed: git checkout origin/stable -- ios/MetaMask.xcodeproj/project.pbxproj'); + await exec(`git checkout origin/${baseBranch} -- ios/MetaMask.xcodeproj/project.pbxproj`); + console.log(`Executed: git checkout origin/${baseBranch} -- ios/MetaMask.xcodeproj/project.pbxproj`); - await exec('git checkout origin/stable -- package.json'); - console.log('Executed: git checkout origin/stable -- package.json'); + await exec(`git checkout origin/${baseBranch} -- package.json`); + console.log(`Executed: git checkout origin/${baseBranch} -- package.json`); } // Execute extension-specific commands if REPO is 'extension' else if (process.env.REPO === 'extension') { console.log('Executing extension-specific commands...'); const { stdout: packageJsonContent } = await exec( - 'git show origin/main:package.json', + 'git show origin/master:package.json', ); const packageJson = JSON.parse(packageJsonContent); const packageVersion = packageJson.version; @@ -175,4 +164,4 @@ async function runGitCommands() { } } -runGitCommands(); \ No newline at end of file +runGitCommands(); From 2f19e16beac4638a0e95471c491240f8f82f67a7 Mon Sep 17 00:00:00 2001 From: Alejandro Som <560018+alucardzom@users.noreply.github.com> Date: Tue, 8 Jul 2025 11:08:32 +0200 Subject: [PATCH 7/8] chore: add step to clean up github tools repo --- .github/workflows/stable-sync.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/stable-sync.yml b/.github/workflows/stable-sync.yml index dca8a08c..6dc846e3 100644 --- a/.github/workflows/stable-sync.yml +++ b/.github/workflows/stable-sync.yml @@ -113,6 +113,8 @@ jobs: # Execute the script from github-tools node ./github-tools/.github/scripts/stable-sync.js "stable-main-${{ inputs.semver-version }}" # Check if branch exists remotely + echo "Cleaning up github-tools" + rm -rf github-tools BRANCH_NAME="stable-main-${{ inputs.semver-version }}" if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then git pull --rebase From 6223ebdc379fae52cfd66bf2612d94edfa09287d Mon Sep 17 00:00:00 2001 From: Alejandro Som <560018+alucardzom@users.noreply.github.com> Date: Tue, 8 Jul 2025 13:21:52 +0200 Subject: [PATCH 8/8] chore: use baseBranch instead of hardcoded master --- .github/scripts/stable-sync.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/stable-sync.js b/.github/scripts/stable-sync.js index 103d23fd..d5544eb9 100644 --- a/.github/scripts/stable-sync.js +++ b/.github/scripts/stable-sync.js @@ -103,7 +103,7 @@ async function runGitCommands() { console.log('Executing extension-specific commands...'); const { stdout: packageJsonContent } = await exec( - 'git show origin/master:package.json', + `git show origin/${baseBranch}:package.json`, ); const packageJson = JSON.parse(packageJsonContent); const packageVersion = packageJson.version;