Skip to content

Instantly share code, notes, and snippets.

@stefannibrasil
Created April 30, 2022 03:28
Show Gist options
  • Save stefannibrasil/de79badef2237a00faa55ff0b04fe03c to your computer and use it in GitHub Desktop.
Save stefannibrasil/de79badef2237a00faa55ff0b04fe03c to your computer and use it in GitHub Desktop.
GitHub Actions Workflow for a Rails 7 Tailwind CSS application
name: Rails specs
on: [pull_request]
env:
RAILS_ENV: test
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:11.6-alpine
env:
POSTGRES_USER: app_test
POSTGRES_DB: app_test
POSTGRES_HOST_AUTH_METHOD: "trust"
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Ruby version specified in `.ruby-version`
uses: eregon/use-ruby-action@master
- name: Install required apt packages
run: |
sudo apt-get -y install libpq-dev
- 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: Read Node.js version to install from `.nvmrc`
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm
- name: Install required Node.js version
uses: actions/setup-node@v1
with:
node-version: "${{ steps.nvm.outputs.NVMRC }}"
- 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: Setup test database
env:
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
PGUSER: app_test
PGHOST: localhost
run: |
bundle exec rake assets:precompile # precompile assets
bundle exec rails db:setup
- name: Run RSpec
env:
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
PGUSER: app_test
PGHOST: localhost
run: |
RUBYOPT='-W:no-deprecated -W:no-experimental' bundle exec rspec --format=documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment