Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 24 additions & 35 deletions .github/scripts/stable-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,38 @@ 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';

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');
Expand Down Expand Up @@ -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/${baseBranch}:package.json`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also be stable instead of main?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's why I've updated it and tested it again, to use the correct stable branch which is passed as an argument. Mobile uses the stable branch, extension uses master (once they align the branch naming, will be a matter of updating the GH Workflow input).

Thanks!!

);
const packageJson = JSON.parse(packageJsonContent);
const packageVersion = packageJson.version;
Expand Down Expand Up @@ -175,4 +164,4 @@ async function runGitCommands() {
}
}

runGitCommands();
runGitCommands();
22 changes: 21 additions & 1 deletion .github/workflows/stable-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 'main'
workflow_call:
inputs:
semver-version:
Expand All @@ -36,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:
Expand All @@ -45,6 +55,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
Expand Down Expand Up @@ -93,8 +110,11 @@ 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
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
Expand Down
Loading