Travis CI 构建失败:命令 "bundle exec rake" 以 1 退出

Travis CI Build Failure: The command "bundle exec rake" exited with 1

Travis 非常陌生CI。构建失败 The command "bundle exec rake" exited with 1.

构建在我最近的更改之前通过,其中涉及使用 Fileutils 写入 gem 目录,所以我假设这是罪魁祸首。

我找到了这个: 但仍然没有运气

有什么想法吗?

构建:https://travis-ci.org/AlphaDaniel/ruby_doc/builds/356485701?utm_source=github_status&utm_medium=notification

回购:https://github.com/AlphaDaniel/ruby_doc

    rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - /home/travis/build/AlphaDaniel/ruby_doc/vendor/bundle/ruby/2.2.0/gems/ruby_doc-2.2.0/favs.txt
/home/travis/build/AlphaDaniel/ruby_doc/config/environment.rb:23:in `<top (required)>'
/home/travis/build/AlphaDaniel/ruby_doc/Rakefile:5:in `require_relative'
/home/travis/build/AlphaDaniel/ruby_doc/Rakefile:5:in `<top (required)>'
/home/travis/.rvm/rubies/ruby-2.2.3/bin/bundle:30:in `block in <main>'
/home/travis/.rvm/rubies/ruby-2.2.3/bin/bundle:22:in `<main>'
Errno::ENOENT: No such file or directory @ utime_internal - /home/travis/build/AlphaDaniel/ruby_doc/vendor/bundle/ruby/2.2.0/gems/ruby_doc-2.2.0/favs.txt
/home/travis/build/AlphaDaniel/ruby_doc/config/environment.rb:23:in `<top (required)>'
/home/travis/build/AlphaDaniel/ruby_doc/Rakefile:5:in `require_relative'
/home/travis/build/AlphaDaniel/ruby_doc/Rakefile:5:in `<top (required)>'
/home/travis/.rvm/rubies/ruby-2.2.3/bin/bundle:30:in `block in <main>'
/home/travis/.rvm/rubies/ruby-2.2.3/bin/bundle:22:in `<main>'
(See full trace by running task with --trace)

如果您阅读错误消息和堆栈跟踪,这里的问题会变得更加清楚。 Errno::ENOENT: No such file or directory 基本上意味着 Ruby 找不到特定的文件或目录,在您的情况下是 /home/travis/build/AlphaDaniel/ruby_doc/vendor/bundle/ruby/2.2.0/gems/ruby_doc-2.2.0/favs.txt。 运行 的最后一行代码是对 FileUtils.touch 的调用(在 config/environment.rb:23 中)。

您可能已经问过自己 "But shouldn't that create this file if it does not yet exist?"。答案是:是的,但是 仅当父目录也存在时。当您 gem install 您的 gem 时,将为您创建这些目录。当您克隆存储库和 运行 rake 时情况并非如此(这也是 Travis 在看到 Ruby 项目时自动为您执行的操作)。

为了解决这个问题,我建议您将 fav_dir 方法的主体更改为如下内容:

File.expand_path("../favs.txt", __dir__)

乍一看有点神奇,但实际上并非如此:__dir__ is a Ruby method which returns the absolute path of the directory of the file from which this method is called. In this case this would be e.g. /usr/home/foo/dev/ruby_doc/config. Finally, File.expand_path 允许我们解析相对路径,在这种情况下最终结果将是 /usr/home/foo/dev/ruby_doc/favs.txt.
这样您就不需要指定任何绝对路径或对目录布局做出假设,并且还可以确保路径存在(因为源文件的目录及其父目录始终存在)。