mirror of
https://github.com/golangci/golangci-lint-action.git
synced 2025-12-13 14:31:15 +00:00
feat: automatic-module-directories
This commit is contained in:
parent
e9b51884a8
commit
161a55b8c4
1 changed files with 38 additions and 2 deletions
40
src/run.ts
40
src/run.ts
|
|
@ -26,7 +26,7 @@ const printOutput = (res: ExecRes): void => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runLint(binPath: string, rootDir: string): Promise<void> {
|
async function runGolangciLint(binPath: string, rootDir: string): Promise<void> {
|
||||||
const userArgs = core.getInput(`args`)
|
const userArgs = core.getInput(`args`)
|
||||||
const addedArgs: string[] = []
|
const addedArgs: string[] = []
|
||||||
|
|
||||||
|
|
@ -184,6 +184,42 @@ function getWorkingDirectory(): string {
|
||||||
return workingDirectory
|
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<void> {
|
||||||
|
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<void> {
|
export async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await core.group(`Restore cache`, restoreCache)
|
await core.group(`Restore cache`, restoreCache)
|
||||||
|
|
@ -201,7 +237,7 @@ export async function run(): Promise<void> {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await core.group(`run golangci-lint`, () => runLint(binPath, getWorkingDirectory()))
|
await runLint(binPath)
|
||||||
} 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