简体   繁体   中英

Rails Postgres Github Actions error: PG::ConnectionBad: fe_sendauth: no password supplied

I am trying to get a Rails app build and test working on Github Actions using Postgresql, based on the configuration shown in this article and this article . When I push a branch to Github to kick off the action, I get the following error when the tests are run:

PG::ConnectionBad: fe_sendauth: no password supplied

I provided the username and password for the database as shown in those articles, why is it failing?

[...]

jobs:
  test:

    runs-on: ubuntu-latest

    services:
      postgres:
        image: postgres:13
        ports:
          - 5432:5432
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    [...]
    - name: Install postgres
      run: sudo apt-get install libpq-dev
    - name: Install dependencies
      run: bundle install
    - name: Setup database
      env:
        RAILS_ENV: test
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: postgres
      run: |
        cp config/database.yml.github-actions config/database.yml
        bundle exec rake db:create
        bundle exec rake db:schema:load
    - name: Run tests
      run: bundle exec rake

The issue is a simple omission from the configuration file: I set the env variables section for the Setup database step, but not the Run tests step. As a result, the error is correct, during that step, there is no username/password being provided so it cannot connect to the DB server. Adding it to the test step solves the problem:

- name: Run tests
  run: bundle exec rake
  env:
    RAILS_ENV: test
    POSTGRES_USER: postgres
    POSTGRES_PASSWORD: postgres

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM