Created
April 26, 2020 20:29
-
-
Save tadast/5f13b4ca3a38502a56cf24e89f97dc7e to your computer and use it in GitHub Desktop.
Example github actions config for Rails with postgres using DATABASE_URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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 :)
Thank you very much! :D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! Do you accept donations? LOL 🤣