1
0
mirror of https://github.com/lensapp/lens.git synced 2024-10-26 17:58:19 +03:00

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

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-05-19 11:23:34 -04:00 committed by Gabriel Accettola
parent 99e6b77fc1
commit add1a0a39e

View File

@ -5,7 +5,7 @@
*/ */
import assert from "assert"; import assert from "assert";
import chalk from "chalk"; 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 { readFile } from "fs/promises";
import inquirer from "inquirer"; import inquirer from "inquirer";
import { createInterface, ReadLine } from "readline"; import { createInterface, ReadLine } from "readline";
@ -24,11 +24,15 @@ const exec = ((cmd, ...args) => {
return _exec(cmd, ...args as any[]); return _exec(cmd, ...args as any[]);
}) as typeof _exec; }) as typeof _exec;
const execFile = (file: string, args: string[], opts?: ExecFileOptions) => { const execFile = ((file, ...rest) => {
console.log("EXEC", file, args); 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) => { const spawn = ((file, ...args) => {
console.log("SPAWN", file); console.log("SPAWN", file);
@ -168,6 +172,33 @@ function formatVersionForPickingPrs(version: SemVer): string {
return `${version.major}.${version.minor}.${version.patch+1}`; 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> { async function createReleaseBranchAndCommit(prBase: string, version: SemVer, prBody: string): Promise<void> {
const prBranch = `release/v${version.format()}`; const prBranch = `release/v${version.format()}`;
@ -185,6 +216,8 @@ async function createReleaseBranchAndCommit(prBase: string, version: SemVer, prB
throw error; throw error;
} }
await deleteAndClosePreviousReleaseBranch(prBase, prBranch);
await pipeExecFile("git", ["push", "--set-upstream", "origin", prBranch]); await pipeExecFile("git", ["push", "--set-upstream", "origin", prBranch]);
await pipeExecFile("gh", [ await pipeExecFile("gh", [