GitHubActions์— reviewdog ๐Ÿถ์„ ๋„์ž…ํ•˜์—ฌ ์ž๋™์œผ๋กœ PR ์ฝ”๋ฉ˜ํŠธ ํ˜•์‹์œผ๋กœ Typescript ์˜ค๋ฅ˜๋ฅผ ์ฃผ์„ ์‹œํ‚ค์ž

ํ•˜๊ณ  ์‹ถ์€ ๊ฒƒ, ํ–ˆ๋˜ ๊ฒƒ


Typescript ํ˜•์‹ ์˜ค๋ฅ˜๊ฐ€ ํฌํ•จ ๋œ ์ฝ”๋“œ๋ฅผ GitHub์˜ ๋ณดํ˜ธ ์ง€์ ์— ๋ณ‘ํ•ฉํ•˜์ง€ ์•Š๋„๋ก GitHub Actions ๊ฒŒ๋‹ค๊ฐ€ tsc ๊ฐ€ ๊ฒ€์ง€ํ•œ ๊ฐœ์†Œ์— PR ์ฝ”๋ฉ˜ํŠธ๋กœ ์ฃผ์„ํ•ด ์ฃผ์—ˆ์œผ๋ฉด ํ•˜๋Š” ๋‚ ์ด ์žˆ๋‹ค. ์ด๋ฒˆ์€ reviewdog ์„ ์‚ฌ์šฉํ•ด ์ž๋™์œผ๋กœ ์ฃผ์„ํ•˜๊ฒŒ ํ–ˆ๋‹ค.
tsc ๊ฐ€ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋Š” ๊ธฐ์„ฑํ’ˆ reviewdog ์—, GitHub Action ์˜ ์—๋Ÿฌ๋ฅผ ์ž๋™์œผ๋กœ ์ฃผ์„ํ•ด ์ค€๋‹ค ๊ทธ๋ ‡๊ฒŒ ํ•˜์ง€ ์•Š์„๊นŒ ํ•˜๋Š” ์ƒ๊ฐ.

์ฃผ์„์ด ๋‹ฌ๋ฆฐ ๋ชจ์Šต
Run eslint with reviewdog

๊ตฌํ˜„ํ•œ workflow



์ „์ œ



ํ”„๋กœ์ ํŠธ์— eslint์˜ TypeScript๊ฐ€ ๋„์ž…๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
yarn add -D typescript

๊ตฌํ˜„ํ•œ Workflow



๊ตฌํ˜„ํ•œ Workflow์˜ ํฌ์ธํŠธ๋Š” ์ดํ•˜ 2์ .
  • npmใƒ‘ใƒƒใ‚ฑใƒผใ‚ธ ์˜ ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์œผ๋กœ, typescript ์œ„์—์„œ Githubใ€€Action
  • Githubใ€€Actions ๋‹จ๊ณ„.

  • .github/workflows/main.yml
    name: Test
    on: [pull_request]
    
    jobs:
      build:
        name: build
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v2
          # ref: https://github.com/actions/setup-node#v2
          - uses: actions/setup-node@v2
            with:
              node-version: "14"
          # ref: https://github.com/reviewdog/reviewdog#github-action-reviewdogaction-setup
          - uses: reviewdog/action-setup@v1
            with:
              reviewdog_version: latest
          # ref: https://github.com/actions/cache/blob/main/examples.md#node---yarn
          - name: Get yarn cache directory path
            id: yarn-cache-dir-path
            run: echo "::set-output name=dir::$(yarn cache dir)"
          - uses: actions/cache@v2
            id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
            with:
              path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
              key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
              restore-keys: |
                ${{ runner.os }}-yarn-
          - name: Install Dependencies
            run: yarn --frozen-lockfile
          # ref: https://github.com/reviewdog/reviewdog#available-pre-defined-errorformat
          - name: Typecheck
            run: tsc --pretty false --noEmit | reviewdog -f=tsc -reporter=github-pr-review -fail-on-error=true
            env:
              REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.github_token }}
    

    ๊ฐ ํฌ์ธํŠธ์— ๋Œ€ํ•ด



    reviewdog/action-setup@v1
    reviewdog/action-setup@v1 ์—์„œ reviewdog ์œ„์— Typecheck ๋ฅผ ์„ค์น˜ํ–ˆ์Šต๋‹ˆ๋‹ค. GitHub Actions๋Š” ๋‹ค์–‘ํ•œ ์ฒดํฌ ํˆด์˜ ์ถœ๋ ฅ์— ๋Œ€์‘ํ•˜๊ณ  reviewdog ์˜ต์…˜์„ ๋ถ™์—ฌ ์‹คํ–‰ํ•˜๋ฉด ๊ทธ ์ผ๋žŒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ์ด ๊ฒ€์‚ฌ ๋„๊ตฌ์˜ ์ถœ๋ ฅ์„ ๋ฐ›์•„ ๊ฒฐ๊ณผ๋ฅผ reviewdog์˜ PR์— ์ฃผ์„์„ ๋‹ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    -list ๊ฒฐ๊ณผ

    terminal
     โฏโฏโฏ reviewdog -list
    rdjson          Reviewdog Diagnostic JSON Format (JSON of DiagnosticResult message)                                             - https://github.com/reviewdog/reviewdog
    rdjsonl         Reviewdog Diagnostic JSONL Format (JSONL of Diagnostic message)                                                 - https://github.com/reviewdog/reviewdog
    diff            Unified Diff Format                                                                                             - https://en.wikipedia.org/wiki/Diff#Unified_format
    checkstyle      checkstyle XML format                                                                                           - http://checkstyle.sourceforge.net/
    ansible-lint    (ansible-lint -p playbook.yml) Checks playbooks for practices and behaviour that could potentially be improved  - https://github.com/ansible/ansible-lint
    brakeman        (brakeman --quiet --format tabs) A static analysis security vulnerability scanner for Ruby on Rails applications- https://github.com/presidentbeef/brakeman
    cargo-check     (cargo check -q --message-format=short) Check a local package and all of its dependencies for errors            - https://github.com/rust-lang/cargo
    clippy          (cargo clippy -q --message-format=short) A bunch of lints to catch common mistakes and improve your Rust code   - https://github.com/rust-lang/rust-clippy
    dotenv-linter   Lightning-fast linter for .env files. Written in Rust                                                           - https://github.com/dotenv-linter/dotenv-linter
    dotnet          (dotnet build -clp:NoSummary -p:GenerateFullPaths=true --no-incremental --nologo -v q) .NET Core CLI            - https://docs.microsoft.com/en-us/dotnet/core/tools/
    eslint          (eslint [-f stylish]) A fully pluggable tool for identifying and reporting on patterns in JavaScript            - https://github.com/eslint/eslint
    eslint-compact  (eslint -f compact) A fully pluggable tool for identifying and reporting on patterns in JavaScript              - https://github.com/eslint/eslint
    fasterer        Speed improvements suggester                                                                                    - https://github.com/DamirSvrtan/fasterer
    go-consistent   Source code analyzer that helps you to make your Go programs more consistent                                    - https://github.com/quasilyte/go-consistent
    golangci-lint   (golangci-lint run --out-format=line-number) GolangCI-Lint is a linters aggregator.                             - https://github.com/golangci/golangci-lint
    golint          linter for Go source code                                                                                       - https://github.com/golang/lint
    gosec           (gosec -fmt=golint) Golang Security Checker                                                                     - https://github.com/securego/gosec
    govet           Vet examines Go source code and reports suspicious problems                                                     - https://golang.org/cmd/vet/
    haml-lint       Tool for writing clean and consistent HAML                                                                      - https://github.com/sds/haml-lint
    hlint           Linter for Haskell source code                                                                                  - https://github.com/ndmitchell/hlint
    msbuild         (msbuild /property:GenerateFullPaths=true /nologo /v:q) Microsoft Build Engine                                  - https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild
    pep8            Python style guide checker                                                                                      - https://pypi.python.org/pypi/pep8
    phpstan         (phpstan --error-format=raw) PHP Static Analysis Tool - discover bugs in your code without running it!          - https://github.com/phpstan/phpstan
    psalm           (psalm --output-format=text) Psalm is a static analysis tool for finding errors in PHP                          - https://github.com/vimeo/psalm
    puppet-lint     Check that your Puppet manifests conform to the style guide                                                     - https://github.com/rodjek/puppet-lint
    reek            (reek --single-line) Code smell detector for Ruby                                                               - https://github.com/troessner/reek
    rubocop         A Ruby static code analyzer, based on the community Ruby style guide                                            - https://github.com/rubocop-hq/rubocop
    sbt             the interactive build tool                                                                                      - http://www.scala-sbt.org/
    sbt-scalastyle  Scalastyle - SBT plugin                                                                                         - http://www.scalastyle.org/sbt.html
    scalac          Scala compiler                                                                                                  - http://www.scala-lang.org/
    scalastyle      Scalastyle - Command line                                                                                       - http://www.scalastyle.org/command-line.html
    slim-lint       Tool to help keep your Slim files clean and readable                                                            - https://github.com/sds/slim-lint
    sorbet          A fast, powerful type checker designed for Ruby                                                                 - https://github.com/sorbet/sorbet
    standardjs      (standard) JavaScript style guide, linter, and formatter                                                        - https://github.com/standard/standard
    standardrb      (standard) Ruby style guide, linter, and formatter                                                              - https://github.com/testdouble/standard
    stylelint       A mighty modern CSS linter                                                                                      - https://github.com/stylelint/stylelint
    tsc             TypeScript compiler                                                                                             - https://www.typescriptlang.org/
    tslint          An extensible linter for the TypeScript language                                                                - https://github.com/palantir/tslint
    



    TypeCheck ๋‹จ๊ณ„

    .github/workflows/main.yml ๋ถ€๋ถ„
     - name: Typecheck
            run: tsc --pretty false --noEmit | reviewdog -f=tsc -reporter=github-pr-review -fail-on-error=true
            env:
              REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.github_token }}
    
    GitHub ์˜ ์ปดํŒŒ์ผ๋Ÿฌ์ธ reviewdog -list ๋Š” TypeScript ์˜ต์…˜์„ ๋ถ™์ด๋ฉด ์—๋Ÿฌ ์ถœ๋ ฅ์ด ๋‹จ์ˆœํ™”๋œ๋‹ค. tsc ๊ฐ€ ๋ฐ›์•„๋“ค์ธ๋‹ค --pretty false ์˜ ์ถœ๋ ฅ์€ ๋‹จ์ˆœํ™”๋œ (๋ถ„)ํŽธ์ด๋ฏ€๋กœ, ์ด ์˜ต์…˜์„ ๋ถ€์—ฌํ•œ ๊ฒƒ์„ ํŒŒ์ดํ”„( reviewdog )๋กœ tsc ์— ๋ณด๋‚ธ๋‹ค.
    | ์˜ ์œ ๋ฌด์— ๋”ฐ๋ฅธ ์ฐจ์ด

    terminal
    โฏโฏโฏ tsc
    src/components/IndexPage.tsx:3:7 - error TS2322: Type 'string' is not assignable to type 'number'.
    
    3 const a: number = "hoge";
            ~
    
    
    Found 1 error.
    
    โฏโฏโฏ tsc --pretty false
    src/components/IndexPage.tsx(3,7): error TS2322: Type 'string' is not assignable to type 'number'.
    


    reviewdog ์—๋Š” tsc --pretty ์˜ต์…˜์œผ๋กœ ์–ด๋Š ์ฒดํฌ ํˆด์˜ ์ถœ๋ ฅ์ด ์ž…๋ ฅ๋˜๊ณ  ์žˆ๋Š”์ง€ ์ „ํ•˜๊ณ  ์žˆ๋‹ค. ์—ฌ๊ธฐ์„œ reviewdog ์˜ต์…˜๊ณผ ํ•„์š”ํ•œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ๋ถ™์ด๋Š” ๊ฒƒ์œผ๋กœ, ์ž๋™์œผ๋กœ PR์— ์ฝ”๋ฉ˜ํŠธ๊ฐ€ ๋œ๋‹ค. ํ•„์š”ํ•œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋Š” -f์ด๋ฉฐ, -reporter=github-pr-review์˜ $REVIEWDOG_GITHUB_API_TOKEN์—์„œ๋Š” ์œ„์™€ ๊ฐ™์€ ์„ค์ •์„ ํ•˜๋ฉด ๋œ๋‹ค.

    ๋˜ GitHub Actions ์— Workflow ์˜ต์…˜์„ ๋ถ™์ด๋Š” ๊ฒƒ์œผ๋กœ, ์—๋Ÿฌ๊ฐ€ ์ž…๋ ฅ๋˜๋ฉด reviewdog ์˜ PR ์˜ ์ฒดํฌ๋ฅผ ์‹คํŒจ์‹œํ‚ค๋„๋ก ํ•˜๊ณ  ์žˆ๋‹ค.

    ๋์—



    ์ตœ๊ทผ ์ €๋Š” ๋น„๋ก ํ˜ผ์ž ๋งŒ๋“œ๋Š” ๊ฒƒ๋„ -fail-on-error=true ๋“ฑ์„ ์ •๋ˆํ•˜๋Š” ๊ฒƒ์„ ์ฆ๊ฒจ ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๊ฐ€ ๋‚ด๋Š” PR์— ์ฝ”๋ฉ˜ํŠธ๋ฅผ ๋ฌป์ง€ ์•Š๋Š” ๊ณณ, bot์—๋ผ๋„ ์ฝ”๋ฉ˜ํŠธ๋˜๋ฉด ํ™œ๊ธฐ์ฐจ๊ณ  ์ข‹์€ ๊ฒƒ์ด๊ตฐ์š”. ํ˜ผ์ž ๋งŒ๋“œ๋Š” ํ”„๋กœ์ ํŠธ์•ผ๋ง๋กœ ๊ทธ ์ ์„ ํ™•์ธํ•  ํ•„์š”๊ฐ€ ์—†๋Š”๋ฐ, ๊ฑฐ๊ธฐ์„œ, ๋กœ๋ด‡์ด ๋˜๊ณ  ๊ณ ์–‘์ด๊ฐ€ ๋‚™์ง€ ๋‚˜๋ฆ„๋Œ€๋กœ ์ž์‹ ์˜ ๋ถ€์ฃผ์˜๋ฅผ ์ง€์ ํ•ด ์ฃผ์—ˆ์œผ๋ฉด ํ•˜๋Š” ๊ฒƒ์€, ๋ญ”๊ฐ€ ๋งŒ๋“ค๊ธฐ์— ์žˆ์–ด์„œ ๋ฌถ์–ด ํ”Œ๋ ˆ์ด์— ์žฌ๋ฏธ๋ฅผ ๋Š๋ผ๋Š” ์†์ˆ˜์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค ๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

    ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ