From 161a55b8c4ce4bf22019386237c618d9194ef339 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 21 Nov 2025 03:18:27 +0100 Subject: [PATCH] feat: automatic-module-directories --- src/run.ts | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/run.ts b/src/run.ts index ca92e0f..7faeafb 100644 --- a/src/run.ts +++ b/src/run.ts @@ -26,7 +26,7 @@ const printOutput = (res: ExecRes): void => { } } -async function runLint(binPath: string, rootDir: string): Promise { +async function runGolangciLint(binPath: string, rootDir: string): Promise { const userArgs = core.getInput(`args`) const addedArgs: string[] = [] @@ -184,6 +184,42 @@ function getWorkingDirectory(): string { return workingDirectory } +function modulesAutoDetection(rootDir: string): string[] { + const o: fs.GlobOptions = { + cwd: rootDir, + exclude: ["**/vendor/**", "**/node_modules/**", "**/.git/**", "**/dist/**"], + } + + const matches = fs.globSync("**/go.mod", o) + + const dirs = matches + .filter((m) => typeof m === "string") + .map((m) => path.resolve(rootDir, path.dirname(m))) + .sort() + + return [...new Set(dirs)] +} + +async function runLint(binPath: string): Promise { + const workingDirectory = getWorkingDirectory() + + const experimental = core.getInput(`experimental`).split(`,`) + + if (experimental.includes(`automatic-module-directories`)) { + const wds = modulesAutoDetection(workingDirectory) + + const cwd = process.cwd() + + for (const wd of wds) { + await core.group(`run golangci-lint in ${path.relative(cwd, wd)}`, () => runGolangciLint(binPath, wd)) + } + + return + } + + await core.group(`run golangci-lint`, () => runGolangciLint(binPath, workingDirectory)) +} + export async function run(): Promise { try { await core.group(`Restore cache`, restoreCache) @@ -201,7 +237,7 @@ export async function run(): Promise { return } - await core.group(`run golangci-lint`, () => runLint(binPath, getWorkingDirectory())) + await runLint(binPath) } catch (error) { core.error(`Failed to run: ${error}, ${error.stack}`) core.setFailed(error.message)