gpt4 book ai didi

ruby-on-rails - Github 操作工作流程 PG::ConnectionBad:无法连接到服务器:运行 bundle exec rake 时没有此类文件或目录

转载 作者:行者123 更新时间:2023-12-03 08:40:59 25 4
gpt4 key购买 nike

这是我的第一个问题。

我正在尝试将 github actions 集成到我的 Rails 项目中。

我的 ruby​​.yml 是这样的:

name: Ruby

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@ec106b438a1ff6ff112340de34ddc62c540232e0
with:
ruby-version: 2.6.5
- name: Install dependencies
run: bundle install
- name: Run tests
run: bundle exec rake

捆绑步骤需要很多时间,我不知道是否可以只加载 Gemfile.lock 而不是每次都运行捆绑。但运行正常。

问题在于测试步骤。

错误如下:

rails aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
/home/runner/work/project/project/test/test_helper.rb:10:in `<main>'
/home/runner/work/project/project/test/application_system_test_case.rb:1:in `<main>'
/home/runner/work/project/project/test/system/create_practice_test.rb:1:in `<main>'
/home/runner/work/GPLM/GPLM/bin/rails:9:in `<top (required)>'
/home/runner/work/GPLM/GPLM/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => test:system
(See full trace by running task with --trace)
Coverage report generated for Minitest to /home/runner/work/project/project/coverage. 31 / 3352 LOC (0.92%) covered.
SimpleCov failed with exit 1
##[error]Process completed with exit code 1.

谢谢大家。

最佳答案

您需要将 Postgres 服务添加到 GitHub Action 配置中。例如:

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

捆绑安装之前,您需要安装依赖库:

- name: Install library for postgres
run: sudo apt-get install libpq-dev

不要忘记设置数据库:

- name: Setup Database
run: |
cp config/YOUR_GITHUB_ACTIONS_DATABASE.yml config/database.yml
bundle exec rails db:setup
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
RAILS_ENV: test

当然,在这里,您必须根据您的具体情况定制命令。最简单的方法是专门为 GitHub Actions 创建一个单独的数据库配置文件。但您也可以拥有一个特殊的 CI 环境。

关于ruby-on-rails - Github 操作工作流程 PG::ConnectionBad:无法连接到服务器:运行 bundle exec rake 时没有此类文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62783381/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com