Compare commits

...

5 Commits

Author SHA1 Message Date
64c208bfbc docs: add working-directory to README 2020-05-21 14:43:37 +03:00
20d5541dab Add working-directory support (#18)
Add working-directory support

Fixes #15
2020-05-21 14:36:02 +03:00
85a3a6abe4 docs: remove 'beta version' 2020-05-16 17:24:18 +03:00
b66692b61d mark the action as stable: v0 -> v1 2020-05-16 17:20:48 +03:00
348830fe4b docs: recommend distinct job 2020-05-09 18:48:24 +03:00
6 changed files with 54 additions and 15 deletions

View File

@ -23,4 +23,5 @@ jobs:
- uses: ./
with:
version: v1.26
args: --issues-exit-code=0 ./sample/...
args: --issues-exit-code=0 ./...
working-directory: sample

View File

@ -27,15 +27,21 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v0.2.0
uses: golangci/golangci-lint-action@v1
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.26
# Optional: working directory, useful for monorepos
# working-directory: somedir
# Optional: golangci-lint command line arguments.
# args: ./the-only-dir-to-analyze/...
# args: --issues-exit-code=0
```
We recommend running this action in a job separate from other jobs (`go test`, etc)
because different jobs [run in parallel](https://help.github.com/en/actions/getting-started-with-github-actions/core-concepts-for-github-actions#job).
## Comments and Annotations
Currently, GitHub parses the action's output and creates [annotations](https://github.community/t5/GitHub-Actions/What-are-annotations/td-p/30770).

View File

@ -1,6 +1,6 @@
---
name: 'Run golangci-lint'
description: 'Official golangci-lint action with line-attached annotations for found issues, caching and parallel execution. Beta version.'
description: 'Official golangci-lint action with line-attached annotations for found issues, caching and parallel execution.'
author: 'golangci'
inputs:
version:
@ -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'
@ -20,4 +20,4 @@ runs:
post: 'dist/post_run/index.js'
branding:
icon: 'shield'
color: 'yellow'
color: 'yellow'

View File

@ -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
View File

@ -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`);
}

View File

@ -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) {