Rubocop in Github Actinos

2022/02/17 22:18

This is my GitHub actions script. On my configuration, on every push to Github, the rubocop GitHub action will start running. This file is located at the following place

~/.github/workflows/*.yml

You can change the Ruby version whichever you want.

~/.github/workflows/rubocop.yml

name: rubocop

on: [push]

jobs:
  rubocop:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Set up Ruby 3.0
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: 3.0
        bundler-cache: true

    - name: Run RuboCop
      run: bundle exec rubocop --parallel

~/.github/workflows/rubocop.yml

name: Rails Rspec

on: [push]

jobs:
  rspec:
    runs-on: ubuntu-latest

    services:
      postgres:
        image: postgres:12.6
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
        env:
          POSTGRES_HOST_AUTH_METHOD: 'trust'
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: rails_app_test # modify to your database name
        ports:
        - 5432:5432

    container:
      image: ruby:3.0.0

    steps:
      - uses: actions/checkout@v2

      - name: Install Bundler
        run: gem install bundler --no-document -v $(grep "BUNDLED WITH" -1 Gemfile.lock | tail -n 1)

      - name: Bundle install
        run: bundle install --path=vendor/bundle --jobs 4 --retry 3

      - name: DB setup
        env:
          BOOKING_DATABASE_USER: postgres
          BOOKING_DATABASE_PASSWORD: postgres
          BOOKING_DATABASE_HOST: postgres
          RAILS_ENV: test
        run: |
          bundle exec rails db:create
          bundle exec rails db:migrate          

      - name: Run rspec
        env:
          BOOKING_DATABASE_USER: postgres
          BOOKING_DATABASE_PASSWORD: postgres
          BOOKING_DATABASE_HOST: postgres
          RAILS_ENV: test
        run: bundle exec rspec
comments powered by Disqus