Skip to content
19 changes: 11 additions & 8 deletions .github/scripts/stable-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
// Usage: node stable-sync.js [branch-name]
// If no branch name is provided, defaults to 'stable-sync'
//
//
// Environment variables:
// CREATE_BRANCH - if set to 'true', will push the branch at the end

Expand All @@ -19,7 +19,10 @@ const exec = promisify(require('child_process').exec);
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';

// Check if CREATE_BRANCH environment variable exists and is set to true
const shouldPushBranch = (process.env.CREATE_BRANCH || 'false').toLowerCase() === 'true';

Expand Down Expand Up @@ -82,7 +85,7 @@ async function runGitCommands() {

await exec('git add .');
await exec('git restore --source origin/main .');
console.log('Executed: it restore --source origin/main .');
console.log('Executed: git restore --source origin/main .');

await exec('git checkout origin/main -- .');
console.log('Executed: git checkout origin/main -- .');
Expand All @@ -93,7 +96,7 @@ async function runGitCommands() {
// 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');

Expand All @@ -109,9 +112,9 @@ async function runGitCommands() {
// 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/master:package.json',
'git show origin/main:package.json',
);
const packageJson = JSON.parse(packageJsonContent);
const packageVersion = packageJson.version;
Expand Down Expand Up @@ -143,7 +146,7 @@ async function runGitCommands() {
}

console.log(`Your local ${branchName} branch is now ready to become a PR.`);

// Push the branch if CREATE_BRANCH is true
if (shouldPushBranch) {
try {
Expand Down Expand Up @@ -172,4 +175,4 @@ async function runGitCommands() {
}
}

runGitCommands();
runGitCommands();
28 changes: 27 additions & 1 deletion .github/workflows/stable-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ on:
- mobile
- extension
default: 'mobile'
stable-branch-name:
required: false
type: string
description: 'The name of the stable branch to sync to (e.g., stable, master, main)'
default: 'stable'
workflow_call:
inputs:
semver-version:
Expand All @@ -26,6 +31,11 @@ on:
type: string
description: 'Type of repository (mobile or extension)'
default: 'mobile'
stable-branch-name:
required: false
type: string
description: 'The name of the stable branch to sync to (e.g., stable, master, main)'
default: 'stable'

jobs:
stable-sync:
Expand All @@ -35,11 +45,26 @@ jobs:
with:
fetch-depth: 0

- name: Setup Node.js
- name: Setup Node.js Mobile
if: ${{ inputs.repo-type == 'mobile' }}
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Setup Node.js Extension
if: ${{ inputs.repo-type == 'extension' }}
uses: actions/setup-node@v4
with:
node-version: '22.15'

- name: Prepare Yarn
if: ${{ inputs.repo-type == 'extension' }}
run: corepack prepare yarn@4.5.1 --activate

- name: Prepare Yarn - Enable corepack
if: ${{ inputs.repo-type == 'extension' }}
run: corepack enable

- name: Check if PR exists
id: check-pr
uses: actions/github-script@v7
Expand All @@ -66,6 +91,7 @@ jobs:
env:
CREATE_BRANCH: 'false' # let the script handle the branch creation
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 }}"
# Check if branch exists remotely
Expand Down
Loading