Skip to content

Commit f4d3380

Browse files
committed
impr(release script): check if local master is in sync with origin
!nuf
1 parent 25c6fa8 commit f4d3380

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

bin/release.mjs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,34 @@ const runCommand = (command, force) => {
2828
}
2929
};
3030

31+
const checkBranchSync = () => {
32+
console.log("Checking if local master branch is in sync with origin...");
33+
34+
if (isDryRun) {
35+
console.log("[Dry Run] Checking sync...");
36+
} else {
37+
try {
38+
// Fetch the latest changes from the remote repository
39+
runCommand("git fetch origin");
40+
41+
// Get the commit hashes of the local and remote master branches
42+
const localMaster = runCommand("git rev-parse master").trim();
43+
const remoteMaster = runCommand("git rev-parse origin/master").trim();
44+
45+
if (localMaster !== remoteMaster) {
46+
console.error(
47+
"Local master branch is not in sync with origin. Please pull the latest changes before proceeding."
48+
);
49+
process.exit(1);
50+
}
51+
} catch (error) {
52+
console.error("Error checking branch sync status.");
53+
console.error(error);
54+
process.exit(1);
55+
}
56+
}
57+
};
58+
3159
const getCurrentVersion = () => {
3260
console.log("Getting current version...");
3361
const packageJson = JSON.parse(readFileSync("./package.json", "utf-8"));
@@ -153,6 +181,9 @@ const createGithubRelease = async (version, changelogContent) => {
153181

154182
const main = async () => {
155183
console.log("Starting release process...");
184+
185+
checkBranchSync();
186+
156187
checkUncommittedChanges();
157188

158189
const changelogContent = await generateChangelog();

0 commit comments

Comments
 (0)