From e60f12798f688a06f082a55eaf52f7d33f5013f9 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 27 Apr 2021 11:02:47 +0200 Subject: [PATCH] build: fix autoroller (#672) --- .github/workflows/update-v8.yml | 12 +++++++--- tools/auto_update_v8.ts | 42 ++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/.github/workflows/update-v8.yml b/.github/workflows/update-v8.yml index e195374b..e13f9a3e 100644 --- a/.github/workflows/update-v8.yml +++ b/.github/workflows/update-v8.yml @@ -11,11 +11,17 @@ jobs: steps: - name: Clone repository uses: actions/checkout@v1 - with: - fetch-depth: 10 - submodules: recursive - uses: denoland/setup-deno@main with: deno-version: v1.x + - name: Setup Git user + run: | + git config --global user.email "33910674+denobot@users.noreply.github.com" + git config --global user.name "denobot" + git config --global user.password ${{ secrets.DENOBOT_PAT }} + echo "GIT_USER=${{ secrets.DENOBOT_PAT }}" >> $GITHUB_ENV + git remote set-url origin https://${{ secrets.DENOBOT_PAT }}@github.com/denoland/rusty_v8.git - run: deno run -A ./tools/auto_update_v8.ts + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/tools/auto_update_v8.ts b/tools/auto_update_v8.ts index c62608e7..b08da8db 100644 --- a/tools/auto_update_v8.ts +++ b/tools/auto_update_v8.ts @@ -22,11 +22,13 @@ function extractVersion() { } 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(); if (!status.success) { @@ -36,6 +38,7 @@ async function run(cmd: string[], cwd?: string) { } // Update v8 submodule +await run(["git", "fetch", `origin`, V8_TRACKING_BRANCH], "./v8"); await run(["git", "checkout", `origin/${V8_TRACKING_BRANCH}`], "./v8"); const newVersion = extractVersion(); @@ -61,30 +64,41 @@ await run(["git", "add", "v8", "README.md"]); await run(["git", "commit", "-m", `Rolling to V8 ${newVersion}`]); // Push to the `denoland/rusty_v8#autoroll` -await run(["git", "push", "origin", `+HEAD:${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]); const proc = Deno.run({ - cmd: ["gh", "pr", "view", AUTOROLL_BRANCH], + cmd: ["gh", "pr", "view", AUTOROLL_BRANCH, "--json", "state"], + stdout: "piped", }); const status = await proc.status(); -if (status.code == 1) { - console.log("No PR open. Creating a new PR."); - await run([ - "gh", - "pr", - "create", - "--fill", - "--head", - AUTOROLL_BRANCH, - ]); -} else { +const isPrOpen = status.success + ? JSON.parse(new TextDecoder().decode(await proc.output())).state === "OPEN" + : false; + +if (isPrOpen) { console.log("Already open PR. Editing existing PR."); await run([ "gh", "pr", "edit", - AUTOROLL_BRANCH, + `denoland:${AUTOROLL_BRANCH}`, "--title", `Rolling to V8 ${newVersion}`, ]); +} else { + console.log("No PR open. Creating a new PR."); + await run([ + "gh", + "pr", + "create", + "--title", + `Rolling to V8 ${newVersion}`, + "--body", + "", + "--head", + `denoland:${AUTOROLL_BRANCH}`, + ]); }