### Basic Ruby Setup in GitHub Actions Workflow Source: https://github.com/ruby/setup-ruby/blob/master/README.md This snippet demonstrates the basic usage of the setup-ruby action in a GitHub Actions workflow. It checks out the repository, sets up Ruby version '3.4', and enables automatic bundler installation and caching. ```yaml name: My workflow on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - uses: ruby/setup-ruby@v1 with: ruby-version: '3.4' # Not needed with a .ruby-version, .tool-versions or mise.toml bundler-cache: true # runs 'bundle install' and caches installed gems automatically - run: bundle exec rake ``` -------------------------------- ### Setup Ruby with Bundler Cache Source: https://github.com/ruby/setup-ruby/blob/master/README.md This snippet demonstrates how to set up a Ruby environment using the setup-ruby action and enable Bundler caching. It also shows how to manage a corrupted cache by setting a new cache-version. ```yaml - uses: ruby/setup-ruby@v1 with: bundler-cache: true cache-version: 1 ``` -------------------------------- ### Install Dependencies with Yarn Source: https://github.com/ruby/setup-ruby/blob/master/CONTRIBUTING.md Installs project dependencies using Yarn. This is preferred over npm for correct ESLint dependency installation. ```bash yarn install ``` -------------------------------- ### Automatic Bundler Install and Caching Source: https://github.com/ruby/setup-ruby/blob/master/README.md Configures the setup-ruby action to automatically run `bundle install` and cache the installed gems. This speeds up gem installation significantly and reduces requests to RubyGems.org. It requires a Gemfile in the working directory. ```yaml - uses: ruby/setup-ruby@v1 with: bundler-cache: true ``` -------------------------------- ### Matrix of Gemfiles for Testing Source: https://github.com/ruby/setup-ruby/blob/master/README.md Demonstrates setting up a Ruby environment with a specific Bundler version and caching for a matrix of Gemfiles in a GitHub Actions workflow. It configures the BUNDLE_GEMFILE environment variable to point to different Gemfile locations. ```yaml name: My workflow on: [push, pull_request] jobs: test: strategy: fail-fast: false matrix: gemfile: [ rails7, rails8 ] runs-on: ubuntu-latest env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile steps: - uses: actions/checkout@v5 - uses: ruby/setup-ruby@v1 with: ruby-version: '3.4' bundler-cache: true # runs 'bundle install' and caches installed gems automatically - run: bundle exec rake ``` -------------------------------- ### Matrix Testing with Multiple Ruby Versions and Platforms Source: https://github.com/ruby/setup-ruby/blob/master/README.md This snippet showcases how to use a matrix strategy in a GitHub Actions workflow to test across different Ruby versions (MRI, JRuby, TruffleRuby) and operating systems (Ubuntu, macOS). It includes checking out code, setting up the specified Ruby version, and caching gems. ```yaml name: My workflow on: [push, pull_request] jobs: test: strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0' ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4', head, jruby, jruby-head, truffleruby, truffleruby-head] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v5 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} bundler-cache: true # runs 'bundle install' and caches installed gems automatically - run: bundle exec rake ``` -------------------------------- ### Add Git Pre-commit Hook Source: https://github.com/ruby/setup-ruby/blob/master/CONTRIBUTING.md Copies the pre-commit script to the .git/hooks directory, enabling it as a pre-commit hook for Git. This helps automate checks before commits. ```bash cp pre-commit .git/hooks/pre-commit ``` -------------------------------- ### Regenerate dist/index.js with Yarn Source: https://github.com/ruby/setup-ruby/blob/master/CONTRIBUTING.md Regenerates the dist/index.js file using the 'package' script defined in yarn. This is typically used for packaging the project. ```bash yarn run package ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.