mirror of
https://github.com/swc-project/swc.git
synced 2024-12-26 07:02:28 +03:00
refactor: Remove unused files (#9285)
This commit is contained in:
parent
6afa40b7b4
commit
33284c128e
87
.github/bot/src/auto-rebase.ts
vendored
87
.github/bot/src/auto-rebase.ts
vendored
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})();
|
|
44
.github/bot/src/cargo/bump.ts
vendored
44
.github/bot/src/cargo/bump.ts
vendored
@ -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`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})();
|
|
58
.github/bot/src/cargo/comment-parser.ts
vendored
58
.github/bot/src/cargo/comment-parser.ts
vendored
@ -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<Action[]> {
|
|
||||||
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);
|
|
||||||
}
|
|
15
.github/bot/src/cargo/ensure-comment.ts
vendored
15
.github/bot/src/cargo/ensure-comment.ts
vendored
@ -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."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})();
|
|
29
.github/workflows/bot-pr.yml
vendored
29
.github/workflows/bot-pr.yml
vendored
@ -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
|
|
Loading…
Reference in New Issue
Block a user