LoginSignup
1
1

More than 3 years have passed since last update.

Railsの静的コード解析をGitHub Actionsでやる

Posted at

これはなにか

GitHub に push すると GitHub Actions がブンブン回って、静的コード解析をしてくれるやつ。ついでにキャッシュされるので、毎回 bundle install がまわることがないやつ。はやい、やすい、うまい ... かどうかはわからないが、要はオレによし、オマエによし。

ワークフロー

name: Static Check 

on: [push]

jobs:
  RuboCop:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/setup-ruby@v1
      with:
        ruby-version: '2.7'
    - uses: actions/checkout@v2
    - uses: actions/cache@preview
      with:
        path: ./web/vendor/bundle
        key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
        restore-keys: |
          ${{ runner.os }}-gem-
    - name: Run RuboCop
      run: |
        cd ./web/
        bundle install --jobs 4 --retry 3 --path vendor/bundle
        bundle exec rubocop -a
  BrakeMan:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/setup-ruby@v1
      with:
        ruby-version: '2.7'
    - uses: actions/checkout@v2
    - uses: actions/cache@preview
      with:
        path: ./web/vendor/bundle
        key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
        restore-keys: |
          ${{ runner.os }}-gem-
    - name: Run BrakeMan
      run: |
        cd ./web/
        bundle install --jobs 4 --retry 3 --path vendor/bundle
        bundle exec rubocop -a
  RubyCritic:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/setup-ruby@v1
      with:
        ruby-version: '2.7'
    - uses: actions/checkout@v2
    - uses: actions/cache@preview
      with:
        path: ./web/vendor/bundle
        key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
        restore-keys: |
          ${{ runner.os }}-gem-
    - name: Run BrakeMan
      run: |
        cd ./web/
        bundle install --jobs 4 --retry 3 --path vendor/bundle
        bundle exec rubycritic

おわりに

ほんとは Docker 化しているのだから、Docker 上で動かせば良いのだろうけど Docker イメージの置き場所とか考えると、めんどくさくなったのでこうした。次は GitHub Actions で Docker image をロードして CI するやつでもつくろうかな。

1
1
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
1
1