Skip to content

Add working-directory support #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ jobs:
- uses: ./
with:
version: v1.26
args: --issues-exit-code=0 ./sample/...
args: --issues-exit-code=0 ./...
working-directory: sample
8 changes: 4 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ 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'
main: 'dist/run/index.js'
post: 'dist/post_run/index.js'
branding:
icon: 'shield'
color: 'yellow'
color: 'yellow'
14 changes: 12 additions & 2 deletions dist/post_run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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`);
}
Expand Down
14 changes: 12 additions & 2 deletions dist/run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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`);
}
Expand Down
18 changes: 15 additions & 3 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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) {
Expand Down