---
name: Unit tests

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

# minimal permissions
permissions:
  contents: read

env:
  CI: true

jobs:
  matrix:
    runs-on: ubuntu-24.04
    outputs:
      ruby: ${{ steps.ruby.outputs.versions }}
    steps:
      - uses: actions/checkout@v4
      - name: Install Ruby 3.4
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: '3.4'
          bundler-cache: true
      #- name: Run RuboCop
      #  run: bundle exec rake rubocop
      - id: ruby
        uses: voxpupuli/ruby-version@v1

  linux_unit_tests:
    needs: matrix
    name: Ruby version
    strategy:
      fail-fast: false
      matrix:
        ruby: ${{ fromJSON(needs.matrix.outputs.ruby) }}
    runs-on: ubuntu-24.04
    steps:
      - name: Checkout current PR
        uses: actions/checkout@v4

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

      - name: Display bundle environment
        run: |
          bundle env

      - run: bundle exec rake spec_random

  tests:
    needs:
      - matrix
      - linux_unit_tests
    runs-on: ubuntu-24.04
    name: Test suite
    steps:
      - run: echo Test suite completed
