Github Actions - 未处理的拒绝 SequelizeConnectionError:启动数据包中未指定 PostgreSQL 用户名

jy9*_*y95 3 postgresql node.js sequelize.js github-actions

我为 CI/CD 设置了 Github Actions,但我在数据库连接方面遇到了困难。
由于sequelize允许指定另一个数据库url(使用“use_env_variable”选项),我更新了我的配置,如下所示:

{
  "test": {
    "dialect": "postgres",
    "schema": "exercises_library",
    "logging": false,
    "use_env_variable": "DATABASE_URL"
  },
  "production": {
    "dialect": "postgres",
    "schema": "exercises_library",
    "logging": false,
    "use_env_variable": "DATABASE_URL"
  }
}
Run Code Online (Sandbox Code Playgroud)

所以我在 Github Actions 中编写了我的工作流程:

name: Source Code CI/CD

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  ci:
    runs-on: ubuntu-latest
    container:
      image: node:12
    services:
# More explanation about that here :
# https://github.com/actions/example-services/blob/master/.github/workflows/postgres-service.yml
      postgres:
        image: postgres:12-alpine
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: jy95
          POSTGRES_DB: sourcecode
        ports: ["5432:5432"]
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
    env:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: jy95
      POSTGRES_DB: sourcecode
      # use postgres for the host here because we have specified a container for the job.
      # If we were running the job on the VM this would be localhost
      POSTGRES_HOST: postgres
    steps:
      - uses: actions/checkout@v2
      - name: Set DB Port
        env:
          POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
        run: |
          echo "::set-env name=POSTGRES_PORT::$POSTGRES_PORT"
      - name: Install
        run: |
          npm install -g npm@latest
          npm install -g codecov
          npm ci
      - name: Tests
        env:
          DATABASE_URL: '${{ env.POSTGRES_HOST }}://${{ env.POSTGRES_USER}}:${{env.POSTGRES_PASSWORD}}:${{env.POSTGRES_PORT}}/${{env.POSTGRES_DB}}'
        run: |
          npm test
      - name: Upload code coverage
        run: |
          npx codecov
  cd:
    runs-on: ubuntu-latest
    needs: ci

    steps:
      - uses: actions/checkout@v2
      - name: Docker login
        run: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
      - name: Build
        run: docker build -t sourcecode_api .
      - name: Tags
        run: |
          docker tag sourcecode_api ${{ secrets.DOCKER_USER }}/sourcecode_api:${{ github.sha }}
          docker tag sourcecode_api ${{ secrets.DOCKER_USER }}/sourcecode_api:latest
      - name: Push
        run: |
          docker push ${{ secrets.DOCKER_USER }}/sourcecode_api:${{ github.sha }}
          docker push ${{ secrets.DOCKER_USER }}/sourcecode_api:latest
Run Code Online (Sandbox Code Playgroud)

我的日志中出现此错误:

错误

我看到环境变量设置正确:

配置

我读过很多资源(关于 Github issues 或 Stackoverflow),但没有一个能解决我的问题。

提前致谢

jy9*_*y95 6

这是我的错字 - 如果它可以帮助任何人:

DATABASE_URL: 'postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@${{ env.POSTGRES_HOST }}:${{env.POSTGRES_PORT}}/${{env.POSTGRES_DB}}'
Run Code Online (Sandbox Code Playgroud)