Changed yarn for pnpm and used new logs from toolkit

This commit is contained in:
2024-12-28 00:08:03 +01:00
committed by Auto Rebase
parent eb50e21241
commit 7e6bef38bf
6 changed files with 1467 additions and 657 deletions

30
app.ts
View File

@@ -1,6 +1,7 @@
import { spawn } from "child_process";
import { ChildProcess, SpawnOptions } from "node:child_process";
import {spawn} from "child_process";
import {ChildProcess, SpawnOptions} from "node:child_process";
import * as core from '@actions/core';
import {LogLevel, writeConsole} from "@skydust/toolkit";
// Ignored branches
const IGNORED_BRANCHES: string[] = core.getInput('branchesToIgnore', { required: false }).split(",");
@@ -29,7 +30,7 @@ interface BranchWithDependencies {
* Helper function to run a Git command and capture stdout and stderr.
*/
const runGitCommand = (args: string[], options?: SpawnOptions): Promise<string> => {
console.log(`Running git command: git ${ args.join(" ") }`);
writeConsole(`Running git command: git ${ args.join(" ") }`);
return new Promise((resolve, reject) => {
const git: ChildProcess = spawn("git", args, { stdio: "pipe", ...options });
let stdout: string = "";
@@ -50,7 +51,7 @@ const runGitCommand = (args: string[], options?: SpawnOptions): Promise<string>
* Fetch all remote branches.
*/
const fetchBranches = async (): Promise<string[]> => {
console.log("Fetching all branches...");
writeConsole("Fetching all branches...");
await runGitCommand(["fetch", "--all"]);
const branches: string = await runGitCommand(["branch", "-r"]);
@@ -81,6 +82,8 @@ const buildRebaseDependencyGraph = async (branches: string[]): Promise<Record<st
const commitHistories: Record<string, Set<string>> = {};
for (const branch of branches) {
commitHistories[branch] = await getCommitsForBranch(branch);
writeConsole(`Commits ${ branch }`, LogLevel.DEBUG);
writeConsole(commitHistories[branch], LogLevel.DEBUG);
}
let finalBranches: Record<string, BranchWithDependencies> = {};
@@ -133,7 +136,7 @@ const buildRebaseDependencyGraph = async (branches: string[]): Promise<Record<st
};
const rebaseOrder = (branchesWithDependencies: Record<string, BranchWithDependencies>): RebaseAction[] => {
console.log("Order everything")
writeConsole("Order everything", LogLevel.DEBUG);
// First choose the right actions
let orderedActions: RebaseAction[] = []
@@ -184,7 +187,8 @@ const rebaseBranch = async ({
"rebase",
onBranch
]).catch(async error => {
console.error(error);
writeConsole(`Failed to rebase ${ branch } on ${ onBranch }`, LogLevel.ERROR);
writeConsole(error, LogLevel.ERROR)
await runGitCommand([
"rebase",
"--abort"
@@ -222,28 +226,32 @@ const setupAutoRebaseGit = async () => {
*/
const main = async (): Promise<void> => {
try {
console.log("Setup auto rebase")
writeConsole("Setup auto rebase");
await setupAutoRebaseGit();
// Step 1: Fetch branches
const branches: string[] = (await fetchBranches());
branches.push(mainBranch)
console.log("Branches:", branches);
writeConsole("Branches");
writeConsole(branches);
// Step 2: Detect dependencies
const dependencies = await buildRebaseDependencyGraph(branches);
console.log("Dependencies:", dependencies);
writeConsole("Dependencies");
writeConsole(dependencies);
// Step 3: Determine rebase order
const order = rebaseOrder(dependencies);
console.log("Rebase order:", order);
writeConsole("Rebase order");
writeConsole(order);
// Step 4: Rebase branches
for (const rebaseAction of order) {
await rebaseBranch(rebaseAction);
}
} catch (error) {
console.error("Error during workflow execution:", error.message);
writeConsole("Error during workflow execution", LogLevel.ERROR);
writeConsole(error.message, LogLevel.ERROR);
process.exit(1);
}
}