# .github/workflows/ruby.yml
name: Ruby

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

env:
  POSTGRES_DB: postgres
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: password

jobs:
  tests:
    name: Tests
    runs-on: ubuntu-latest

    services:
      postgres:
        image: postgres:12
        env:
          POSTGRES_PASSWORD: password
        ports: ['5432:5432']
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Setup Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.2.3
          bundler-cache: true

      - name: Install dependencies
        run: |
          sudo apt-get update && sudo apt-get -yqq install libpq-dev
          bundle install --jobs 4 --retry 3
      - name: Run Tests
        env:
          RAILS_ENV: test
          PGHOST: localhost
          DISABLE_SPRING: 1
        run: |
          cp config/database.ci.yml config/database.yml
          bundle exec rails db:schema:load
          bundle exec rspec --format progress
