name: Ruby

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

jobs:
  ruby-versions:
    uses: ruby/actions/.github/workflows/ruby_versions.yml@master
    with:
      engine: cruby-jruby
      min_version: 2.5

  build:
    needs: ruby-versions
    runs-on: ubuntu-latest
    strategy:
      matrix:
        ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
    steps:
    - uses: actions/checkout@v4
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: ${{ matrix.ruby }}
    - name: Build and test with Rake
      run: |
        gem i test-unit test-unit-ruby-core
        RUBYOPT='--disable-did_you_mean' rake

  benchmark:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: 3.3.6
    - name: Test performance and accuracy
      run: |
        gem install bundler
        bundle install --jobs 4 --retry 2
        RUBYOPT='--disable-did_you_mean' bundle exec rake test:accuracy
        RUBYOPT='--disable-did_you_mean' bundle exec rake benchmark:memory
