mirror of
https://github.com/golangci/golangci-lint-action.git
synced 2025-12-12 14:01:14 +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 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<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> {
|
||||
try {
|
||||
await core.group(`Restore cache`, restoreCache)
|
||||
|
|
@ -201,7 +237,7 @@ export async function run(): Promise<void> {
|
|||
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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue