Skip to main content
Testing:

GitHub Actions with Ruby on Rails: Setting up Continuous Integration

19

Episode 316 · October 17, 2019

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

Testing


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
Transcripts

No transcripts available. Earn a free month

Loading...

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.