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/checkout@v1
- name: Setup Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: 2.6.x
- uses: borales/actions-yarn@v2.0.0
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