travis-ci / travis.rb

Travis CI Client (CLI and Ruby library)
MIT License
1.59k stars 409 forks source link

travis setup heroku - No such file or directory #577

Open goldtreefrog opened 6 years ago

goldtreefrog commented 6 years ago

I am new to travis and not much more experienced with heroku. I recently updated Ruby and gems and removed old versions. I have travis integrated with github and all is well there. I have created a new repository successfully at heroku, so I have the same repository at github, heroku and on my local computer.

But I cannot get travis to play with heroku. When I type "travis setup heroku" - either in git bash or in the Windows command line - I get this response:

No such file or directory - git config --get travis.slug for a full error report, run travis report

When I run travis report, I get:

System Ruby: Ruby 2.4.1-p111 Operating System: Windows RubyGems: RubyGems 2.6.11

CLI Version: 1.8.8 Plugins: none Auto-Completion: yes Last Version Check: 2018-02-05 12:18:56 -0800

Session API Endpoint: https://api.travis-ci.org/ Logged In: as "goldtreefrog" Verify SSL: yes Enterprise: no

Endpoints org: https://api.travis-ci.org/ (access token, current)

Last Exception An error occurred running travis setup: Errno::ENOENT: No such file or directory - git config --get travis.slug from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/travis-1.8.8/lib/travis/cli/repo_command.rb:96:in `' from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/travis-1.8.8/lib/travis/cli/repo_command.rb:96:inload_slug' from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/travis-1.8.8/lib/travis/cli/repo_command.rb:58:in find_slug' from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/travis-1.8.8/lib/travis/cli/repo_command.rb:20:insetup' from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/travis-1.8.8/lib/travis/cli/command.rb:197:in execute' from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/travis-1.8.8/lib/travis/cli.rb:64:inrun' from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/travis-1.8.8/bin/travis:18:in <top (required)>' from C:/Ruby24-x64/bin/travis:22:inload' from C:/Ruby24-x64/bin/travis:22:in `

'

When I run it in git bash, I also get asked for an authorization key, but when I enter it, the program just hangs (until I press Ctrl-C, at which point it tries to use the key I just entered as a new git command on the next line, so it isn't actually accepting a key).

What do I need to do differently?

trcrkrn commented 6 years ago

My mentor and I were having the same problem; we were able to fix it by going into C:/Ruby23/lib/ruby/gems/2.3.0/gems/travis-1.8.8/lib/travis/cli/setup/heroku.rb and deleting a bit of code, so that the "run" function ultimately looks like this:

    def run
      deploy 'heroku' do |config|
        config['api_key'] = `heroku auth:token`.strip
        config['api_key'] = ask("Heroku API token: ") { |q| q.echo = "*" }.to_s if config['api_key'].empty?
        config['app']     = `heroku apps:info`.scan(/^=== (.+)$/).flatten.first
        config['app']     = ask("Heroku application name: ") { |q| q.default = repository.name }.to_s if config['app'].nil?
      end
    end

Your version of ruby is 2.4.0, but the paths should be the same. The command "travis setup heroku" should now work in your command prompt. Hope this helps.

goldtreefrog commented 6 years ago

Thanks for your solution. I worry that a later update will wipe it out - or maybe it will fix it!

I found a work-around that was easier, courtesy of Travis CI Documentation:

If you have both the Heroku and Travis CI command line clients installed, you can get your key, encrypt it and add it to your .travis.yml by running the following command from your project directory:

travis encrypt $(heroku auth:token) --add deploy.api_key

Doing that put the following into .travis.yml for me:

deploy: api_key: secure: (my api key)

Then I needed to add provider and app to the .travis.yml file, so that it ended up looking like this:

deploy: provider: heroku api_key: secure: (the step above filled this in for you) app: (your Heroku app name)

(Sorry I cannot get the code indented properly here. Everything is indented under "deploy" and "secure" is indented further under "api key." That makes it more clear.)