DEV Community

Luis Ortega
Luis Ortega

Posted on

2 2

Setting up GitHub Actions with Rails 6.1 and MySQL 5.7

I'm actually new to this technology, but I've been working with it for a week and I have to say it's really handy. When you integrate GitHub Actions into your workflow, you can stop worrying about setting up your own custom CI server, at least for testing.

I've been working it with a Rails 6.1 and a MySQL 5.6 database engine.

It takes little time and effort and in return you have a full testing environment ready to work on the same place you have your code. So no need for API keys, no integrations with other systems, keeping everything simple.

I've done this setup with Rails & Postgres and had no issue, but had a hard time looking how others have done it with Rails & MySQL. Because of this I thought of sharing how I did it.

 My working example

.github/workflow/ci.yml file:


name: github-actions-rails-mysql

on:
  pull_request:
    branches: ['*']
  push:
    branches: [master]
jobs:
  test:
    runs-on: ubuntu-latest
    services:
      mysql:
        image: mysql:5.7
        env:
          MYSQL_HOST: 127.0.0.1
          MYSQL_DB: github_actions_test
          MYSQL_USER: root
          MYSQL_ALLOW_EMPTY_PASSWORD: yes
          MYSQL_PASSWORD:
        ports:
          - "3306:3306"
    steps:
      - uses: actions/checkout@v2
      - name: Setup Ruby 2.7
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 2.7
          bundler: default
          bundler-cache: true
      - name: Run tests
        env:
          RAILS_ENV: test
          DATABASE_PORT: 3306
        run: |
          bin/rails db:create
          bin/rails db:schema:load
          bin/rails test

Enter fullscreen mode Exit fullscreen mode

My config/database.yml file:

default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password:
  socket: /tmp/mysql.sock

development:
  <<: *default
  database: github_actions_development

test:
  <<: *default
  database: github_actions_test
  host: 127.0.0.1

production:
  <<: *default
  database: github_actions_production
Enter fullscreen mode Exit fullscreen mode

Image of Stellar post

How a Hackathon Win Led to My Startup Getting Funded

In this episode, you'll see:

  • The hackathon wins that sparked the journey.
  • The moment José and Joseph decided to go all-in.
  • Building a working prototype on Stellar.
  • Using the PassKeys feature of Soroban.
  • Getting funded via the Stellar Community Fund.

Watch the video 🎥

Top comments (0)

Image of Quadratic

Free AI chart generator

Upload data, describe your vision, and get Python-powered, AI-generated charts instantly.

Try Quadratic free

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay