.github/workflows/ruby.yml

Summary

Maintainability
Test Coverage
name: Ruby

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        ruby: [2.6, 2.7, 3.0, 3.1] # 2.6 is EOL March 31, 2022; kept for information only
        rails: [5.2.6, 6.1.4.4, 7.0.1] # 5.2 EOL in 01 Jun 2022; kept for information only
        exclude:
        # excludes Rails 5.2.x on Ruby 3.0 and on 3.1 
        # Note that 6.0.x should also exclude 3.0 and 3.1 but we're not testing it.
        - rails: 5.2.6
          ruby: 3.0
        - rails: 5.2.6
          ruby: 3.1
        # Rails 7.0.1 requires >= 2.7.0, so excluding 2.6
        - rails: 7.0.1
          ruby: 2.6
    env:
      RAILS_VERSION: ${{ matrix.rails }}

    steps:
    - uses: actions/checkout@v4
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: ${{ matrix.ruby }}
        bundler-cache: true # runs 'bundle install' and caches installed gems automatically

    - uses: actions/cache@v4
      id: cache
      with:
        path: |
          rswag-ui/node_modules
          vendor/bundle
        key: ${{ runner.os }}-ruby_${{ matrix.ruby }}-rails_${{ matrix.rails }}-${{ hashFiles('Gemfile', '**/package-lock.json') }}

    - name: Install dependencies
      run: |
        if [ $(cut -d '.' -f 1 <<< "${{ matrix.ruby }}") -lt 3 ]; then
          gem update --system 3.4.22
        else
          gem update --system
        fi
        bundle install
        cd rswag-ui && npm install

    - name: rswag-api
      run: |
        cd rswag-api
        bundle exec rspec

    - name: rswag-specs
      if: success() || failure()
      run: |
        cd rswag-specs
        bundle exec rspec

    - name: rswag-ui
      if: success() || failure()
      run: |
        cd rswag-ui
        bundle exec rspec

    - name: test-app
      if: success() || failure()
      run: |
        cd test-app
        bundle exec rake db:migrate db:test:prepare
        bundle exec rspec