我正在使用 Ruby on Rails 应用程序尝试 GitHub Actions for CI。
我的设置是使用 VM,而不是在容器中运行 Ruby 构建。
这是我的工作流程 yml。它一直运行而没有错误,直到步骤“设置数据库”。
name: Rails CI
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:10.10
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: db_test
ports:
- 5432/tcp
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
redis:
image: redis:latest
ports:
- 6379/tcp
steps:
- uses: actions/checkout@v1
- name: Set up ruby 2.5
uses: actions/setup-ruby@v1
with:
ruby-version: 2.5.5
- name: Set up node …Run Code Online (Sandbox Code Playgroud) 在我的 CI 中,我需要确保我的代码与 mongo 一起使用,因此我使用官方 mongo docker 映像并将所需的凭据作为 mongo 映像的环境变量传递。
build-on-mongo:
runs-on: ${{ matrix.os }}
env:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: password
MONGO_INITDB_DATABASE: vote-stuysu-org
services:
mongo:
image: mongo
ports:
# Maps tcp port 27017 on service container to the host
- 27017:27017
strategy:
matrix:
os: [ubuntu-20.04]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '14.x'
- name: Install dependencies
run: npm install
- name: Test
run: npm test
env:
MONGO_URL: mongodb://root:password@localhost:27017/vote-stuysu-org
Run Code Online (Sandbox Code Playgroud)
但是,在测试步骤中,会记录一条错误消息:
(节点:2158)未处理的PromiseRejectionWarning:MongoError:身份验证失败。
我在 nodejs 旁边使用 mongoose,所以这是负责身份验证的代码:
mongoose.connect(process.env.MONGO_URL, {
useUnifiedTopology: true, …Run Code Online (Sandbox Code Playgroud)