Skip to content

Cache is hit but "bundle install" still try to install all dependency instead of just using them #201

Closed

Description

@onevcat

I followed the example here to use cache in my action: https://github.com/actions/cache/blob/master/examples.md#ruby---bundler

- uses: actions/cache@v1
with:
    path: vendor/bundle
    key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
    restore-keys: |
    ${{ runner.os }}-gems-
- name: Bundle install
run: |
    bundle config path vendor/bundle
    bundle install --job

However, although the cache is hit and restored to vendor/bundle, it seems that the required gems are still being installed. It slows down the CI and wastes a lot of resource. Here is the screenshot of the result, you can see bundle install installs the gems instead of just using them.

截屏2020-02-2722 29 40

The final Post actions/cache@v1 reports the "Cache hit occurred".

Here is an example job result: https://github.com/onevcat/Kingfisher/pull/1396/checks?check_run_id=472401799

Any suggestions would be helpful! Thank you.

Activity

  1. mattt commented on Mar 5, 2020

    @mattt

    @onevcat Have you tried conditionalizing the bundle install step?

    - uses: actions/cache@v1
      id: bundler-cache
      with:
        path: vendor/bundle
        key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
        restore-keys: |
          ${{ runner.os }}-gems-
    - name: Bundle install
      if: steps.bundler-cache.outputs.cache-hit != 'true'
      run: |
        bundle config path vendor/bundle
        bundle install --job
  2. onevcat commented on Mar 6, 2020

    @onevcat
    Author

    @mattt Thank you. Good idea! I will try it.

    In fact, the cache action works sometimes, even for the same cache key:

    Success case: https://github.com/onevcat/Kingfisher/runs/488869840?check_suite_focus=true
    Failure case: https://github.com/onevcat/Kingfisher/runs/472663143?check_suite_focus=true

    Both were restored from the same key, but have different behavior on bundle install. It confuses me a bit.

    Anyway, I will add the condition checking to the install step and watch the result.

  3. onevcat commented on Mar 8, 2020

    @onevcat
    Author

    Umm, setting a condition does not work. It gives a "Bundler::GemNotFound: Could not find minitest-5.14.0 in any of the sources" error now. It seems that the restored gems are not recognized at all. (Here is a sample error build for this case.)

    Maybe it is related to the ruby (and gem) version? I am using rbenv on my local machine to manage ruby versions, and have a .ruby-version in the project root. I will try to dig it deeper to see how it affects.

  4. onevcat commented on Mar 8, 2020

    @onevcat
    Author

    Oh, it turned out to be my fault. I also skipped the bundle path setting. I have to split bundle config and bundle install to two steps to make it work. (Of course!)

    The following steps work fine for now. I will keep an eye on it to see whether any unexpected behavior happens again.

    steps:
      - uses: actions/checkout@v1
      - uses: actions/cache@v1
        id: bundler-cache
        with:
          path: vendor/bundle
          key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
          restore-keys: |
            ${{ runner.os }}-gems-
      - name: Bundle setup
         run: bundle config path vendor/bundle
      - name: Bundle install
         if: steps.bundler-cache.outputs.cache-hit != 'true'
         run: bundle install --jobs 4 --retry 3
      # More steps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions