From e9b51884a8d0670da6b6f438596941c045ff9d20 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 21 Nov 2025 02:25:36 +0100 Subject: [PATCH] refactor: modify working directory usage inside run --- src/run.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/run.ts b/src/run.ts index 34426d6..ca92e0f 100644 --- a/src/run.ts +++ b/src/run.ts @@ -26,7 +26,7 @@ const printOutput = (res: ExecRes): void => { } } -async function runLint(binPath: string): Promise { +async function runLint(binPath: string, rootDir: string): Promise { const userArgs = core.getInput(`args`) const addedArgs: string[] = [] @@ -84,17 +84,12 @@ async function runLint(binPath: string): Promise { const cmdArgs: ExecOptionsWithStringEncoding = {} - const workingDirectory = core.getInput(`working-directory`) - if (workingDirectory) { - if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) { - throw new Error(`working-directory (${workingDirectory}) was not a path`) - } - + if (rootDir) { if (!userArgNames.has(`path-prefix`) && !userArgNames.has(`path-mode`)) { addedArgs.push(`--path-mode=abs`) } - cmdArgs.cwd = path.resolve(workingDirectory) + cmdArgs.cwd = path.resolve(rootDir) } await runVerify(binPath, userArgsMap, cmdArgs) @@ -178,6 +173,17 @@ async function debugAction(binPath: string) { } } +function getWorkingDirectory(): string { + const workingDirectory = core.getInput(`working-directory`) + if (workingDirectory) { + if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) { + throw new Error(`working-directory (${workingDirectory}) was not a path`) + } + } + + return workingDirectory +} + export async function run(): Promise { try { await core.group(`Restore cache`, restoreCache) @@ -195,7 +201,7 @@ export async function run(): Promise { return } - await core.group(`run golangci-lint`, () => runLint(binPath)) + await core.group(`run golangci-lint`, () => runLint(binPath, getWorkingDirectory())) } catch (error) { core.error(`Failed to run: ${error}, ${error.stack}`) core.setFailed(error.message)