name: Rails run RSpec tests

on: [push, pull_request]
  
jobs:
  build:

    runs-on: ubuntu-latest
    
    services:
      db:
        image: postgres:10.2
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
        ports:
          - 5432:5432        
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
    - uses: actions/checkout@v2
    - uses: ruby/setup-ruby@v1.32.1      
      with:
        ruby-version: 2.5.4
    - uses: actions/cache@v1
      with:
        path: vendor/bundle
        key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
        restore-keys: |
          ${{ runner.os }}-gems-
    - name: Bundle install
      env:
        RAILS_ENV: test
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: postgres
      run: |
        sudo apt-get -yqq install libpq-dev
        gem install bundler
        bundle config path vendor/bundle
        bundle install --jobs=3 --retry=3 --without production
    - name: Setup environment and database
      env:
        RAILS_ENV: test
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: postgres
      run: |
        cp env.example .env
        cp config/database.yml.ci config/database.yml
        bundle exec rails db:create
        bundle exec rails db:migrate
    - name: Run tests
      env:
        RAILS_ENV: test
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: postgres
      run: |
        bundle exec rspec
      
        

name: Rails run RSpec tests

on: [push, pull_request]
  
jobs:
    
  build:
    env:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      RAILS_ENV: test

    runs-on: ubuntu-latest
    
    services:
      db:
        image: postgres:10.2
        ports:
          - 5432:5432        
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
    - uses: actions/checkout@v2
    - uses: ruby/setup-ruby@v1.32.1      
      with:
        ruby-version: 2.5.4
    - uses: actions/cache@v1
      with:
        path: vendor/bundle
        key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
        restore-keys: |
          ${{ runner.os }}-gems-
    - name: Bundle install
      run: |
        sudo apt-get -yqq install libpq-dev
        gem install bundler
        bundle config path vendor/bundle
        bundle install --jobs=3 --retry=3 --without production
    - name: Setup environment and database
      run: |
        cp env.example .env
        cp config/database.yml.ci config/database.yml
        bundle exec rails db:create
        bundle exec rails db:migrate
    - name: Run tests
      run: |
        bundle exec rspec
      
        

Set env for entire job instead of per step
Set env for entire job instead of per step