Used inputs
This commit is contained in:
11
action.yml
11
action.yml
@@ -5,10 +5,13 @@ author: Skydust
|
|||||||
# Define your inputs here.
|
# Define your inputs here.
|
||||||
inputs:
|
inputs:
|
||||||
branchesToIgnore:
|
branchesToIgnore:
|
||||||
description: The username
|
description: Comma separated branches to ignore
|
||||||
required: true
|
default: "dev,main,master"
|
||||||
branchesToRebaseOn:
|
required: false
|
||||||
description: ""
|
mainBranch:
|
||||||
|
description: "The main branch to rebase on"
|
||||||
|
default: "dev"
|
||||||
|
required: false
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node20'
|
using: 'node20'
|
||||||
|
|||||||
44
app.ts
44
app.ts
@@ -1,10 +1,11 @@
|
|||||||
import { spawn } from "child_process";
|
import { spawn } from "child_process";
|
||||||
import { ChildProcess, SpawnOptions } from "node:child_process";
|
import { ChildProcess, SpawnOptions } from "node:child_process";
|
||||||
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
// Ignored branches
|
// Ignored branches
|
||||||
const IGNORED_BRANCHES = ["master", "main", "dev", "release"];
|
const IGNORED_BRANCHES: string[] = core.getInput('branchesToIgnore', { required: false }).split(",");
|
||||||
|
|
||||||
const mainBranch = "dev";
|
const mainBranch: string = `origin/${ core.getInput('mainBranch', { required: false }) }`;
|
||||||
|
|
||||||
enum Action {
|
enum Action {
|
||||||
Rebase = 0,
|
Rebase = 0,
|
||||||
@@ -27,8 +28,9 @@ interface BranchWithDependencies {
|
|||||||
/**
|
/**
|
||||||
* Helper function to run a Git command and capture stdout and stderr.
|
* Helper function to run a Git command and capture stdout and stderr.
|
||||||
*/
|
*/
|
||||||
const runGitCommand = (args: string[], options?: SpawnOptions): Promise<string> =>
|
const runGitCommand = (args: string[], options?: SpawnOptions): Promise<string> => {
|
||||||
new Promise((resolve, reject) => {
|
console.log(`Running git command: git ${ args.join(" ") }`);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
const git: ChildProcess = spawn("git", args, { stdio: "pipe", ...options });
|
const git: ChildProcess = spawn("git", args, { stdio: "pipe", ...options });
|
||||||
let stdout: string = "";
|
let stdout: string = "";
|
||||||
let stderr: string = "";
|
let stderr: string = "";
|
||||||
@@ -41,6 +43,8 @@ const runGitCommand = (args: string[], options?: SpawnOptions): Promise<string>
|
|||||||
resolve(stdout) :
|
resolve(stdout) :
|
||||||
reject(new Error(`Git command failed with code ${code}: ${stderr}`)));
|
reject(new Error(`Git command failed with code ${code}: ${stderr}`)));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch all remote branches.
|
* Fetch all remote branches.
|
||||||
@@ -52,11 +56,10 @@ const fetchBranches = async (): Promise<string[]> => {
|
|||||||
|
|
||||||
return branches
|
return branches
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.map((branch) => branch.trim().replace("origin/", ""))
|
.map((branch) => branch.trim())
|
||||||
.filter((branch) => !IGNORED_BRANCHES.includes(branch) && branch !== "");
|
.filter((branch) => !IGNORED_BRANCHES.includes(branch.replace("origin/", "")) && branch !== "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get the full commit history for a branch
|
// Get the full commit history for a branch
|
||||||
const getCommitsForBranch = async (branch: string): Promise<Set<string>> => {
|
const getCommitsForBranch = async (branch: string): Promise<Set<string>> => {
|
||||||
const commits = await runGitCommand(["rev-list", branch]);
|
const commits = await runGitCommand(["rev-list", branch]);
|
||||||
@@ -115,6 +118,7 @@ const buildRebaseDependencyGraph = async (branches: string[]): Promise<Record<st
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log(finalBranches);
|
||||||
|
|
||||||
// Set rebase for branches with no dependencies
|
// Set rebase for branches with no dependencies
|
||||||
for (const branch of branches) {
|
for (const branch of branches) {
|
||||||
@@ -173,14 +177,20 @@ const rebaseBranch = async ({
|
|||||||
|
|
||||||
await runGitCommand([
|
await runGitCommand([
|
||||||
"checkout",
|
"checkout",
|
||||||
branch
|
branch.replace("origin/", "")
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if(action === Action.Rebase) {
|
if(action === Action.Rebase) {
|
||||||
await runGitCommand([
|
await runGitCommand([
|
||||||
"rebase",
|
"rebase",
|
||||||
onBranch
|
onBranch
|
||||||
]);
|
]).catch(async error => {
|
||||||
|
console.error(error);
|
||||||
|
await runGitCommand([
|
||||||
|
"rebase",
|
||||||
|
"--abort"
|
||||||
|
])
|
||||||
|
});
|
||||||
} else if(action === Action.Reset) {
|
} else if(action === Action.Reset) {
|
||||||
await runGitCommand([
|
await runGitCommand([
|
||||||
"reset",
|
"reset",
|
||||||
@@ -195,11 +205,26 @@ const rebaseBranch = async ({
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setupAutoRebaseGit = async () => {
|
||||||
|
await runGitCommand([
|
||||||
|
"config",
|
||||||
|
"user.email",
|
||||||
|
"auto-rebase@skydust.fr"
|
||||||
|
]);
|
||||||
|
await runGitCommand([
|
||||||
|
"config",
|
||||||
|
"user.name",
|
||||||
|
"Auto Rebase"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main function to execute the workflow.
|
* Main function to execute the workflow.
|
||||||
*/
|
*/
|
||||||
const main = async (): Promise<void> => {
|
const main = async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
|
await setupAutoRebaseGit();
|
||||||
|
|
||||||
// Step 1: Fetch branches
|
// Step 1: Fetch branches
|
||||||
const branches: string[] = (await fetchBranches());
|
const branches: string[] = (await fetchBranches());
|
||||||
branches.push(mainBranch)
|
branches.push(mainBranch)
|
||||||
@@ -219,6 +244,7 @@ const main = async (): Promise<void> => {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error during workflow execution:", error.message);
|
console.error("Error during workflow execution:", error.message);
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
19863
dist/app.js
vendored
19863
dist/app.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user