Update the ruby caching example

The ruby version should be a part of the cache hash. Gems built for one version of ruby may not work with a different version of ruby. Making the ruby version a part of the cache key will bust the cache when the ruby version changes.

 Most ruby projects have a `.ruby-version` file that can be hashed into the cache key.

Use the `--deployment` option with `bundle install` to properly set `vendor/bundle` as the gem path, and also set other options optimized for CI deployment. https://bundler.io/v2.0/man/bundle-install.1.html#DEPLOYMENT-MODE
This commit is contained in:
Scott Jacobsen 2020-05-01 11:52:15 -06:00 committed by GitHub
parent 9ceee97d99
commit 431ddd542e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -381,17 +381,15 @@ Replace `~/.local/share/renv` with the correct `path` if not using Ubuntu.
- uses: actions/cache@v1
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
key: ${{ runner.os }}-gems-${{ hashFiles('.ruby-version') }}-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
${{ runner.os }}-gems-${{ hashFiles('.ruby-version') }}-
```
When dependencies are installed later in the workflow, we must specify the same path for the bundler.
When dependencies are installed later use the `--deployment` flag which tells bundler to install gems to `vendor/bundle`, and sets other options optimized for a CI workflow.
```yaml
- name: Bundle install
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
run: bundle install --deployment --jobs 4 --retry 3
```
## Rust - Cargo