Skip to content

Commit 40fdea6

Browse files
committed
Add working-directory support
Fixes golangci#15
1 parent 85a3a6a commit 40fdea6

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ jobs:
2323
- uses: ./
2424
with:
2525
version: v1.26
26-
args: --issues-exit-code=0 ./sample/...
26+
args: --issues-exit-code=0 ./...
27+
working-directory: sample

dist/post_run/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23522352
Object.defineProperty(exports, "__esModule", { value: true });
23532353
const core = __importStar(__webpack_require__(470));
23542354
const child_process_1 = __webpack_require__(129);
2355+
const path = __importStar(__webpack_require__(622));
2356+
const fs = __importStar(__webpack_require__(747));
23552357
const util_1 = __webpack_require__(669);
23562358
const cache_1 = __webpack_require__(722);
23572359
const install_1 = __webpack_require__(655);
@@ -2396,11 +2398,15 @@ function runLint(lintPath) {
23962398
if (args.includes(`-out-format`)) {
23972399
throw new Error(`please, don't change out-format for golangci-lint: it can be broken in a future`);
23982400
}
2401+
const workingDirectory = path.resolve(core.getInput(`working-directory`));
2402+
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
2403+
throw new Error(`working-directory (${workingDirectory}) was not a path`);
2404+
}
23992405
const cmd = `${lintPath} run --out-format=github-actions ${args}`.trimRight();
24002406
core.info(`Running [${cmd}] ...`);
24012407
const startedAt = Date.now();
24022408
try {
2403-
const res = yield execShellCommand(cmd);
2409+
const res = yield execShellCommand(cmd, { cwd: workingDirectory });
24042410
printOutput(res);
24052411
core.info(`golangci-lint found no issues`);
24062412
}

dist/run/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23642364
Object.defineProperty(exports, "__esModule", { value: true });
23652365
const core = __importStar(__webpack_require__(470));
23662366
const child_process_1 = __webpack_require__(129);
2367+
const path = __importStar(__webpack_require__(622));
2368+
const fs = __importStar(__webpack_require__(747));
23672369
const util_1 = __webpack_require__(669);
23682370
const cache_1 = __webpack_require__(722);
23692371
const install_1 = __webpack_require__(655);
@@ -2408,11 +2410,15 @@ function runLint(lintPath) {
24082410
if (args.includes(`-out-format`)) {
24092411
throw new Error(`please, don't change out-format for golangci-lint: it can be broken in a future`);
24102412
}
2413+
const workingDirectory = path.resolve(core.getInput(`working-directory`));
2414+
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
2415+
throw new Error(`working-directory (${workingDirectory}) was not a path`);
2416+
}
24112417
const cmd = `${lintPath} run --out-format=github-actions ${args}`.trimRight();
24122418
core.info(`Running [${cmd}] ...`);
24132419
const startedAt = Date.now();
24142420
try {
2415-
const res = yield execShellCommand(cmd);
2421+
const res = yield execShellCommand(cmd, { cwd: workingDirectory });
24162422
printOutput(res);
24172423
core.info(`golangci-lint found no issues`);
24182424
}

src/run.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as core from "@actions/core"
22
import { exec } from "child_process"
3+
import * as path from "path"
4+
import * as fs from "fs"
35
import { promisify } from "util"
46

57
import { restoreCache, saveCache } from "./cache"
@@ -55,11 +57,16 @@ async function runLint(lintPath: string): Promise<void> {
5557
throw new Error(`please, don't change out-format for golangci-lint: it can be broken in a future`)
5658
}
5759

60+
const workingDirectory = path.resolve(core.getInput(`working-directory`))
61+
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
62+
throw new Error(`working-directory (${workingDirectory}) was not a path`)
63+
}
64+
5865
const cmd = `${lintPath} run --out-format=github-actions ${args}`.trimRight()
5966
core.info(`Running [${cmd}] ...`)
6067
const startedAt = Date.now()
6168
try {
62-
const res = await execShellCommand(cmd)
69+
const res = await execShellCommand(cmd, { cwd: workingDirectory })
6370
printOutput(res)
6471
core.info(`golangci-lint found no issues`)
6572
} catch (exc) {

0 commit comments

Comments
 (0)