4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに

こんにちは、Gakken LEAP のバックエンドエンジニアの mizuno です。
以前にGitLabのartifacts reportsを設定する で codequality を実装しました。
codequality を使い始めたのですが、実行時間が少し長いため、Rubocop と Brakeman を別々に分けて同時に実行し、速度を上げたいと思いました。
また、reviewdog を使って GitLab のマージリクエストにコメントを追加できることが分かったので、こちらも実装してみました。

reviewdog の下準備

APIトークンの発行

reviewdogを導入するにあたり、APIトークンが必要になるため、
個人アクセストークンの作成プロジェクトアクセストークンの作成を参考にしつつ、どちらかでAPIアクセストークンを発行しトークンを控えます。
プロジェクトの環境変数にREVIEWDOG_GITLAB_API_TOKENというキー名にして、発行したトークンを登録します。

reviewdogのインストール

共通して、before_script でreviewdogのインストールとgitをインストールします。

Rubocopの例

rubocop.gitlab-ci.yml
rubocop:
  image: registry.gitlab.com/pipeline-components/rubocop:latest
  stage: test
  variables:
    GIT_STRATEGY: clone
    GIT_DEPTH: 0
  before_script:
    - wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s
    - apk add git
  script:
   - rubocop | bin/reviewdog -f=rubocop -reporter=gitlab-mr-discussion

Brakemanの例

action-brakemanscript.sh を参考にし、scriptに実装しました。

brakeman.gitlab-ci.yml
brakeman:
  image: ruby:3.3-alpine
  stage: test
  variables:
    GIT_STRATEGY: clone
    GIT_DEPTH: 0
  before_script:
    - wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s
    - apk add git
    - gem install brakeman
  script:
    - brakeman --quiet --format tabs | bin/reviewdog -f=brakeman -reporter=gitlab-mr-discussion

brakmanのimageにgitをインストールできなかったため、ruby:3.3-alpineで代用しています。

動作確認

Rubocop

  • 省略記法の検知

Rubocop

Brakeman

  • SQLインジェクションの検知

Brakeman

まとめ

同時にjobが実行され高速になり、またマージリクエストの変更画面でも修正箇所が分かりやすくなり便利になりました。
reviewdog -listで使用可能なフォーマットは確認できるので、対応しているフォーマットがある場合はぜひ使ってみて下さい。

Gakken LEAP では教育をアップデートしていきたいエンジニアを絶賛大募集しています!!

https://gakken-leap.co.jp/recruit/

参考記事

https://qiita.com/yokoo-an209/items/b1071c716cfe937b2210

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?