Used inputs
This commit is contained in:
2
.husky/pre-commit
Executable file
2
.husky/pre-commit
Executable file
@@ -0,0 +1,2 @@
|
||||
set -e
|
||||
npm run build && git add dist/
|
||||
11
action.yml
11
action.yml
@@ -5,10 +5,13 @@ author: Skydust
|
||||
# Define your inputs here.
|
||||
inputs:
|
||||
branchesToIgnore:
|
||||
description: The username
|
||||
required: true
|
||||
branchesToRebaseOn:
|
||||
description: ""
|
||||
description: Comma separated branches to ignore
|
||||
default: "dev,main,master"
|
||||
required: false
|
||||
mainBranch:
|
||||
description: "The main branch to rebase on"
|
||||
default: "dev"
|
||||
required: false
|
||||
|
||||
runs:
|
||||
using: 'node20'
|
||||
|
||||
43
app.ts
43
app.ts
@@ -1,10 +1,11 @@
|
||||
import { spawn } from "child_process";
|
||||
import { ChildProcess, SpawnOptions } from "node:child_process";
|
||||
import * as core from '@actions/core';
|
||||
|
||||
// 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 {
|
||||
Rebase = 0,
|
||||
@@ -27,8 +28,9 @@ interface BranchWithDependencies {
|
||||
/**
|
||||
* Helper function to run a Git command and capture stdout and stderr.
|
||||
*/
|
||||
const runGitCommand = (args: string[], options?: SpawnOptions): Promise<string> =>
|
||||
new Promise((resolve, reject) => {
|
||||
const runGitCommand = (args: string[], options?: SpawnOptions): Promise<string> => {
|
||||
console.log(`Running git command: git ${ args.join(" ") }`);
|
||||
return new Promise((resolve, reject) => {
|
||||
const git: ChildProcess = spawn("git", args, { stdio: "pipe", ...options });
|
||||
let stdout: string = "";
|
||||
let stderr: string = "";
|
||||
@@ -41,6 +43,8 @@ const runGitCommand = (args: string[], options?: SpawnOptions): Promise<string>
|
||||
resolve(stdout) :
|
||||
reject(new Error(`Git command failed with code ${code}: ${stderr}`)));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch all remote branches.
|
||||
@@ -52,11 +56,10 @@ const fetchBranches = async (): Promise<string[]> => {
|
||||
|
||||
return branches
|
||||
.split("\n")
|
||||
.map((branch) => branch.trim().replace("origin/", ""))
|
||||
.filter((branch) => !IGNORED_BRANCHES.includes(branch) && branch !== "");
|
||||
.map((branch) => branch.trim())
|
||||
.filter((branch) => !IGNORED_BRANCHES.includes(branch.replace("origin/", "")) && branch !== "");
|
||||
}
|
||||
|
||||
|
||||
// Get the full commit history for a branch
|
||||
const getCommitsForBranch = async (branch: string): Promise<Set<string>> => {
|
||||
const commits = await runGitCommand(["rev-list", branch]);
|
||||
@@ -173,14 +176,20 @@ const rebaseBranch = async ({
|
||||
|
||||
await runGitCommand([
|
||||
"checkout",
|
||||
branch
|
||||
branch.replace("origin/", "")
|
||||
]);
|
||||
|
||||
if(action === Action.Rebase) {
|
||||
await runGitCommand([
|
||||
"rebase",
|
||||
onBranch
|
||||
]);
|
||||
]).catch(async error => {
|
||||
console.error(error);
|
||||
await runGitCommand([
|
||||
"rebase",
|
||||
"--abort"
|
||||
])
|
||||
});
|
||||
} else if(action === Action.Reset) {
|
||||
await runGitCommand([
|
||||
"reset",
|
||||
@@ -195,11 +204,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.
|
||||
*/
|
||||
const main = async (): Promise<void> => {
|
||||
try {
|
||||
await setupAutoRebaseGit();
|
||||
|
||||
// Step 1: Fetch branches
|
||||
const branches: string[] = (await fetchBranches());
|
||||
branches.push(mainBranch)
|
||||
@@ -219,6 +243,7 @@ const main = async (): Promise<void> => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error during workflow execution:", error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
19862
dist/app.js
vendored
19862
dist/app.js
vendored
File diff suppressed because one or more lines are too long
2
dist/package.json
vendored
2
dist/package.json
vendored
@@ -4,6 +4,7 @@
|
||||
"description": "",
|
||||
"main": "app.js",
|
||||
"scripts": {
|
||||
"prepare": "husky",
|
||||
"build": "cp package.json dist/ && esbuild --outdir=dist --bundle --platform=node --allow-overwrite ./app.ts",
|
||||
"dev": "tsx app.ts"
|
||||
},
|
||||
@@ -15,6 +16,7 @@
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.10.0",
|
||||
"esbuild": "^0.24.0",
|
||||
"husky": "^9.1.7",
|
||||
"tsx": "^4.19.2",
|
||||
"typescript": "^5.7.2"
|
||||
},
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"description": "",
|
||||
"main": "app.js",
|
||||
"scripts": {
|
||||
"prepare": "husky",
|
||||
"build": "cp package.json dist/ && esbuild --outdir=dist --bundle --platform=node --allow-overwrite ./app.ts",
|
||||
"dev": "tsx app.ts"
|
||||
},
|
||||
@@ -15,6 +16,7 @@
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.10.0",
|
||||
"esbuild": "^0.24.0",
|
||||
"husky": "^9.1.7",
|
||||
"tsx": "^4.19.2",
|
||||
"typescript": "^5.7.2"
|
||||
},
|
||||
|
||||
@@ -354,6 +354,11 @@ get-tsconfig@^4.7.5:
|
||||
dependencies:
|
||||
resolve-pkg-maps "^1.0.0"
|
||||
|
||||
husky@^9.1.7:
|
||||
version "9.1.7"
|
||||
resolved "https://registry.yarnpkg.com/husky/-/husky-9.1.7.tgz#d46a38035d101b46a70456a850ff4201344c0b2d"
|
||||
integrity sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==
|
||||
|
||||
resolve-pkg-maps@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz#616b3dc2c57056b5588c31cdf4b3d64db133720f"
|
||||
|
||||
Reference in New Issue
Block a user