github.com/mattbailey/reviewdog@v0.10.0/README.md (about) 1 <p align="center"> 2 <a href="https://github.com/reviewdog/reviewdog"> 3 <img alt="reviewdog" src="https://raw.githubusercontent.com/haya14busa/i/d598ed7dc49fefb0018e422e4c43e5ab8f207a6b/reviewdog/reviewdog.logo.png"> 4 </a> 5 </p> 6 7 <h2 align="center"> 8 reviewdog - A code review dog who keeps your codebase healthy. 9 </h2> 10 11 <p align="center"> 12 <a href="https://github.com/reviewdog/reviewdog/blob/master/LICENSE"> 13 <img alt="LICENSE" src="https://img.shields.io/badge/license-MIT-blue.svg?maxAge=43200"> 14 </a> 15 <a href="https://godoc.org/github.com/reviewdog/reviewdog"> 16 <img alt="GoDoc" src="https://img.shields.io/badge/godoc-reference-4F73B3.svg?label=godoc.org&maxAge=43200&logo=go"> 17 </a> 18 <a href="https://github.com/reviewdog/reviewdog/releases"> 19 <img alt="releases" src="https://img.shields.io/github/release/reviewdog/reviewdog.svg?logo=github"> 20 </a> 21 <a href="https://somsubhra.com/github-release-stats/?username=reviewdog&repository=reviewdog"> 22 <img alt="Github Releases Stats" src="https://img.shields.io/github/downloads/reviewdog/reviewdog/total.svg?logo=github"> 23 </a> 24 <a href="https://gitlab.com/reviewdog/reviewdog/pipelines"> 25 <img alt="GitLab Supported" src="https://img.shields.io/badge/GitLab%20-Supported-fc6d26?logo=gitlab"> 26 </a> 27 </p> 28 29 <p align="center"> 30 <a href="https://github.com/reviewdog/reviewdog/actions?query=workflow%3AGo+event%3Apush+branch%3Amaster"> 31 <img alt="GitHub Actions" src="https://github.com/reviewdog/reviewdog/workflows/Go/badge.svg"> 32 </a> 33 <a href="https://github.com/reviewdog/reviewdog/actions?query=workflow%3Areviewdog+event%3Apush+branch%3Amaster"> 34 <img alt="reviewdog" src="https://github.com/reviewdog/reviewdog/workflows/reviewdog/badge.svg?branch=master&event=push"> 35 </a> 36 <a href="https://travis-ci.org/reviewdog/reviewdog"><img alt="Travis Status" src="https://img.shields.io/travis/reviewdog/reviewdog/master.svg?label=Travis&logo=travis"></a> 37 <a href="https://circleci.com/gh/reviewdog/reviewdog"><img alt="CircleCI Status" src="http://img.shields.io/circleci/build/github/reviewdog/reviewdog/master.svg?label=CircleCI&logo=circleci"></a> 38 <a href="https://codecov.io/github/reviewdog/reviewdog"><img alt="Coverage Status" src="https://img.shields.io/codecov/c/github/reviewdog/reviewdog/master.svg?logo=codecov"></a> 39 <a href="https://starcharts.herokuapp.com/reviewdog/reviewdog"><img alt="Stars" src="https://img.shields.io/github/stars/reviewdog/reviewdog.svg?style=social"></a> 40 </p> 41 42 "reviewdog" provides a way to post review comments to code hosting service, 43 such as GitHub, automatically by integrating with any linter tools with ease. 44 It uses an output of lint tools and posts them as a comment if findings are in 45 diff of patches to review. 46 47 reviewdog also supports run in the local environment to filter an output of lint tools 48 by diff. 49 50 [design doc](https://docs.google.com/document/d/1mGOX19SSqRowWGbXieBfGPtLnM0BdTkIc9JelTiu6wA/edit?usp=sharing) 51 52 ## Table of Contents 53 54 - [Installation](#installation) 55 - [Input Format](#input-format) 56 * ['errorformat'](#errorformat) 57 * [Available pre-defined 'errorformat'](#available-pre-defined-errorformat) 58 * [checkstyle format](#checkstyle-format) 59 - [reviewdog config file](#reviewdog-config-file) 60 - [Reporters](#reporters) 61 * [Reporter: Local (-reporter=local) [default]](#reporter-local--reporterlocal-default) 62 * [Reporter: GitHub Checks (-reporter=github-pr-check)](#reporter-github-checks--reportergithub-pr-check) 63 * [Reporter: GitHub Checks (-reporter=github-check)](#reporter-github-checks--reportergithub-check) 64 * [Reporter: GitHub PullRequest review comment (-reporter=github-pr-review)](#reporter-github-pullrequest-review-comment--reportergithub-pr-review) 65 * [Reporter: GitLab MergeRequest discussions (-reporter=gitlab-mr-discussion)](#reporter-gitlab-mergerequest-discussions--reportergitlab-mr-discussion) 66 * [Reporter: GitLab MergeRequest commit (-reporter=gitlab-mr-commit)](#reporter-gitlab-mergerequest-commit--reportergitlab-mr-commit) 67 - [Supported CI services](#supported-ci-services) 68 * [GitHub Actions](#github-actions) 69 * [Travis CI](#travis-ci) 70 * [Circle CI](#circle-ci) 71 * [GitLab CI](#gitlab-ci) 72 * [Common (Jenkins, local, etc...)](#common-jenkins-local-etc) 73 + [Jenkins with Github pull request builder plugin](#jenkins-with-github-pull-request-builder-plugin) 74 - [Exit codes](#exit-codes) 75 - [Articles](#articles) 76 77 [![github-pr-check sample](https://user-images.githubusercontent.com/3797062/40884858-6efd82a0-6756-11e8-9f1a-c6af4f920fb0.png)](https://github.com/reviewdog/reviewdog/pull/131/checks) 78 ![comment in pull-request](https://user-images.githubusercontent.com/3797062/40941822-1d775064-6887-11e8-98e9-4775d37d47f8.png) 79 ![commit status](https://user-images.githubusercontent.com/3797062/40941738-d62acb0a-6886-11e8-858d-7b97aded2a42.png) 80 [![sample-comment.png](https://raw.githubusercontent.com/haya14busa/i/dc0ccb1e110515ea407c146d99b749018db05c45/reviewdog/sample-comment.png)](https://github.com/reviewdog/reviewdog/pull/24#discussion_r84599728) 81 ![reviewdog-local-demo.gif](https://raw.githubusercontent.com/haya14busa/i/dc0ccb1e110515ea407c146d99b749018db05c45/reviewdog/reviewdog-local-demo.gif) 82 83 ## Installation 84 85 ```shell 86 # Install the latest version. (Install it into ./bin/ by default). 87 $ curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s 88 89 # Specify installation directory ($(go env GOPATH)/bin/) and version. 90 $ curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b $(go env GOPATH)/bin [vX.Y.Z] 91 92 # In alpine linux (as it does not come with curl by default) 93 $ wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s [vX.Y.Z] 94 ``` 95 96 or 97 98 ```shell 99 $ go get -u github.com/reviewdog/reviewdog/cmd/reviewdog 100 ``` 101 102 ### homebrew / linuxbrew 103 You can also install reviewdog using brew: 104 105 ```shell 106 $ brew install reviewdog/tap/reviewdog 107 $ brew upgrade reviewdog/tap/reviewdog 108 ``` 109 110 ## Input Format 111 112 ### 'errorformat' 113 114 reviewdog accepts any compiler or linter result from stdin and parses it with 115 scan-f like [**'errorformat'**](https://github.com/reviewdog/errorformat), 116 which is the port of Vim's [errorformat](https://vim-jp.org/vimdoc-en/quickfix.html#error-file-format) 117 feature. 118 119 For example, if the result format is `{file}:{line number}:{column number}: {message}`, 120 errorformat should be `%f:%l:%c: %m` and you can pass it as `-efm` arguments. 121 122 ```shell 123 $ golint ./... 124 comment_iowriter.go:11:6: exported type CommentWriter should have comment or be unexported 125 $ golint ./... | reviewdog -efm="%f:%l:%c: %m" -diff="git diff master" 126 ``` 127 128 | name | description | 129 | ---- | ----------- | 130 | %f | file name | 131 | %l | line number | 132 | %c | column number | 133 | %m | error message | 134 | %% | the single '%' character | 135 | ... | ... | 136 137 Please see [reviewdog/errorformat](https://github.com/reviewdog/errorformat) 138 and [:h errorformat](https://vim-jp.org/vimdoc-en/quickfix.html#error-file-format) 139 if you want to deal with a more complex output. 'errorformat' can handle more 140 complex output like a multi-line error message. 141 142 You can also try errorformat on [the Playground](https://reviewdog.github.io/errorformat-playground/)! 143 144 By this 'errorformat' feature, reviewdog can support any tools output with ease. 145 146 ### Available pre-defined 'errorformat' 147 148 But, you don't have to write 'errorformat' in many cases. reviewdog supports 149 pre-defined errorformat for major tools. 150 151 You can find available errorformat name by `reviewdog -list` and you can use it 152 with `-f={name}`. 153 154 ```shell 155 $ reviewdog -list 156 golint linter for Go source code - https://github.com/golang/lint 157 govet Vet examines Go source code and reports suspicious problems - https://golang.org/cmd/vet/ 158 sbt the interactive build tool - http://www.scala-sbt.org/ 159 ... 160 ``` 161 162 ```shell 163 $ golint ./... | reviewdog -f=golint -diff="git diff master" 164 ``` 165 166 You can add supported pre-defined 'errorformat' by contributing to [reviewdog/errorformat](https://github.com/reviewdog/errorformat) 167 168 ### checkstyle format 169 170 reviewdog also accepts [checkstyle XML format](http://checkstyle.sourceforge.net/) as well. 171 If the linter supports checkstyle format as a report format, you can use 172 -f=checkstyle instead of using 'errorformat'. 173 174 ```shell 175 # Local 176 $ eslint -f checkstyle . | reviewdog -f=checkstyle -diff="git diff" 177 178 # CI (overwrite tool name which is shown in review comment by -name arg) 179 $ eslint -f checkstyle . | reviewdog -f=checkstyle -name="eslint" -reporter=github-pr-check 180 ``` 181 182 Also, if you want to pass other Json/XML/etc... format to reviewdog, you can write a converter. 183 184 ```shell 185 $ <linter> | <convert-to-checkstyle> | reviewdog -f=checkstyle -name="<linter>" -reporter=github-pr-check 186 ``` 187 188 ## reviewdog config file 189 190 reviewdog can also be controlled via the .reviewdog.yml configuration file instead of "-f" or "-efm" arguments. 191 192 With .reviewdog.yml, you can run the same commands both CI service and local 193 environment including editor integration with ease. 194 195 #### .reviewdog.yml 196 197 ```yaml 198 runner: 199 <tool-name>: 200 cmd: <command> # (required) 201 errorformat: # (optional if there is supported format for <tool-name>. see reviewdog -list) 202 - <list of errorformat> 203 name: <tool-name> # (optional. you can overwrite <tool-name> defined by runner key) 204 level: <level> # (optional. same as -level flag. [info,warning,error]) 205 206 # examples 207 golint: 208 cmd: golint ./... 209 errorformat: 210 - "%f:%l:%c: %m" 211 level: warning 212 govet: 213 cmd: go vet -all . 214 ``` 215 216 ```shell 217 $ reviewdog -diff="git diff master" 218 project/run_test.go:61:28: [golint] error strings should not end with punctuation 219 project/run.go:57:18: [errcheck] defer os.Setenv(name, os.Getenv(name)) 220 project/run.go:58:12: [errcheck] os.Setenv(name, "") 221 # You can use -runners to run only specified runners. 222 $ reviewdog -diff="git diff master" -runners=golint,govet 223 project/run_test.go:61:28: [golint] error strings should not end with punctuation 224 # You can use -conf to specify config file path. 225 $ reviewdog -conf=./.reviewdog.yml -reporter=github-pr-check 226 ``` 227 228 Output format for project config based run is one of the following formats. 229 230 - `<file>: [<tool name>] <message>` 231 - `<file>:<lnum>: [<tool name>] <message>` 232 - `<file>:<lnum>:<col>: [<tool name>] <message>` 233 234 ## Reporters 235 236 reviewdog can report results both in local environment and review services as 237 continuous integration. 238 239 ### Reporter: Local (-reporter=local) [default] 240 241 reviewdog can find newly introduced findings by filtering linter results 242 using diff. You can pass diff command as `-diff` arg. 243 244 ```shell 245 $ golint ./... | reviewdog -f=golint -diff="git diff master" 246 ``` 247 248 ### Reporter: GitHub Checks (-reporter=github-pr-check) 249 250 [![github-pr-check sample annotation with option 1](https://user-images.githubusercontent.com/3797062/64875597-65016f80-d688-11e9-843f-4679fb666f0d.png)](https://github.com/reviewdog/reviewdog/pull/275/files#annotation_6177941961779419) 251 [![github-pr-check sample](https://user-images.githubusercontent.com/3797062/40884858-6efd82a0-6756-11e8-9f1a-c6af4f920fb0.png)](https://github.com/reviewdog/reviewdog/pull/131/checks) 252 253 github-pr-check reporter reports results to [GitHub Checks](https://help.github.com/articles/about-status-checks/). 254 255 You can change report level for this reporter by `level` field in [config 256 file](#reviewdog-config-file) or `-level` flag. You can control GitHub status 257 check result with this feature. (default: error) 258 259 | Level | GitHub Status | 260 | --------- | ------------- | 261 | `info` | neutral | 262 | `warning` | neutral | 263 | `error` | failure | 264 265 There are two options to use this reporter. 266 267 #### Option 1) Run reviewdog from GitHub Actions w/ secrets.GITHUB_TOKEN 268 269 Example: [.github/workflows/reviewdog.yml](.github/workflows/reviewdog.yml) 270 271 ```yaml 272 - name: Run reviewdog 273 env: 274 REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} 275 run: | 276 golint ./... | reviewdog -f=golint -reporter=github-pr-check 277 ``` 278 279 See [GitHub Actions](#github-actions) section too. You can also use public 280 reviewdog GitHub Actions. 281 282 #### Option 2) Install reviewdog GitHub Apps 283 reviewdog CLI send a request to reviewdog GitHub App server and the server post 284 results as GitHub Checks, because Check API only supported for GitHub App and 285 GitHub Actions. 286 287 1. Install reviewdog Apps. https://github.com/apps/reviewdog 288 2. Set `REVIEWDOG_TOKEN` or run reviewdog CLI in trusted CI providers. 289 - Get token from `https://reviewdog.app/gh/{owner}/{repo-name}`. 290 291 ```shell 292 $ export REVIEWDOG_TOKEN="<token>" 293 $ reviewdog -reporter=github-pr-check 294 ``` 295 296 Note: Token is not required if you run reviewdog in Travis or AppVeyor. 297 298 *Caution* 299 300 As described above, github-pr-check reporter with Option 2 depends on 301 reviewdog GitHub App server. 302 The server is running with haya14busa's pocket money for now and I may break 303 things, so I cannot ensure that the server is running 24h and 365 days. 304 305 **UPDATE:** Started getting support by [opencollective](https://opencollective.com/reviewdog) 306 and GitHub sponsor. 307 See [Supporting reviewdog](#supporting-reviewdog) 308 309 github-pr-check reporter is better than github-pr-review reporter in general 310 because it provides more rich feature and has less scope, but please bear in 311 mind the above caution and please use it on your own risk. 312 313 You can use github-pr-review reporter if you don't want to depend on reviewdog 314 server. 315 316 ### Reporter: GitHub Checks (-reporter=github-check) 317 318 It's basically same as `-reporter=github-pr-check` except it works not only for 319 Pull Request but also for commit and it reports results outside Pull Request 320 diff too. 321 322 [![sample comment outside diff](https://user-images.githubusercontent.com/3797062/69917921-e0680580-14ae-11ea-9a56-de9e3cbac005.png)](https://github.com/reviewdog/reviewdog/pull/364/files) 323 324 You can create [reviewdog badge](#reviewdog-badge-) for this reporter. 325 326 ### Reporter: GitHub PullRequest review comment (-reporter=github-pr-review) 327 328 [![sample-comment.png](https://raw.githubusercontent.com/haya14busa/i/dc0ccb1e110515ea407c146d99b749018db05c45/reviewdog/sample-comment.png)](https://github.com/reviewdog/reviewdog/pull/24#discussion_r84599728) 329 330 github-pr-review reporter reports results to GitHub PullRequest review comments 331 using GitHub Personal API Access Token. 332 [GitHub Enterprise](https://enterprise.github.com/home) is supported too. 333 334 - Go to https://github.com/settings/tokens and generate new API token. 335 - Check `repo` for private repositories or `public_repo` for public repositories. 336 337 ```shell 338 $ export REVIEWDOG_GITHUB_API_TOKEN="<token>" 339 $ reviewdog -reporter=github-pr-review 340 ``` 341 342 For GitHub Enterprise, set API endpoint by environment variable. 343 344 ```shell 345 $ export GITHUB_API="https://example.githubenterprise.com/api/v3/" 346 $ export REVIEWDOG_INSECURE_SKIP_VERIFY=true # set this as you need to skip verifying SSL 347 ``` 348 349 See [GitHub Actions](#github-actions) section too if you can use GitHub 350 Actions. You can also use public reviewdog GitHub Actions. 351 352 ### Reporter: GitLab MergeRequest discussions (-reporter=gitlab-mr-discussion) 353 354 [![gitlab-mr-discussion sample](https://user-images.githubusercontent.com/3797062/41810718-f91bc540-773d-11e8-8598-fbc09ce9b1c7.png)](https://gitlab.com/haya14busa/reviewdog/merge_requests/113#note_83411103) 355 356 Required GitLab version: >= v10.8.0 357 358 gitlab-mr-discussion reporter reports results to GitLab MergeRequest discussions using 359 GitLab Personal API Access token. 360 Get the token with `api` scope from https://gitlab.com/profile/personal_access_tokens. 361 362 ```shell 363 $ export REVIEWDOG_GITLAB_API_TOKEN="<token>" 364 $ reviewdog -reporter=gitlab-mr-discussion 365 ``` 366 367 For self-hosted GitLab, set API endpoint by environment variable. 368 369 ```shell 370 $ export GITLAB_API="https://example.gitlab.com/api/v4" 371 $ export REVIEWDOG_INSECURE_SKIP_VERIFY=true # set this as you need to skip verifying SSL 372 ``` 373 374 ### Reporter: GitLab MergeRequest commit (-reporter=gitlab-mr-commit) 375 376 gitlab-mr-commit is similar to [gitlab-mr-discussion](#reporter-gitlab-mergerequest-discussions--reportergitlab-mr-discussion) reporter but reports results to each commit in GitLab MergeRequest. 377 378 gitlab-mr-discussion is recommended, but you can use gitlab-mr-commit reporter 379 if your GitLab version is under v10.8.0. 380 381 ```shell 382 $ export REVIEWDOG_GITLAB_API_TOKEN="<token>" 383 $ reviewdog -reporter=gitlab-mr-commit 384 ``` 385 386 ## Supported CI services 387 388 ### [GitHub Actions](https://github.com/features/actions) 389 390 Example: [.github/workflows/reviewdog.yml](.github/workflows/reviewdog.yml) 391 392 ```yaml 393 name: reviewdog 394 on: [pull_request] 395 jobs: 396 reviewdog: 397 name: reviewdog 398 runs-on: ubuntu-latest 399 steps: 400 # ... 401 - name: Setup reviewdog 402 run: | 403 mkdir -p $HOME/bin && curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b $HOME/bin 404 echo ::add-path::$HOME/bin 405 echo ::add-path::$(go env GOPATH)/bin # for Go projects 406 - name: Run reviewdog 407 env: 408 REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} 409 run: | 410 reviewdog -reporter=github-pr-check -runners=golint,govet 411 # or 412 reviewdog -reporter=github-pr-review -runners=golint,govet 413 ``` 414 415 <details> 416 <summary><strong>Example (github-check reporter):</strong></summary> 417 418 [.github/workflows/reviewdog](.github/workflows/reviewdog.yml) 419 420 Only `github-check` reporter can run on push event too. 421 422 ```yaml 423 name: reviewdog (github-check) 424 on: 425 push: 426 branches: 427 - master 428 pull_request: 429 430 jobs: 431 reviewdog: 432 name: reviewdog 433 runs-on: ubuntu-latest 434 steps: 435 # ... 436 - name: Run reviewdog 437 env: 438 REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} 439 run: | 440 reviewdog -reporter=github-check -runners=golint,govet 441 ``` 442 443 </details> 444 445 #### Public Reviewdog GitHub Actions 446 You can use public GitHub Actions to start using reviewdog with ease! :tada: :arrow_forward: :tada: 447 448 - Common 449 - [reviewdog/action-misspell](https://github.com/reviewdog/action-misspell) - Run [misspell](https://github.com/client9/misspell). 450 - [tsuyoshicho/action-textlint](https://github.com/tsuyoshicho/action-textlint) - Run [textlint](https://github.com/textlint/textlint) 451 - [tsuyoshicho/action-redpen](https://github.com/tsuyoshicho/action-redpen) - Run [redpen](https://github.com/redpen-cc/redpen) 452 - [reviewdog/action-languagetool](https://github.com/reviewdog/action-languagetool) - Run [languagetool](https://github.com/languagetool-org/languagetool). 453 - Docker 454 - [reviewdog/action-hadolint](https://github.com/reviewdog/action-hadolint) - Run [hadolint](https://github.com/hadolint/hadolint) to lint `Dockerfile`. 455 - Env 456 - [mgrachev/action-dotenv-linter](https://github.com/mgrachev/action-dotenv-linter) - Run [dotenv-linter](https://github.com/mgrachev/dotenv-linter) to lint `.env` files. 457 - Shell script 458 - [reviewdog/action-shellcheck](https://github.com/reviewdog/action-shellcheck) - Run [shellcheck](https://github.com/koalaman/shellcheck). 459 - Go 460 - [reviewdog/action-golangci-lint](https://github.com/reviewdog/action-golangci-lint) - Run [golangci-lint](https://github.com/golangci/golangci-lint) and supported linters individually by golangci-lint. 461 - JavaScript 462 - [reviewdog/action-eslint](https://github.com/reviewdog/action-eslint) - Run [eslint](https://github.com/eslint/eslint). 463 - CSS 464 - [reviewdog/action-stylelint](https://github.com/reviewdog/action-stylelint) - Run [stylelint](https://github.com/stylelint/stylelint). 465 - Vim script 466 - [reviewdog/action-vint](https://github.com/reviewdog/action-vint) - Run [vint](https://github.com/Kuniwak/vint). 467 - [tsuyoshicho/action-vimlint](https://github.com/tsuyoshicho/action-vimlint) - Run [vim-vimlint](https://github.com/syngan/vim-vimlint) 468 - Terraform 469 - [reviewdog/action-tflint](https://github.com/reviewdog/action-tflint) - Run [tflint](https://github.com/wata727/tflint). 470 - YAML 471 - [reviewdog/action-yamllint](https://github.com/reviewdog/action-yamllint) - Run [yamllint](https://github.com/adrienverge/yamllint). 472 - Ruby 473 - [reviewdog/action-brakeman](https://github.com/reviewdog/action-brakeman) - Run [brakeman](https://github.com/presidentbeef/brakeman). 474 - [reviewdog/action-rubocop](https://github.com/reviewdog/action-rubocop) - Run [rubocop](https://github.com/rubocop-hq/rubocop). 475 - [vk26/action-fasterer](https://github.com/vk26/action-fasterer) - Run [fasterer](https://github.com/DamirSvrtan/fasterer). 476 - Python 477 - [wemake-python-styleguide](https://github.com/wemake-services/wemake-python-styleguide) - Run wemake-python-styleguide 478 - Kotlin 479 - [ScaCap/action-ktlint](https://github.com/ScaCap/action-ktlint) - Run [ktlint](https://ktlint.github.io/). 480 481 ... and more on [GitHub Marketplace](https://github.com/marketplace?utf8=✓&type=actions&query=reviewdog). 482 483 Missing actions? Check out [reviewdog/action-template](https://github.com/reviewdog/action-template) and create a new reviewdog action! 484 485 Please open a Pull Request to add your created reviewdog actions here :sparkles:. 486 I can also put your repositories under reviewdog org and co-maintain the actions. 487 Example: [action-tflint](https://github.com/reviewdog/reviewdog/issues/322). 488 489 #### Graceful Degradation for Pull Requests from forked repositories 490 491 ![Graceful Degradation example](https://user-images.githubusercontent.com/3797062/71781334-e2266b00-3010-11ea-8a38-dee6e30c8162.png) 492 493 `GITHUB_TOKEN` for Pull Requests from forked repository doesn't have write 494 access to Check API nor Review API due to [GitHub Actions 495 restriction](https://help.github.com/en/articles/virtual-environments-for-github-actions#github_token-secret). 496 497 Instead, reviewdog uses [Logging commands of GitHub 498 Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/development-tools-for-github-actions#set-an-error-message-error) 499 to post results as 500 [annotations](https://developer.github.com/v3/checks/runs/#annotations-object) 501 similar to `github-pr-check` reporter. 502 503 Note that there is a limitation for annotations created by logging commands, 504 such as [max # of annotations per run](https://github.com/reviewdog/reviewdog/issues/411#issuecomment-570893427). 505 You can check GitHub Actions log to see full results in such cases. 506 507 #### reviewdog badge [![reviewdog](https://github.com/reviewdog/reviewdog/workflows/reviewdog/badge.svg?branch=master&event=push)](https://github.com/reviewdog/reviewdog/actions?query=workflow%3Areviewdog+event%3Apush+branch%3Amaster) 508 509 As [`github-check` reporter](#reporter-github-checks--reportergithub-pr-check) support running on commit, we can create reviewdog 510 [GitHub Action badge](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/configuring-a-workflow#adding-a-workflow-status-badge-to-your-repository) 511 to check the result against master commit for example. :tada: 512 513 Example: 514 ``` 515 <!-- Replace <OWNWER> and <REPOSITORY>. It assumes workflow name is "reviewdog" --> 516 [![reviewdog](https://github.com/<OWNER>/<REPOSITORY>/workflows/reviewdog/badge.svg?branch=master&event=push)](https://github.com/<OWNER>/<REPOSITORY>/actions?query=workflow%3Areviewdog+event%3Apush+branch%3Amaster) 517 ``` 518 519 ### Travis CI 520 521 #### Travis CI (-reporter=github-pr-check) 522 523 If you use -reporter=github-pr-check in Travis CI, you don't need to set `REVIEWDOG_TOKEN`. 524 525 Example: 526 527 ```yaml 528 install: 529 - mkdir -p ~/bin/ && export PATH="~/bin/:$PATH" 530 - curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b ~/bin 531 532 script: 533 - reviewdog -conf=.reviewdog.yml -reporter=github-pr-check 534 ``` 535 536 #### Travis CI (-reporter=github-pr-review) 537 538 Store GitHub API token by [travis encryption keys](https://docs.travis-ci.com/user/encryption-keys/). 539 540 ```shell 541 $ gem install travis 542 $ travis encrypt REVIEWDOG_GITHUB_API_TOKEN=<token> --add env.global 543 ``` 544 Example: 545 546 ```yaml 547 env: 548 global: 549 - secure: <token> 550 551 install: 552 - mkdir -p ~/bin/ && export PATH="~/bin/:$PATH" 553 - curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b ~/bin 554 555 script: 556 - >- 557 golint ./... | reviewdog -f=golint -reporter=github-pr-review 558 ``` 559 560 Examples 561 - https://github.com/azu/textlint-reviewdog-example 562 563 ### Circle CI 564 565 Store `REVIEWDOG_TOKEN` or `REVIEWDOG_GITHUB_API_TOKEN` in 566 [Environment variables - CircleCI](https://circleci.com/docs/environment-variables/#setting-environment-variables-for-all-commands-without-adding-them-to-git) 567 568 #### .circleci/config.yml sample 569 570 ```yaml 571 version: 2 572 jobs: 573 build: 574 docker: 575 - image: golang:latest 576 steps: 577 - checkout 578 - run: curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b ./bin 579 - run: go vet ./... 2>&1 | ./bin/reviewdog -f=govet -reporter=github-pr-check 580 # or 581 - run: go vet ./... 2>&1 | ./bin/reviewdog -f=govet -reporter=github-pr-review 582 ``` 583 584 ### GitLab CI 585 586 Store `REVIEWDOG_GITLAB_API_TOKEN` in [GitLab CI variable](https://docs.gitlab.com/ee/ci/variables/#variables). 587 588 #### .gitlab-ci.yml sample 589 590 ```yaml 591 reviewdog: 592 script: 593 - reviewdog -reporter=gitlab-mr-discussion 594 # Or 595 - reviewdog -reporter=gitlab-mr-commit 596 ``` 597 598 ### Common (Jenkins, local, etc...) 599 600 You can use reviewdog to post review comments from anywhere with following 601 environment variables. 602 603 | name | description | 604 | ---- | ----------- | 605 | `CI_PULL_REQUEST` | Pull Request number (e.g. 14) | 606 | `CI_COMMIT` | SHA1 for the current build | 607 | `CI_REPO_OWNER` | repository owner (e.g. "haya14busa" for https://github.com/haya14busa/reviewdog) | 608 | `CI_REPO_NAME` | repository name (e.g. "reviewdog" for https://github.com/haya14busa/reviewdog) | 609 | `CI_BRANCH` | [optional] branch of the commit | 610 611 ```shell 612 $ export CI_PULL_REQUEST=14 613 $ export CI_REPO_OWNER=haya14busa 614 $ export CI_REPO_NAME=reviewdog 615 $ export CI_COMMIT=$(git rev-parse HEAD) 616 ``` 617 and set a token if required. 618 619 ```shell 620 $ REVIEWDOG_TOKEN="<token>" 621 $ REVIEWDOG_GITHUB_API_TOKEN="<token>" 622 $ REVIEWDOG_GITLAB_API_TOKEN="<token>" 623 ``` 624 625 If a CI service doesn't provide information such as Pull Request ID - reviewdog can guess it by branch name and commit SHA. 626 Just pass the flag `guess`: 627 628 ```shell 629 $ reviewdog -conf=.reviewdog.yml -reporter=github-pr-check -guess 630 ``` 631 632 #### Jenkins with Github pull request builder plugin 633 - [GitHub pull request builder plugin - Jenkins - Jenkins Wiki](https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin) 634 635 ```shell 636 $ export CI_PULL_REQUEST=${ghprbPullId} 637 $ export CI_REPO_OWNER=haya14busa 638 $ export CI_REPO_NAME=reviewdog 639 $ export CI_COMMIT=${ghprbActualCommit} 640 $ export REVIEWDOG_INSECURE_SKIP_VERIFY=true # set this as you need 641 $ REVIEWDOG_TOKEN="<token>" reviewdog -reporter=github-pr-check 642 # Or 643 $ REVIEWDOG_GITHUB_API_TOKEN="<token>" reviewdog -reporter=github-pr-review 644 ``` 645 646 ## Exit codes 647 By default Reviewdog will return `0` as exit code once all actions done (linter report analyzed, comments posted and so on). 648 649 Once `fail-on-error` flag passed - Reviewdog will return `1` as exit code if at least one violation was found/reported. 650 This can be helpful when you are using it as a step in your CI pipeline and want to mark the step failed if any error found by linter. 651 652 ## Articles 653 - [reviewdog — A code review dog who keeps your codebase healthy ](https://medium.com/@haya14busa/reviewdog-a-code-review-dog-who-keeps-your-codebase-healthy-d957c471938b) 654 - [reviewdog ♡ GitHub Check — improved automated review experience](https://medium.com/@haya14busa/reviewdog-github-check-improved-automated-review-experience-58f89e0c95f3) 655 - [Automated Code Review on GitHub Actions with reviewdog for any languages/tools](https://medium.com/@haya14busa/automated-code-review-on-github-actions-with-reviewdog-for-any-languages-tools-20285e04448e) 656 657 ## :bird: Author 658 haya14busa [![GitHub followers](https://img.shields.io/github/followers/haya14busa.svg?style=social&label=Follow)](https://github.com/haya14busa) 659 660 ## Contributors 661 662 [![Contributors](https://opencollective.com/reviewdog/contributors.svg?width=890)](https://github.com/reviewdog/reviewdog/graphs/contributors) 663 664 ### Supporting reviewdog 665 666 Become GitHub Sponsor for [each contributor](https://github.com/reviewdog/reviewdog/graphs/contributors) 667 or become a backer or sponsor from [opencollective](https://opencollective.com/reviewdog). 668 669 [![Become a backer](https://opencollective.com/reviewdog/tiers/backer.svg?avatarHeight=64)](https://opencollective.com/reviewdog#backers)