ruby-on-rails - Github actions rails commands "/bin/ruby: invalid option -: (-h will show valid options) (RuntimeError)"
问题描述
我试图实现 Github Actions 但无法运行 rails 命令。
在运行bundle exec rake
或bundle exec rails db:create
在 github 工作流程中引发错误。
Run bundle exec rake rails db:setup
bundle exec rake rails db:setup
shell: /bin/bash -e {0}
env:
PATH: /home/runner/.rubies/ruby-2.6.5/bin:/usr/share/rust/.cargo/bin:/home/runner/.config/composer/vendor/bin:/home/runner/.dotnet/tools:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin
RAILS_ENV: test
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_PORT: 5432
RUBYOPT: -W:no-deprecated -W:no-experimental
/home/runner/.rubies/ruby-2.6.5/bin/ruby: invalid option -: (-h will show valid options) (RuntimeError)
##[error]Process completed with exit code 1.
这是我的 ruby.yml 文件:
name: Ruby
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:11
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6.5
- name: Install library for postgres
run: sudo apt-get install libpq-dev
- name: Install dependencies
run: bundle install
- name: Setup Database
run: bundle exec rake rails db:setup
env:
RAILS_ENV: test
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_PORT: 5432
RUBYOPT: "-W:no-deprecated -W:no-experimental"
- name: Run tests
env:
RAILS_ENV: test
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_PORT: 5432
RUBYOPT: "-W:no-deprecated -W:no-experimental"
run: bundle exec rake
- name: Ensure that assets compile correctly
run: bundle exec rails assets:precompile
谢谢大家!
解决方案
RUBYOPT='-W:no-deprecated
不适用于 Ruby 版本 <2.7。
改变
ruby-version: 2.6.5
至
ruby-version: 2.7.0
推荐阅读
- python - 使用 Apache 使用同一服务器在多个域上实现 Django 通道
- r - 哪些行包含指定元素,使用 R
- bash - 将用户添加到 username.htpasswd
- python - 如何使用 pandas 数据框中的正则表达式在答案中删除点号:'(i)'、'(ii)'、'(iii)'?
- java - 如何在 Android 的 Appbar 中更改 Search View 的背景?
- python-3.x - DICTIONARY KEYERROR:如何在 python 字典中使用反斜杠作为键
- javascript - 如何使用 clearRect 不在画布上绘制移动对象
- reactjs - Firestore 无法获取数据
- chart.js - 如何使用 chart.js 版本 2.8.0(空间折线图)更改每个图例标签字体颜色?
- apache-flink - 在 flink 中将作业提交给特定的任务管理器