Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements to release-tool #7232

Merged
merged 11 commits into from
Feb 24, 2023
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/release-tool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"rimraf": "^4.1.2"
},
"dependencies": {
"chalk": "^5.2.0",
"inquirer": "^9.1.4",
"semver": "^7.3.8"
}
Expand Down
35 changes: 31 additions & 4 deletions packages/release-tool/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import assert from "assert";
import chalk from "chalk";
import child_process from "child_process";
import { readFile } from "fs/promises";
import inquirer from "inquirer";
import { EOL } from "os";
import { createInterface, ReadLine } from "readline";
import semver from "semver";
import { promisify } from "util";
Expand Down Expand Up @@ -191,10 +191,38 @@ const isBugfixPr = (pr: ExtendedGithubPrData) => pr.labels.some(label => label.n

const cherrypickCommitWith = (rl: ReadLine) => async (commit: string) => {
try {
await spawn("git", ["cherry-pick", commit], {
stdio: "inherit",
const cherryPick = child_process.spawn("git", ["cherry-pick", commit]);

cherryPick.stdout.pipe(process.stdout);
cherryPick.stderr.pipe(process.stderr);

await new Promise<void>((resolve, reject) => {
const cleaners: (() => void)[] = [];
const cleanup = () => cleaners.forEach(cleaner => cleaner());

const onExit = (code: number | null) => {
if (code) {
reject(new Error(`git cherry-pick failed with exit code ${code}`));
cleanup();
}

resolve();
cleanup();
};

cherryPick.once("exit", onExit);
cleaners.push(() => cherryPick.off("exit", onExit));

const onError = (error: Error) => {
cleanup();
reject(error);
};

cherryPick.once("error", onError);
cleaners.push(() => cherryPick.off("error", onError));
});
} catch {
console.error(chalk.bold("Please resolve conflicts in a seperate terminal and then press enter here..."));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seperate => separate

await new Promise<void>(resolve => rl.once("line", () => resolve()));
}
};
Expand Down Expand Up @@ -258,7 +286,6 @@ function formatChangelog(previousReleasedVersion: string, prs: ExtendedGithubPrD
}

async function cherrypickCommits(prs: ExtendedGithubPrData[]): Promise<void> {
console.log(`${EOL}If cherry-picking fails for any of these commits, please resolve them in a seperate terminal and then run "git cherry-pick --continue"${EOL}`);
const rl = createInterface(process.stdin);
const cherrypickCommit = cherrypickCommitWith(rl);

Expand Down