title: Github Actions: Getting error when Setting Up Postgres database together with Ruby on Rails
body: <p>I'm trying to set up my CI in Github actions, already gone through with online tutorials and tried setting up by mirroring what I have learned.</p>
  <p>My problem is it produces a NoMethodError: undefined method `[]' for nil:NilClass when setting up the database even though the Ruby has been successfully installed.</p>
  <p>Here is my github actions configuration:</p>
  <pre><code>name: RSpec Unit Tests
  
  on:
    push:
      branches: [ main ]
    pull_request:
      branches: [ main ]
  
  jobs:
    test:
      runs-on: ubuntu-latest
      services:
        postgres:
          image: postgres
          ports: ['5432:5432']
          env:
            POSTGRES_USERNAME: 'postgres'
            POSTGRES_PASSWORD: 'test'
          options: &gt;-
            --health-cmd pg_isready
            --health-interval 10s
            --health-timeout 5s
            --health-retries 5
    
      steps:
      - uses: actions/checkout@v2
  
      - name: Setup Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.0.0
          bundler-cache: true
  
      - name: Setup Database
        run: |
          cp config/database.yml.sample config/database.yml
          bundle exec rake db:create
          bundle exec rake db:schema:load
        env:
          DATABASE_USERNAME: 'postgres'
          DATABASE_PASSWORD: 'test'
          DATABASE_HOST: 127.0.0.1
  
      - name: Run Rspec Unit Tests
        run: bundle exec rspec
        env:
          DATABASE_HOST: 127.0.0.1
          DATABASE_USERNAME: 'postgres'
          DATABASE_PASSWORD: 'test'
          RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
  </code></pre>
  <p>Here are the error logs:</p>
  <pre><code>Run cp config/database.yml.sample config/database.yml
    cp config/database.yml.sample config/database.yml
    bundle exec rake db:create
    bundle exec rake db:schema:load
    shell: /usr/bin/bash -e {0}
    env:
      DATABASE_USERNAME: postgres
      DATABASE_PASSWORD: test
      DATABASE_HOST: 127.0.0.1
  rake aborted!
  NoMethodError: undefined method `[]' for nil:NilClass
  
  .... many directory logs here
  
  /opt/hostedtoolcache/Ruby/3.0.0/x64/bin/bundle:23:in `load'
  /opt/hostedtoolcache/Ruby/3.0.0/x64/bin/bundle:23:in `&lt;main&gt;'
  Tasks: TOP =&gt; db:create =&gt; db:load_config =&gt; environment
  (See full trace by running task with --trace)
  Error: Process completed with exit code 1.
  </code></pre>
  <p>How do I fix my database so my CI will proceed with the actual RSpec Testing?</p>