mirror of
https://github.com/golangci/golangci-lint-action.git
synced 2025-12-12 14:01:14 +00:00
refactor: modify working directory usage inside run
This commit is contained in:
parent
3da8bd416a
commit
e9b51884a8
1 changed files with 15 additions and 9 deletions
24
src/run.ts
24
src/run.ts
|
|
@ -26,7 +26,7 @@ const printOutput = (res: ExecRes): void => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runLint(binPath: string): Promise<void> {
|
async function runLint(binPath: string, rootDir: string): Promise<void> {
|
||||||
const userArgs = core.getInput(`args`)
|
const userArgs = core.getInput(`args`)
|
||||||
const addedArgs: string[] = []
|
const addedArgs: string[] = []
|
||||||
|
|
||||||
|
|
@ -84,17 +84,12 @@ async function runLint(binPath: string): Promise<void> {
|
||||||
|
|
||||||
const cmdArgs: ExecOptionsWithStringEncoding = {}
|
const cmdArgs: ExecOptionsWithStringEncoding = {}
|
||||||
|
|
||||||
const workingDirectory = core.getInput(`working-directory`)
|
if (rootDir) {
|
||||||
if (workingDirectory) {
|
|
||||||
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
|
|
||||||
throw new Error(`working-directory (${workingDirectory}) was not a path`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!userArgNames.has(`path-prefix`) && !userArgNames.has(`path-mode`)) {
|
if (!userArgNames.has(`path-prefix`) && !userArgNames.has(`path-mode`)) {
|
||||||
addedArgs.push(`--path-mode=abs`)
|
addedArgs.push(`--path-mode=abs`)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdArgs.cwd = path.resolve(workingDirectory)
|
cmdArgs.cwd = path.resolve(rootDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
await runVerify(binPath, userArgsMap, cmdArgs)
|
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<void> {
|
export async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await core.group(`Restore cache`, restoreCache)
|
await core.group(`Restore cache`, restoreCache)
|
||||||
|
|
@ -195,7 +201,7 @@ export async function run(): Promise<void> {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await core.group(`run golangci-lint`, () => runLint(binPath))
|
await core.group(`run golangci-lint`, () => runLint(binPath, getWorkingDirectory()))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.error(`Failed to run: ${error}, ${error.stack}`)
|
core.error(`Failed to run: ${error}, ${error.stack}`)
|
||||||
core.setFailed(error.message)
|
core.setFailed(error.message)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue