4

我在 GitHub 上有一个带有 PostgreSQL 的空 Rails 6 项目,我正在尝试配置 GitHub Actions 以在创建拉取请求时运行 Rails 测试套件。

我尝试遵循本指南,但不知何故它对我不起作用。

管道失败rails db:setup并抱怨:

could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

在我看来,由于某种原因,Rails 应用程序无法正确定位 PostgreSQL 服务。

这是我当前的GitHub 操作配置

name: CI

on:
  pull_request:
    branches:
      - '*'
  push:
    branches:
      - master
jobs:
  test:
    runs-on: ubuntu-latest

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

    steps:
      - uses: actions/checkout@master

      - name: Setup Ruby 2.7
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 2.7

      - name: Setup Node 12
        uses: actions/setup-node@v1
        with:
          node-version: 12.x

      - name: Install dependencies
        run: |
          sudo apt-get -yqq install libpq-dev
          bundle install
          yarn
          rails db:setup
      # Clean up git repo so the new rails template doesn't conflict
      - name: Remove git repo
        run: |
          rm -rf .git
      - name: Run tests
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
        run: |
          rails t

这是我的Rails 数据库配置

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: link_shortener_development

test:
  <<: *default
  host: localhost
  database: link_shortener_test
  username: link_shortener
  password: link_shortener

production:
  <<: *default
  database: link_shortener_production
  username: link_shortener
  password: <%= ENV['LINK_SHORTENER_DATABASE_PASSWORD'] %>

如果需要,完整的 GitHub 存储库位于:https ://github.com/dusan-rychnovsky/link-shortener

4

0 回答 0