diff --git a/.github/scripts/stable-sync.js b/.github/scripts/stable-sync.js index d85405c6..26a9341f 100644 --- a/.github/scripts/stable-sync.js +++ b/.github/scripts/stable-sync.js @@ -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 @@ -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'; @@ -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 -- .'); @@ -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'); @@ -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; @@ -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 { @@ -172,4 +175,4 @@ async function runGitCommands() { } } -runGitCommands(); +runGitCommands(); \ No newline at end of file diff --git a/.github/workflows/stable-sync.yml b/.github/workflows/stable-sync.yml index 68fae196..555f5ef6 100644 --- a/.github/workflows/stable-sync.yml +++ b/.github/workflows/stable-sync.yml @@ -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: @@ -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: @@ -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 @@ -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