Add working-directory support (#18)
Add working-directory support Fixes #15
This commit is contained in:
parent
85a3a6abe4
commit
20d5541dab
3
.github/workflows/test.yml
vendored
3
.github/workflows/test.yml
vendored
@ -23,4 +23,5 @@ jobs:
|
||||
- uses: ./
|
||||
with:
|
||||
version: v1.26
|
||||
args: --issues-exit-code=0 ./sample/...
|
||||
args: --issues-exit-code=0 ./...
|
||||
working-directory: sample
|
||||
|
@ -10,9 +10,9 @@ inputs:
|
||||
description: 'golangci-lint command line arguments'
|
||||
default: ''
|
||||
required: false
|
||||
github-token:
|
||||
description: 'GitHub token with scope `repo.public_repo`. Used for fetching a list of releases of golangci-lint.'
|
||||
required: true
|
||||
working-directory:
|
||||
description: 'golangci-lint working directory, default is project root'
|
||||
required: false
|
||||
|
||||
runs:
|
||||
using: 'node12'
|
||||
|
14
dist/post_run/index.js
vendored
14
dist/post_run/index.js
vendored
@ -2352,6 +2352,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(__webpack_require__(470));
|
||||
const child_process_1 = __webpack_require__(129);
|
||||
const fs = __importStar(__webpack_require__(747));
|
||||
const path = __importStar(__webpack_require__(622));
|
||||
const util_1 = __webpack_require__(669);
|
||||
const cache_1 = __webpack_require__(722);
|
||||
const install_1 = __webpack_require__(655);
|
||||
@ -2396,11 +2398,19 @@ function runLint(lintPath) {
|
||||
if (args.includes(`-out-format`)) {
|
||||
throw new Error(`please, don't change out-format for golangci-lint: it can be broken in a future`);
|
||||
}
|
||||
const workingDirectory = core.getInput(`working-directory`);
|
||||
const cmdArgs = {};
|
||||
if (workingDirectory != ``) {
|
||||
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
|
||||
throw new Error(`working-directory (${workingDirectory}) was not a path`);
|
||||
}
|
||||
cmdArgs.cwd = path.resolve(workingDirectory);
|
||||
}
|
||||
const cmd = `${lintPath} run --out-format=github-actions ${args}`.trimRight();
|
||||
core.info(`Running [${cmd}] ...`);
|
||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd}] ...`);
|
||||
const startedAt = Date.now();
|
||||
try {
|
||||
const res = yield execShellCommand(cmd);
|
||||
const res = yield execShellCommand(cmd, cmdArgs);
|
||||
printOutput(res);
|
||||
core.info(`golangci-lint found no issues`);
|
||||
}
|
||||
|
14
dist/run/index.js
vendored
14
dist/run/index.js
vendored
@ -2364,6 +2364,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(__webpack_require__(470));
|
||||
const child_process_1 = __webpack_require__(129);
|
||||
const fs = __importStar(__webpack_require__(747));
|
||||
const path = __importStar(__webpack_require__(622));
|
||||
const util_1 = __webpack_require__(669);
|
||||
const cache_1 = __webpack_require__(722);
|
||||
const install_1 = __webpack_require__(655);
|
||||
@ -2408,11 +2410,19 @@ function runLint(lintPath) {
|
||||
if (args.includes(`-out-format`)) {
|
||||
throw new Error(`please, don't change out-format for golangci-lint: it can be broken in a future`);
|
||||
}
|
||||
const workingDirectory = core.getInput(`working-directory`);
|
||||
const cmdArgs = {};
|
||||
if (workingDirectory != ``) {
|
||||
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
|
||||
throw new Error(`working-directory (${workingDirectory}) was not a path`);
|
||||
}
|
||||
cmdArgs.cwd = path.resolve(workingDirectory);
|
||||
}
|
||||
const cmd = `${lintPath} run --out-format=github-actions ${args}`.trimRight();
|
||||
core.info(`Running [${cmd}] ...`);
|
||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd}] ...`);
|
||||
const startedAt = Date.now();
|
||||
try {
|
||||
const res = yield execShellCommand(cmd);
|
||||
const res = yield execShellCommand(cmd, cmdArgs);
|
||||
printOutput(res);
|
||||
core.info(`golangci-lint found no issues`);
|
||||
}
|
||||
|
18
src/run.ts
18
src/run.ts
@ -1,5 +1,7 @@
|
||||
import * as core from "@actions/core"
|
||||
import { exec } from "child_process"
|
||||
import { exec, ExecOptions } from "child_process"
|
||||
import * as fs from "fs"
|
||||
import * as path from "path"
|
||||
import { promisify } from "util"
|
||||
|
||||
import { restoreCache, saveCache } from "./cache"
|
||||
@ -55,11 +57,21 @@ async function runLint(lintPath: string): Promise<void> {
|
||||
throw new Error(`please, don't change out-format for golangci-lint: it can be broken in a future`)
|
||||
}
|
||||
|
||||
const workingDirectory = core.getInput(`working-directory`)
|
||||
const cmdArgs: ExecOptions = {}
|
||||
if (workingDirectory != ``) {
|
||||
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
|
||||
throw new Error(`working-directory (${workingDirectory}) was not a path`)
|
||||
}
|
||||
|
||||
cmdArgs.cwd = path.resolve(workingDirectory)
|
||||
}
|
||||
|
||||
const cmd = `${lintPath} run --out-format=github-actions ${args}`.trimRight()
|
||||
core.info(`Running [${cmd}] ...`)
|
||||
core.info(`Running [${cmd}] in [${cmdArgs.cwd}] ...`)
|
||||
const startedAt = Date.now()
|
||||
try {
|
||||
const res = await execShellCommand(cmd)
|
||||
const res = await execShellCommand(cmd, cmdArgs)
|
||||
printOutput(res)
|
||||
core.info(`golangci-lint found no issues`)
|
||||
} catch (exc) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user