Ask A Question

Notifications

You’re not receiving notifications from this thread.

GitHub Actions with Ruby on Rails: Setting up Continuous Integration Discussion

Congratulations on the video was very good, I will try today

Reply

I guess part of Continuous Integration is pushing the chanegs to production once the tests succeed.

Any suggestions on how to push to Heroku from within GitHub actions?

It's of course possible to configure this in Heroku, but I'm curious how to this from GitHub as it would allow you to then also run commands like database migrations after deployment.

Reply

Can't you just do this with automatic deploys in Heroku?

Reply

There are probably ways to do it, but I'd be prefer my CI setup to be self contained. For example I'm using Codeship right now which runs the tests, deploys to Heroku, runs migrations, and checks whether the site is still up.

I'm sure the same is possible with GitHub Actions, but I'm not just not sure how to push to the Heroku git repository from within GitHub.

Reply

You'd just use the Heroku action as the last step I believe: https://github.com/actions/heroku

Reply

Thanks. Would love to see an episode on that, as I think most people aren't used to doing Docker Deploys on Heroku.

Reply

Anybody has gotten github actions to work on the latest versions of Ruby? (2.6.4, 2.6.5)? Looks like the setup-ruby action has been outdated for a cople of months now.

Reply

Still waiting on them to release those Ruby versions. You can use a Ruby Docker image instead or compile and cache Ruby as part of the steps. Other than that, we just have to wait for 2.6.5 support to use setup-ruby. :(

Reply

Yeah I was trying that too!! It works fine for running regular tests I think, but it looks like you'd have to do a bit of an extra setup for system tests and chromedriver-helper. Have you had any luck running system tests?

Reply

Looks really interesting, thank you so much!

Reply

Thank you for Sharing This.

Reply

I was having issues with that YML file. This is my working versions. I use Rails, Postgresq, Redis, RSpec.

name: Continuous integration
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
services:
db:
image: postgres:11@sha256:85d79cba2d4942dad7c99f84ec389a5b9cc84fb07a3dcd3aff0fb06948cdc03b
ports: ['5432:5432']
env:
POSTGRES_DB: test
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@v2
  - name: Setup Ruby
    uses: actions/setup-ruby@v1
    with:
      ruby-version: 2.7
  - name: Build and test with Rake
    env:
      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
  - name: Db create Migrate
    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: | 
      bundle exec rails db:schema:load
      bundle exec rspec ./spec
Reply

Just to confirm, even though the test runs on Github CI, it still uses the test DATABASE instead of production DATABASE right? So the main purpose here is to confirm the rest of the project members' code under testing within the whole project? The reason I ask this question is that before pushing the code to GitHub, I will definitely test it locally, so if it just for my own benefit, it won't need to be tested again on GitHub CI. Or maybe there are some others reasons which make the GitHub CI test necessary.

I am sorry if I asked any low-level questions, I am a newbie of Ruby on Rails and GitHub CI, I am really curious about this question, thanks for your time.

Reply

Yes, it uses a database used only inside the CI.

And you want to always run the CI even if your local tests pass. The CI environment may catch something you missed and is most important when you have multiple people merging changes together as it can be easy to miss something. Think of it as double checking your work constantly. 👍

Reply

Got it, thank you so much for the explanation.

Reply

Thank you very much for this video, Chris! I just wanted to share here a little update I had to do in order to make it work:
1) the new postgres images require a password, so I had to add it as an env variable.
2) actions/setup-ruby is deprecated, now you have to use ruby/setup-ruby instead
3) the borales/actions-yarn is now at v2.3.0, the 2.0.0 is not working anymore

So the final version of this setup looks like this one:

# .github/workflows/ci.yml

name: CI
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    services:
      db:
        image: postgres
        env:
          password: secretpassword
        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: ruby/setup-ruby@v1
        with:
          ruby-version: 2.6.x
      - uses: borales/actions-yarn@v2.3.0
        with:
          cmd: install
      - name: Build and run tests
        env:
          DATABASE_URL: postgres://postgres:secretpassword@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
Reply

Getting this error on the Run borales/actions-yarn@v2.0.0 step

yarn install v1.17.3
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@2.3.2: The platform "linux" is incompatible with this module.
info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.13: The platform "linux" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
error webpack-dev-server@4.5.0: The engine "node" is incompatible with this module. Expected version ">= 12.13.0". Got "10.16.3"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Any ideas?

Reply

Your node version is too old (see the webpack-dev-server line)

Expected version ">= 12.13.0". Got "10.16.3"

Reply

As a note, for devs with PR process, this setup will cause to be n+1 since you'll be triggering runs on any push without considering the branch, a better approach would be to only count pushes to main, something like this would work:

name: CI
on:
  pull_request:
    branches:
      - "*"
  push:
    branches:
      - main
      - master
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.