name: rubygems

on:
  pull_request:

  push:
    branches:
      - 3.5

concurrency:
  group: ci-${{ github.ref }}-${{ github.workflow }}
  cancel-in-progress: true

permissions:  # added using https://github.com/step-security/secure-workflows
  contents: read

jobs:
  rubygems:
    name: Rubygems on ${{ matrix.os.name }} (${{ matrix.ruby.name }})
    runs-on: ${{ matrix.os.value }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - { name: Ubuntu, value: ubuntu-24.04 }
          - { name: macOS, value: macos-14 }
          - { name: Windows, value: windows-2022 }

        ruby:
          - { name: "3.0", value: 3.0.7 }
          - { name: "3.1", value: 3.1.6 }
          - { name: "3.2", value: 3.2.6 }
          - { name: "3.3", value: 3.3.5 }

        include:
          - ruby: { name: jruby, value: jruby-9.4.8.0 }
            os: { name: Ubuntu, value: ubuntu-24.04 }

          - ruby: { name: truffleruby, value: truffleruby-24.0.1 }
            os: { name: Ubuntu, value: ubuntu-24.04 }

    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
      - name: Setup ruby
        uses: ruby/setup-ruby@7d3497fd78c07c0d84ebafa58d8dac60cd1f0763 # v1.199.0
        with:
          ruby-version: ${{ matrix.ruby.value }}
          bundler: none
      - name: Update RBS # https://github.com/ruby/rbs/pull/1612
        run: ruby -e 'begin; require "rbs"; rescue LoadError; exit; end; exec(*%w{gem install --version 3.4.0 rbs}) if Gem::Requirement.new([">= 1.6", "< 3.1.1"]).satisfied_by?(Gem::Version.new(RBS::VERSION))'
      - name: Install Dependencies
        run: bin/rake setup
      - name: Run Test
        run: bin/rake test
        if: matrix.ruby.name != 'truffleruby' && matrix.ruby.name != 'jruby'
      - name: Run Test isolatedly
        run: bin/rake test:isolated
        if: matrix.ruby.name == '3.3' && matrix.os.name != 'Windows'
      - name: Run Test (JRuby)
        run: JRUBY_OPTS=--debug bin/rake test
        if: startsWith(matrix.ruby.name, 'jruby')
      - name: Run Test (Truffleruby)
        run: TRUFFLERUBYOPT="--experimental-options --testing-rubygems" bin/rake test
        if: matrix.ruby.name == 'truffleruby'

    timeout-minutes: 60
