Travis CI cache a single file at a specified location

久未见 提交于 2019-12-25 03:16:58

问题


I am building a Ruby project on Travis CI and I use Gemfile ans Bundler to manage dependencies. My .travis.yml contains only one line about caching:

cache: bundler

And I rely on this in other places (Travis's default install command, cache directories, plus an extra bundle clean before uploading cache).

By default, Gemfile.lock is not cached. I want to cache it to make Bundler to skip dependency resolution and use the cached Gemfile.lock. I haven't found a valid solution for this.

Any ideas?


回答1:


I noticed the only comment under this question and came up with an idea, but I think it's more a workaround than a solution.

Copy Gemfile.lock from /tmp/cached in before_install phase. The copy Gemfile.lock to /tmp/cached in before_script phase. This way it'll be cached by Travis CI and the cache will be used by Bundler.

I'm still looking for a real solution.




回答2:


AFAICS from Travis' cacher implementation,

  • it will work if you specify a file name rather than a directory name under cache: directories:.1

With one caveat:

  • Initially, when there's no cache (thus the file doesn't yet exist), the cache restore step will create an empty directory with this name.
    • You need to manually detect and delete this directory early in your build

Example .travis.yml (using an evvar for the file's path to avoid repeating it everywhere):

env:
  global:
    - FILE=<path>
cache:
  directories:
    - $FILE
before_install:
  - if [[ -d $FILE ]]; then rm -rf "$FILE"; fi

# create and/or use the file

1That's because they use tar to make and extract cache archives, and tar doesn't care if you pass a file or a directory to it



来源:https://stackoverflow.com/questions/50492750/travis-ci-cache-a-single-file-at-a-specified-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!