Skip to content

Instantly share code, notes, and snippets.

@kwent
Created November 11, 2020 09:14
Show Gist options
  • Save kwent/22d5d30fb867e5a06bfdfc803327c014 to your computer and use it in GitHub Desktop.
Save kwent/22d5d30fb867e5a06bfdfc803327c014 to your computer and use it in GitHub Desktop.
Rails Test GitHub Action
name: Rails Tests
on:
pull_request:
git difnches:
- "master"
push:
branches:
- "master"
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:11.5
ports: ["5432:5432"]
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: 2.6.x
- name: Install PostgreSQL 11 client
run: |
sudo apt-get -yqq install libpq-dev
- name: Ruby gem cache
uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Install gems
env:
RAILS_ENV: test
run: |
gem install bundler
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: 10.13.0
- name: Find yarn cache location
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: JS package cache
uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install packages
run: |
yarn install --pure-lockfile
- name: Create DB
env:
PGHOST: localhost
PGUSER: postgres
RAILS_ENV: test
RAILS_MASTER_KEY: ${{ secrets.RAILS_TEST_MASTER_KEY }}
run: |
bin/rails db:setup
- name: Run Tests
env:
PGHOST: localhost
PGUSER: postgres
RAILS_ENV: test
RAILS_MASTER_KEY: ${{ secrets.RAILS_TEST_MASTER_KEY }}
run: bundle exec rake test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment