Skip to content

Instantly share code, notes, and snippets.

@tarv7
Created July 7, 2025 17:56
Show Gist options
  • Save tarv7/9051ddd07593b7f27f00eda1b672a0b1 to your computer and use it in GitHub Desktop.
Save tarv7/9051ddd07593b7f27f00eda1b672a0b1 to your computer and use it in GitHub Desktop.
Set up Github Actions with Rails
# .github/workflows/ci.yml
name: CI
on:
pull_request:
push:
branches: [ main ]
jobs:
scan_ruby:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true
- name: Scan for common Rails security vulnerabilities using static analysis
run: bin/brakeman --no-pager
scan_js:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true
- name: Scan for security vulnerabilities in JavaScript dependencies
run: bin/importmap audit
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true
- name: Lint code for consistent style
run: bin/rubocop -f github
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
ports:
- 5432:5432
options: --health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: database_name_test
steps:
- name: Install packages
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y build-essential git pkg-config google-chrome-stable
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true
- name: Run tests
env:
RAILS_ENV: test
run: bin/rails db:setup test test:system
- name: Keep screenshots from failed system tests
uses: actions/upload-artifact@v4
if: failure()
with:
name: screenshots
path: ${{ github.workspace }}/tmp/screenshots
if-no-files-found: ignore
# config/database.yml
default: &default
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
adapter: postgresql
encoding: unicode
host: localhost
username: postgres
password: postgres
timeout: 5000
development:
<<: *default
database: database_name_dev
test:
<<: *default
database: database_name_test
production:
primary:
<<: *default
database: database_name_prod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment