Skip to content

Commit 23bc378

Browse files
committed
fix: issues with prepare-release script
- handle deleted files properly - more status checks - catch "errors" during `exec` calls (usually just non-zero exit codes)
1 parent a933f06 commit 23bc378

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

prepare-release.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
writeFileSync,
99
} from "node:fs";
1010
import { dirname, resolve } from "node:path";
11-
import { exit } from "node:process";
11+
import { exit, stderr } from "node:process";
1212
import { fileURLToPath } from "node:url";
1313
import { promisify } from "node:util";
1414
import { parse } from "yaml";
@@ -57,7 +57,15 @@ if (!resolvedRepoPath || !existsSync(resolvedPackageJsonPath)) {
5757

5858
const promiseExec = promisify(exec);
5959
const execInRepo = async (cmd) => {
60-
const result = await promiseExec(`cd ${agentforceMessagingRepoPath}; ${cmd}`);
60+
const result = await promiseExec(
61+
`cd ${agentforceMessagingRepoPath}; ${cmd}`
62+
).catch((err) => ({
63+
// this typically means the command returned a non-zero code
64+
// we will simply pass the `err` object back as the result
65+
// but we will copy `stdout` to `stderr` if `stderr` is blank
66+
...err,
67+
stderr: err.stderr || err.stdout,
68+
}));
6169
return result;
6270
};
6371

@@ -143,20 +151,37 @@ const mergeResult = await execInRepo(
143151
`git merge origin/main --no-commit --squash -s ort -X theirs`
144152
);
145153
if (mergeResult.stderr) {
146-
if (!mergeResult.stderr.match(/Automatic merge went well/)) {
154+
if (mergeResult.stderr.match(/CONFLICT \(modify\/delete\)/)) {
155+
// ensure we are just dealing with deletions in origin/main
156+
const statusResult = await execInRepo("git status -s | grep -E '^[UAD][UAD]'");
157+
if (!statusResult.stdout.split(/\n/g).every((line) => !line || /^[UAD][UAD]\s/.test(line))) {
158+
console.error(`Unexpected merge conflict while merging origin/main into ${releaseBranch} branch`, statusResult.stdout, mergeResult.stderr);
159+
exit(1);
160+
}
161+
const resolveResult = await execInRepo("git status -s | grep -E '^UD ' | awk '{print $2}' | xargs git rm");
162+
if (resolveResult.stderr) {
163+
console.error(`Unexpected error while trying to resolve deleted files during merge of origin/main into ${releaseBranch} branch`, resolveResult.stderr, mergeResult.stderr);
164+
exit(1);
165+
}
166+
const unresolvedResult = await execInRepo("git status -s | grep -E '^[UAD][UAD]'");
167+
if (unresolvedResult.stdout || unresolvedResult.stderr) {
168+
console.error(`Unsuccessful merge of origin/main into ${releaseBranch} branch`, unresolvedResult.stdout || unresolvedResult.stderr, mergeResult.stderr);
169+
exit(1);
170+
}
171+
} else if (!mergeResult.stderr.match(/Automatic merge went well/)) {
147172
console.error(
148173
`Error while merging origin/main into ${releaseBranch} branch`,
149174
mergeResult.stderr
150175
);
151176
exit(1);
152177
}
153-
}
154-
if (mergeResult.stdout.match(/CONFLICT/)) {
178+
} else if (mergeResult.stdout.match(/CONFLICT/)) {
155179
console.error(
156180
`Conflicts encountered while merging origin/main even though we specified a merge strategy to accept remote changes. A manual merge and build will be required to release version ${newVersion}.`
157181
);
158182
exit(1);
159183
}
184+
160185
const squashMessagePath = resolve(resolvedRepoPath, ".git/SQUASH_MSG");
161186
if (!existsSync(squashMessagePath)) {
162187
console.error(

0 commit comments

Comments
 (0)