Bundler/bundle not using cache in Github Actions

With the following configuration…

  test-jekyll:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-ruby@v1
        with:
          ruby-version: "2.6"
      - uses: actions/cache@v2
        with:
          path: vendor/bundle
          key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
          restore-keys: |
            ${{ runner.os }}-gems-
      - run: gem install bundler
      - run: bundle config path vendor/bundle
      - run: bundle install --jobs 4 --retry 3
      - run: mkdir public
      - run: bundle exec jekyll build --destination ./public
        env:
          JEKYLL_ENV: production
      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_branch: gh-pages-test
          enable_jekyll: true

Seems to hit the cache file, but not use the cache when running bundle install. It ends up taking 3+ minutes! I’m following the same instructions as here: https://github.com/actions/cache/blob/ff937cc95032836a535d249de4ce2fc52aeae834/examples.md#ruby---bundler

As a live example^^

Is there a configuration I need to change to have bundle install command use the cache?

Thanks!

Hi @avimoondra,

Thank you for being here!
In your workflow, cache hit cause bundle installation is not stored into cache. Hence, it will take 3mins to install again. You can edit Gemfile.lock and push an empty submit, change the hash value will cause a cache miss, new cache will contain your bundle installation content. Then, you will find if cache hit next time, it will reduce much of time for the step.

I forked your repo, if i manually create a catch miss in prior workflow, in next workflow, it only takes 2s for the step.

Thanks.

Great this worked - had to bust the cache! Thanks @weide-zhou