Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1bfe3ac

Browse files
committed
Recommend ruby/setup-ruby's bundler-cache: true option
Manually caching gems has many issues: * Not working if there is no Gemfile.lock but only a Gemfile * Not having the OS version in the key, which might cause binary incompatibility with system libraries of different ABI version. * Not taking the Ruby version in account. * Not taking the Ruby ABI version of development builds into accounts, which cannot be done with a key, but needs the commit hash. * Using restore-keys would grow the cache over time and have extra gems in the cache. * Those reasons are summarized in https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby#caching-bundle-install-manually
1 parent 3543324 commit 1bfe3ac

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

examples.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -468,21 +468,18 @@ Replace `~/.local/share/renv` with the correct `path` if not using Ubuntu.
468468

469469
## Ruby - Bundler
470470

471-
```yaml
472-
- uses: actions/cache@v2
473-
with:
474-
path: vendor/bundle
475-
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
476-
restore-keys: |
477-
${{ runner.os }}-gems-
478-
```
479-
When dependencies are installed later in the workflow, we must specify the same path for the bundler.
471+
Caching gems with Bundler correctly is not trivial and just using `actions/cache`
472+
is [not enough](https://github.com/ruby/setup-ruby#caching-bundle-install-manually).
473+
474+
Instead, it is recommended to use `ruby/setup-ruby`'s
475+
[`bundler-cache: true` option](https://github.com/ruby/setup-ruby#caching-bundle-install-automatically)
476+
whenever possible:
480477

481478
```yaml
482-
- name: Bundle install
483-
run: |
484-
bundle config path vendor/bundle
485-
bundle install --jobs 4 --retry 3
479+
- uses: ruby/setup-ruby@v1
480+
with:
481+
ruby-version: ...
482+
bundler-cache: true
486483
```
487484

488485
## Rust - Cargo

0 commit comments

Comments
 (0)