How to setup GitHub Actions CI in a Rails 7 app
My learnings on how to go about it

Search for a command to run...
My learnings on how to go about it

No comments yet. Be the first to comment.
Introduction Render offers PostgreSQL for free accounts, but the database is deleted after one month.If the data matters to you, the solution is to back it up and recover it. How to backup Follow these steps; Run this command in the terminal to back...

Deploying to Render

Documenting them one at a time

Introduction The Shape Up Book details how the folks at 37 Signals handle project management, shipping new products and adding new features and everything else in between. What I learnt Experiment to find out what works best for you. Once you have ...

For the uninitiated, GitHub Actions helps automate certain aspects of a software project's build, test and deployment aspects. If your project is already on Github, it makes sense to utilise what GitHub Actions has to offer.
The focus of this write-up is the CI aspect of GitHub Actions.
I set out to familiarise myself with how to use GitHub Actions for CI. I wanted to automate the running of the system tests in Rumblr.
I precisely wanted the CI to run every time I push to a new branch or the main branch and every time a new Pull Request is made.
To get the CI to build, new changes needed to be made and new files needed to be added.
A new file: .env.test had to be created. Below are the contents of the file;
EMAIL_RECIPIENTS=test@test.com
FROM_EMAIL=sample@test.com
HONEYBADGER_API_KEY=honeybadger
A new file for the workflow needed to be added.
Below are the contents of the actual CI file which is located via: .github/workflows/config.yml
name: CI
on: [push,pull_request]
jobs:
test:
name: Tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12.7
env:
POSTGRES_USER: rumblr
POSTGRES_DB: rumblr_test
POSTGRES_PASSWORD: password
ports: ["5432:5432"]
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Ruby and install gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Install postgres client
run: sudo apt-get install libpq-dev
- name: Setup test database
env:
RAILS_ENV: test
POSTGRES_HOST: localhost
POSTGRES_USER: rumblr
POSTGRES_PASSWORD: password
run: |
bin/rails db:setup
- name: Run tests
env:
RAILS_ENV: test
POSTGRES_HOST: localhost
POSTGRES_USER: rumblr
POSTGRES_PASSWORD: password
run: |
bundle exec rake assets:precompile
bundle exec rspec
Some changes needed to be made to the database.yml file. The changes are below;
test:
<<: *default
database: rumblr_test
host: <%= ENV.fetch('POSTGRES_HOST', 'localhost') %>
username: <%= ENV.fetch('POSTGRES_USER', nil) %>
password: <%= ENV.fetch('POSTGRES_PASSWORD', nil) %>
port: <%= ENV.fetch('POSTGRES_PORT', 5432) %>
These changes were done to the test portion of the database configuration.
Some challenges (as expected) were faced while attempting this task.
Consider this git change log for the challenges that were faced.
.env.test fileThis file had to be included and the suggestion came from a colleague.
The official Github guides were only partly helpful to assist in setting this up.
Otherwise, the build kept on failing and the error didn't make a lot of sense.
test section of the DB configConsider the config/database.yml file in the change log.
All that had to be added as well for the build to happen successfully.
The links below were helpful in achieving this task;
This is included in the Rumblr project which can be found here.