Skip to content

Instantly share code, notes, and snippets.

@dfop02
Created May 23, 2023 23:18
Show Gist options
  • Save dfop02/ff29ac9e69e75e9e9157c5d85eebf834 to your computer and use it in GitHub Desktop.
Save dfop02/ff29ac9e69e75e9e9157c5d85eebf834 to your computer and use it in GitHub Desktop.
CI/CD for Github Workflow using Rails and Mysql 5.7 - Runs Rubocop and then RSpec.
name: CI
on:
# Only run this workflow on these actions and branches
push:
branches: [ "master" ]
pull_request:
branches: [ "master", "release/*" ]
permissions:
contents: read
jobs:
rubocop:
name: Rubocop
runs-on: ubuntu-latest # Says the SO used on test
steps:
# Get the source code
- name: Checkout Code
uses: actions/checkout@v3
# Config Ruby and install deps
- name: Setup Ruby 2.7.2
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: 2.7.2
rubygems: 3.4.13
bundler: 2.4.13
# Run Rubocop
- name: Analyze Code
run: bundle exec rubocop
rspec:
name: RSpec
needs: rubocop # If rubocop pass, then run rspec
runs-on: ubuntu-latest # Says the SO used on test
# Env for your app use
# Prefer use DB URL because is easier to handle
env:
RAILS_ENV: test
DATABASE_URL: mysql2://root:root@127.0.0.1:3306/app_test
services:
mysql:
image: mysql:5.7
env:
MYSQL_DB: app_test
MYSQL_ROOT_PASSWORD: root
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
# Get source code
- name: Checkout Code
uses: actions/checkout@v3
# Config Ruby and install deps
- name: Setup Ruby 2.7.2
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: 2.7.2
rubygems: 3.4.13
bundler: 2.4.13
# We need start mysql server manually
# https://github.blog/changelog/2020-02-21-github-actions-breaking-change-ubuntu-virtual-environments-will-no-longer-start-the-mysql-service-automatically/
- name: Start Mysql Server
run: |
sudo systemctl start mysql
mysql -h 127.0.0.1 --port 3306 -u'root' -p'root' -e 'CREATE DATABASE IF NOT EXISTS app_test;'
mysql -h 127.0.0.1 --port 3306 -u'root' -p'root' -e "SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));"
- name: Run Tests
run: bundle exec rspec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment