name: Test

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

permissions:
  contents: read

jobs:
  test:
    name: ${{matrix.ruby}} ${{matrix.gemfile}}
    runs-on: ${{matrix.os}}-latest
    continue-on-error: ${{matrix.experimental}}

    env:
      BUNDLE_GEMFILE: ${{matrix.gemfile}}

    strategy:
      matrix:
        experimental: [false]

        os:
          - ubuntu

        ruby:
          - 2.6
          - 2.7
          - "3.0"
          - 3.1
          - 3.2
          - 3.3
          - 3.4

        gemfile:
          - gems/rack-v1.rb
          - gems/rack-v2.rb
          - gems/rack-v3.rb

        include:
          - experimental: false
            os: macos
            ruby: 3.4
            gemfile: gems/rack-v2.rb
          - experimental: false
            os: macos
            ruby: 3.4
            gemfile: gems/rack-v3.rb
          - experimental: true
            os: ubuntu
            ruby: head
            gemfile: gems/rack-v2.rb
          - experimental: true
            os: ubuntu
            ruby: head
            gemfile: gems/rack-v3.rb
          - experimental: true
            os: ubuntu
            ruby: 3.4
            gemfile: gems/rack-head.rb
        exclude:
          - { ruby: 3.3, gemfile: gems/rack-v1.rb }
          - { ruby: 3.4, gemfile: gems/rack-v1.rb }

    steps:
    - uses: actions/checkout@v4

    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: ${{matrix.ruby}}
        bundler-cache: true

    - name: Run tests
      timeout-minutes: 10
      run: bundle exec rake
