diff --git a/.github/bot/src/auto-rebase.ts b/.github/bot/src/auto-rebase.ts deleted file mode 100644 index 81359e171735..000000000000 --- a/.github/bot/src/auto-rebase.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { getTitleOfLatestCommit } from "./util/git"; -import { octokit } from "./util/octokit"; - -// We only auto-rebase if the latest commit message is one of -// -// - test(*) -// - chore: - -const owner = "swc-project"; -const repo = "swc"; - -function sleep(ms: number) { - return new Promise((r) => setTimeout(r, ms)); -} - -(async () => { - const latestCommitMessage = await getTitleOfLatestCommit(); - - console.log(`Latest commit message: ${latestCommitMessage}`); - - if (!latestCommitMessage.startsWith("chore:")) { - console.log( - `Auto rebase script cannot work because the latest commit may require a version bump` - ); - return; - } - - const allPrs = await octokit.rest.pulls.list({ - owner, - repo, - state: "open", - sort: "long-running", - direction: "desc", - }); - - const autoMergePrs = allPrs.data.filter((pr) => !!pr.auto_merge); - - if (autoMergePrs.length === 0) { - console.log(`No PRs with auto-merge enabled`); - return; - } - - for (const pr of autoMergePrs) { - try { - const baseBranch = await octokit.rest.repos.getBranch({ - owner, - repo, - branch: pr.base.ref, - }); - if (baseBranch.data.commit.sha === pr.base.sha) { - console.error(`PR #${pr.number} is already up-to-date`); - continue; - } - - await octokit.rest.pulls.updateBranch({ - owner, - repo, - pull_number: pr.number, - expected_head_sha: pr.head.sha, - }); - - console.log(`Updated PR ${pr.number} to merge upstream`); - - await sleep(3000); - - const review = await octokit.pulls.createReview({ - owner, - repo, - pull_number: pr.number, - }); - console.log(`Created a review on PR ${pr.number}`); - - await octokit.pulls.submitReview({ - owner, - repo, - pull_number: pr.number, - review_id: review.data.id, - event: "COMMENT", - body: "Automated review comment generated by auto-rebase script", - }); - - break; - } catch (e) { - console.error(`Failed to auto-rebase:`, e); - } - } -})(); diff --git a/.github/bot/src/cargo/bump.ts b/.github/bot/src/cargo/bump.ts deleted file mode 100644 index 19f2796f4f06..000000000000 --- a/.github/bot/src/cargo/bump.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { exec } from "child_process"; -import { getTitleOfLatestCommit } from "../util/git"; -import { parsePrComments } from "./comment-parser"; -import { promisify } from "util"; - -const execAsync = promisify(exec); - -(async () => { - const latestCommitMessage = await getTitleOfLatestCommit(); - console.log("Latest commit message:", latestCommitMessage); - - const lParenIndex = latestCommitMessage.lastIndexOf("(#"); - - console.log(lParenIndex); - - if (!latestCommitMessage.endsWith(")") || lParenIndex === -1) { - console.log(`This commit does not seems like a PR merge`); - process.exit(1); - return; - } - - const prNumber = parseInt( - latestCommitMessage.substring( - lParenIndex + 2, - latestCommitMessage.length - 1 - ) - ); - - const actions = await parsePrComments(prNumber); - - if (actions.length === 0) { - throw new Error("This commit does not require a bump commit"); - } - - for (const action of actions) { - console.log(action); - - if (action.breaking) { - await execAsync(`cargo mono bump ${action.crate} --breaking`); - } else { - await execAsync(`cargo mono bump ${action.crate} -D`); - } - } -})(); diff --git a/.github/bot/src/cargo/comment-parser.ts b/.github/bot/src/cargo/comment-parser.ts deleted file mode 100644 index c5820d4f989d..000000000000 --- a/.github/bot/src/cargo/comment-parser.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { octokit } from "../util/octokit"; -import YAML from "yaml"; - -const owner = "swc-project"; -const repo = "swc"; - -export interface Action { - crate: string; - breaking: boolean; -} - -export async function parsePrComments(prNumber: number): Promise { - const comments = await octokit.pulls.listReviews({ - owner, - repo, - pull_number: prNumber, - }); - - const maintainers = await octokit.orgs.listPublicMembers({ org: owner }); - - return comments.data - .filter( - (c) => c.user && maintainers.data.find((m) => m.login === c.user?.login) - ) - .map((c) => { - const idx = c.body.indexOf("swc-bump:"); - if (idx === -1) { - return undefined; - } - return c.body.substring(idx); - }) - .filter((text) => !!text) - .map((text) => text!) - .map((text) => YAML.parse(text)) - .map((data) => data["swc-bump"]) - .flatMap((data) => data) - .map((line) => { - if (typeof line !== "string") { - throw new Error(`Non-string data: ${line}`); - } - line = line.trim(); - - console.log(`Comment line: '${line}'`); - - if (line.endsWith(" --breaking")) { - return { - crate: line.substring(0, line.length - " --breaking".length), - breaking: true, - }; - } - - return { - crate: line, - breaking: false, - }; - }) - .filter((l) => !!l); -} diff --git a/.github/bot/src/cargo/ensure-comment.ts b/.github/bot/src/cargo/ensure-comment.ts deleted file mode 100644 index 333abe856791..000000000000 --- a/.github/bot/src/cargo/ensure-comment.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { getCurrentPrNumber } from "../util/octokit"; -import { parsePrComments } from "./comment-parser"; - -(async () => { - const prNumber = getCurrentPrNumber(); - console.log(`Checking PR #${prNumber}`); - - const actions = await parsePrComments(prNumber); - - if (actions.length === 0) { - throw new Error( - "PR does not have a review comment to parse. Please wait for a comment by @kdy1 to be added." - ); - } -})(); diff --git a/.github/workflows/bot-pr.yml b/.github/workflows/bot-pr.yml deleted file mode 100644 index 8d9999ff3f3d..000000000000 --- a/.github/workflows/bot-pr.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Maintenance - -env: - # https://github.com/actions/setup-node/issues/899#issuecomment-1819151595 - SKIP_YARN_COREPACK_CHECK: 1 - -on: - pull_request_review: - -jobs: - ensure-comment: - name: Ensure bump comment - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 - with: - node-version: "16" - - - name: Install dependencies - working-directory: .github/bot - run: | - yarn - - - name: Ensure that bump command exists - working-directory: .github/bot - run: | - npx ts-node src/cargo/ensure-comment.ts