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

chore: Remove previous daily alpha when trying to create a new one #7749

Merged
merged 2 commits into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 38 additions & 5 deletions packages/release-tool/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import assert from "assert";
import chalk from "chalk";
import child_process, { ExecFileOptions, spawn as _spawn } from "child_process";
import child_process, { spawn as _spawn } from "child_process";
import { readFile } from "fs/promises";
import inquirer from "inquirer";
import { createInterface, ReadLine } from "readline";
Expand All @@ -24,11 +24,15 @@ const exec = ((cmd, ...args) => {
return _exec(cmd, ...args as any[]);
}) as typeof _exec;

const execFile = (file: string, args: string[], opts?: ExecFileOptions) => {
console.log("EXEC", file, args);
const execFile = ((file, ...rest) => {
if (Array.isArray(rest[0])) {
console.log("EXEC-FILE", file, rest[0]);
} else {
console.log("EXEC-FILE", file);
}

return _execFile(file, args, opts);
};
return _execFile(file, ...rest as [any, any]);
}) as typeof _execFile;

const spawn = ((file, ...args) => {
console.log("SPAWN", file);
Expand Down Expand Up @@ -168,6 +172,33 @@ function formatVersionForPickingPrs(version: SemVer): string {
return `${version.major}.${version.minor}.${version.patch+1}`;
}

async function deleteAndClosePreviousReleaseBranch(prBase: string, prBranch: string) {
try {
await pipeExecFile("gh", [
"pr",
"view",
prBranch,
"--json",
"number",
]);
} catch {
return;
}

await pipeExecFile("gh", [
"pr",
"close",
prBranch,
]);

await pipeExecFile("git", [
"push",
"origin",
"--delete",
prBranch,
]);
}

async function createReleaseBranchAndCommit(prBase: string, version: SemVer, prBody: string): Promise<void> {
const prBranch = `release/v${version.format()}`;

Expand All @@ -185,6 +216,8 @@ async function createReleaseBranchAndCommit(prBase: string, version: SemVer, prB
throw error;
}

await deleteAndClosePreviousReleaseBranch(prBase, prBranch);

await pipeExecFile("git", ["push", "--set-upstream", "origin", prBranch]);

await pipeExecFile("gh", [
Expand Down