lux
lux

Reputation: 81

Github actions rails commands "/bin/ruby: invalid option -: (-h will show valid options) (RuntimeError)"

Im trying to implement Github Actions but not able to run the rails commands.

Raises errors when running bundle exec rake or bundle exec rails db:create in the github workflow.

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.

and here is my ruby.yml file:

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

Thank you everyone!

Upvotes: 5

Views: 1003

Answers (2)

Fiqi Fitransyah
Fiqi Fitransyah

Reputation: 1

I don't know if this could give you any help. But, you can try to do what I did based on my finding.

Go to the root directory of your app. Run the pwd command and see if there's any space in the path. And based on your problem, it probably have a space prior to : char.

I renamed my folder name which containing the space, and everything works fine

I hope it can help

Upvotes: 0

Max
Max

Reputation: 9889

RUBYOPT='-W:no-deprecated is not available for Ruby versions <2.7.

Change

ruby-version: 2.6.5

to

ruby-version: 2.7.0

Upvotes: 3

Related Questions