Skip to content

Commit 34c5d2c

Browse files
committed
chore: update sync script
1 parent 93207bd commit 34c5d2c

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

.github/scripts/stable-sync.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@
99
//
1010
// Usage: node stable-sync.js [branch-name]
1111
// If no branch name is provided, defaults to 'stable-sync'
12+
//
13+
// Environment variables:
14+
// CREATE_BRANCH - if set to 'true', will push the branch at the end
1215

1316
const { promisify } = require('util');
1417
const exec = promisify(require('child_process').exec);
1518

1619
async function runGitCommands() {
1720
// Get branch name from command line arguments or use default
1821
const branchName = process.argv[2] || 'stable-main';
22+
23+
// Check if CREATE_BRANCH environment variable exists and is set to true
24+
const shouldPushBranch = (process.env.CREATE_BRANCH || 'false').toLowerCase() === 'true';
1925

2026
try {
2127
try {
@@ -111,11 +117,36 @@ async function runGitCommands() {
111117
await exec('git add .');
112118
console.log('Executed: git add .');
113119

114-
await exec(`git commit -m "Merge origin/main into ${branchName}" --no-verify`);
115-
console.log('Executed: git commit');
120+
try {
121+
// Check if there are any changes to commit
122+
const { stdout: status } = await exec('git status --porcelain');
123+
if (!status.trim()) {
124+
console.log('No changes to commit, skipping commit step');
125+
return;
126+
}
127+
128+
await exec(`git commit -m "Merge origin/main into ${branchName}" --no-verify`);
129+
console.log('Executed: git commit');
130+
} catch (error) {
131+
console.error(`Error: ${error.message}`);
132+
process.exit(1);
133+
}
116134

117135
console.log(`Your local ${branchName} branch is now ready to become a PR.`);
118-
console.log('You likely now need to do `git push --force`');
136+
137+
// Push the branch if CREATE_BRANCH is true
138+
if (shouldPushBranch) {
139+
try {
140+
console.log(`Pushing branch ${branchName} to remote...`);
141+
await exec(`git push --set-upstream origin ${branchName}`);
142+
console.log(`Successfully pushed branch ${branchName} to remote`);
143+
} catch (error) {
144+
console.error(`Error pushing branch: ${error.message}`);
145+
process.exit(1);
146+
}
147+
} else {
148+
console.log('You likely now need to do `git push --force`');
149+
}
119150
} catch (error) {
120151
console.error(`Error: ${error.message}`);
121152
process.exit(1);

0 commit comments

Comments
 (0)