Save 36% for Black Friday! Learn more

All Lessons / GitHub Actions with Ruby on Rails: Setting up Continuous Integration

GitHub Actions with Ruby on Rails: Setting up Continuous Integration

#316 ยท October 17, 2019

Your Teacher | Chris Oliver

Hi, I'm Chris. I'm the creator of GoRails, Hatchbox.io and Jumpstart. I spend my time creating tutorials and tools to help Ruby on Rails developers build apps better and faster.

About This Episode

Learn how to set up GitHub Actions to run Continuous Integration (CI) with Ruby on Rails

Notes

Continuous Integration (CI) is the process of testing code every time changes are pushed to version control, such as git. The CI process makes sure that new code doesn't break other features when it gets merged. You can setup GitHub to require that tests have passed on a Pull Request before

GitHub Actions is a new feature from GitHub that allows you to define custom workflows to run against your code. In this video, we're going to use GitHub Actions to continuously integrate our Ruby on Rails code every git push to make sure our tests pass.

Setting up GitHub Actions can seem a little daunting, but we've made a solid guide that you can follow and make changes to. Behind the scenes, it's using Docker to spin up an environment that you can use. It builds an Ubuntu, MacOS, or Windows environment and spins up other services like PostgreSQL, MySQL, MongoDB, Redis, ElasticSearch, or any other service you need. Then it checks out your code, installs dependencies, compiles your code, and runs tests.

The results of these tests are stored by GitHub against your commit so you know exactly which commit(s) broke the tests.

Resources

# .github/workflows/ci.yml

name: CI
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    services:
      db:
        image: postgres:11
        ports: ['5432:5432']
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
      redis:
        image: redis
        ports: ['6379:6379']
        options: --entrypoint redis-server

    steps:
      - uses: actions/[email protected]
      - name: Setup Ruby
        uses: actions/[email protected]
        with:
          ruby-version: 2.6.x
      - uses: borales/[email protected]
        with:
          cmd: install
      - name: Build and run tests
        env:
          DATABASE_URL: postgres://postgres:@localhost:5432/test
          REDIS_URL: redis://localhost:6379/0
          RAILS_ENV: test
          RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
        run: |
          sudo apt-get -yqq install libpq-dev
          gem install bundler
          bundle install --jobs 4 --retry 3
          bundle exec rails db:prepare
          bundle exec rails test

Discussion

Loading...
logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.