Skip to content

Instantly share code, notes, and snippets.

@rrmartins
Created June 30, 2024 16:51
Show Gist options
  • Save rrmartins/b353456413c2128bcabbde29181a38eb to your computer and use it in GitHub Desktop.
Save rrmartins/b353456413c2128bcabbde29181a38eb to your computer and use it in GitHub Desktop.
with elasticsearch
name: "Ruby on Rails CI"
on: pull_request
env:
RAILS_ENV: test
DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
rspec-tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14
ports:
- "5432:5432"
env:
POSTGRES_DB: rails_test
POSTGRES_USER: rails
POSTGRES_PASSWORD: password
redis:
image: redis:alpine
ports: ["6379:6379"]
options: --entrypoint redis-server
--health-cmd "redis-cli ping"
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.4
ports:
- "9200:9200"
env:
discovery.type: single-node
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Wait for services to be ready
run: |
until curl -s http://localhost:9200/_cluster/health | grep -q '"status":"green"'; do
echo "Waiting for Elasticsearch..."
sleep 5
done
- name: Set up database schema
run: bin/rails db:schema:load
- name: Precompile assets
run: bin/rails assets:precompile
- name: Run RSpec tests
run: bundle exec rspec spec
minitests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14
ports:
- "5432:5432"
env:
POSTGRES_DB: rails_test
POSTGRES_USER: rails
POSTGRES_PASSWORD: password
redis:
image: redis:alpine
ports: ["6379:6379"]
options: --entrypoint redis-server
--health-cmd "redis-cli ping"
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.4
ports:
- "9200:9200"
env:
discovery.type: single-node
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Wait for services to be ready
run: |
until curl -s http://localhost:9200/_cluster/health | grep -q '"status":"green"'; do
echo "Waiting for Elasticsearch..."
sleep 5
done
- name: Set up database schema
run: bin/rails db:schema:load
- name: Precompile assets
run: bin/rails assets:precompile
- name: Run Minitest tests
run: bundle exec rails test
- name: Upload coverage report
if: ${{ success() || failure() }}
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage
retention-days: 7
bundler-audit:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Security audit dependencies
run: bundle exec bin/bundler-audit --update
brakeman:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Security audit application code
run: bundle exec bin/brakeman -q -w2
rubocop:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Rubocop
run: bundle exec bin/rubocop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment