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

refactor: use Deno.Command instead of Deno.run #1225

Merged
merged 1 commit into from
May 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions tools/auto_update_v8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ function extractVersion() {
return `${major}.${minor}.${build}.${patch}`;
}

await run(["git", "checkout", "origin/main"]);
await run(["git", "submodule", "update", "--init", "--recursive", "v8"]);
await run("git", ["checkout", "origin/main"]);
await run("git", ["submodule", "update", "--init", "--recursive", "v8"]);

const currentVersion = extractVersion();
console.log(`Starting auto update. Currently on ${currentVersion}`);

async function run(cmd: string[], cwd?: string) {
console.log("$", ...cmd);
const proc = Deno.run({ cmd, cwd });
const status = await proc.status();
async function run(cmd: string, args: string[], cwd?: string) {
console.log("$", cmd, ...args);
const proc = new Deno.Command(cmd, { args, cwd });
const status = await proc.output();
if (!status.success) {
console.error(`Failed to run ${cmd.join(" ")}`);
console.error(`Failed to run ${cmd} ${args.join(" ")}`);
Deno.exit(1);
}
}

// Update v8 submodule
await run(["git", "fetch", `origin`, V8_TRACKING_BRANCH], "./v8");
await run(["git", "checkout", `origin/${V8_TRACKING_BRANCH}`], "./v8");
await run("git", ["fetch", `origin`, V8_TRACKING_BRANCH], "./v8");
await run("git", ["checkout", `origin/${V8_TRACKING_BRANCH}`], "./v8");

const newVersion = extractVersion();
if (currentVersion == newVersion) {
Expand All @@ -58,30 +58,29 @@ readme = readme.replace(
Deno.writeTextFileSync("README.md", readme);

// Stage the changes
await run(["git", "add", "v8", "README.md"]);
await run("git", ["add", "v8", "README.md"]);

// Commit the changes
await run(["git", "commit", "-m", `Rolling to V8 ${newVersion}`]);
await run("git", ["commit", "-m", `Rolling to V8 ${newVersion}`]);

// Push to the `denoland/rusty_v8#autoroll`
await run(["git", "push", "origin", `+HEAD:refs/heads/${AUTOROLL_BRANCH}`]);
await run("git", ["push", "origin", `+HEAD:refs/heads/${AUTOROLL_BRANCH}`]);

// Fetch the remote branch so `gh` cli can find it
await run(["git", "fetch", "origin", AUTOROLL_BRANCH]);
await run("git", ["fetch", "origin", AUTOROLL_BRANCH]);

const proc = Deno.run({
cmd: ["gh", "pr", "view", AUTOROLL_BRANCH, "--json", "state"],
const proc = new Deno.Command("gh", {
args: ["pr", "view", AUTOROLL_BRANCH, "--json", "state"],
stdout: "piped",
});
const status = await proc.status();
const isPrOpen = status.success
? JSON.parse(new TextDecoder().decode(await proc.output())).state === "OPEN"
const output = await proc.output();
const isPrOpen = output.success
? JSON.parse(new TextDecoder().decode(output.stdout)).state === "OPEN"
: false;

if (isPrOpen) {
console.log("Already open PR. Editing existing PR.");
await run([
"gh",
await run("gh", [
"pr",
"edit",
AUTOROLL_BRANCH,
Expand All @@ -90,8 +89,7 @@ if (isPrOpen) {
]);
} else {
console.log("No PR open. Creating a new PR.");
await run([
"gh",
await run("gh", [
"pr",
"create",
"--title",
Expand Down
Loading