Skip to content

Instantly share code, notes, and snippets.

@tadast
Created April 26, 2020 20:29
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tadast/5f13b4ca3a38502a56cf24e89f97dc7e to your computer and use it in GitHub Desktop.
Save tadast/5f13b4ca3a38502a56cf24e89f97dc7e to your computer and use it in GitHub Desktop.
Example github actions config for Rails with postgres using DATABASE_URL
name: Ruby
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12.1-alpine
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Ruby 2.7
uses: actions/setup-ruby@v1
with:
ruby-version: 2.7.x
- name: Setup cache key and directory for gems cache
uses: actions/cache@v1
with:
path: vendor/bundle
key: ${{ runner.os }}-gem-use-ruby-${{ hashFiles('**/Gemfile.lock') }}
- name: Get Yarn cache directory path
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Setup cache key and directory for node_modules cache
uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
- name: Bundle install
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Yarn install
run: yarn --frozen-lockfile
- name: Test with RSpec
env:
RAILS_ENV: "test"
DATABASE_URL: "postgres://postgres@localhost:5432/test_database_name"
RUBYOPT: "-W:no-deprecated -W:no-experimental" # Suppress Rails 6 deprecation warnings for ruby 2.7
run: |
bundle exec rails db:setup
bundle exec rspec
@jedrekdomanski
Copy link

Thank you! Do you accept donations? LOL 🤣

@tadast
Copy link
Author

tadast commented Oct 15, 2023

@jedrekdomanski haha I've needed to come back to this myself quite a few times! No donations needed, just pass it forward by open-sourcing useful snippets yourself :)

@tuliotm
Copy link

tuliotm commented May 6, 2024

Thank you very much! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment