You will learn how to configure Ruby on Rails project on GitHub Actions. This specific Rails project has MySQL and Redis database. There is also Elasticsearch service running on CI. If your project is close to that setup below GitHub Actions yaml configuration will allow you to run tests on GitHub CI server.

If you happen to use PostgreSQL you can check our previous article about Rails app configuration with Postgres on GitHub Actions.

GitHub, Redis, MySQL, Elasticsearch

GitHub Actions configuration for Rails

In your repository, you need to create file .github/workflows/main.yaml Thanks to it GitHub Actions will run your CI builds. You can find results of executed CI builds in Actions tab on your GitHub repository page.

In this case, Rails application has MySQL, Redis, and Elasticsearch databases. You need to set up services with docker container to run each. In the below config, there is also a step for health check the MySQL and Elasticsearch to ensure both are up and running before you can start running tests.

The tests are executed across parallel jobs thanks to matrix feature in GitHub Actions and the Knapsack Pro ruby gem that will auto-balance tests distribution across jobs. Auto balancing tests using Knapsack Pro Queue Mode will ensure each parallel job finish work at a similar time. Thanks to that there is no bottleneck (no slow job with too many tests to run) and you can enjoy fast CI build time because you get optimal tests split across parallel tasks.

How Knapsack Pro Queue Mode works

In this video, you will learn how dynamic test suite spilt across parallel jobs (parallel CI nodes) work.

How Knapsack Pro Regular Mode works

Knapsack Pro has also a deterministic way of splitting tests. Tests are split only once before running tests. This is the most simple way that you will try for the first time to record your CI build before you switch to Queue Mode.

You can learn more about Knapsack Pro in the installation guide.

Summary

If you would like to learn more about GitHub Actions check our previous article about testing Rails app with PostgreSQL on GitHub Actions. There is also a video showing it in action.

Learn how to split slow RSpec spec files by test examples on Github Actions.

And if you are still considering using GitHub Actions, then our comparison of GitHub Actions vs other CIs may be helpful for you. The most commonly visited comparisons are: Github Actions vs Circle CI, Github Actions vs Jenkins, and Github Actions vs Travis CI.