name: Experimental Ruby Builds

on:
  workflow_dispatch:

env:
  # SimpleCov suggests setting the JRuby --debug flag to ensure that coverage
  # results from JRuby are complete.
  JRUBY_OPTS: --debug

# Experimental platforms / Ruby versions:
#  - Ubuntu: MRI (head), JRuby (head), TruffleRuby (head)
#  - Windows: MRI (head), JRuby (9.4), JRuby (head)

jobs:
  build:
    name: Ruby ${{ matrix.ruby }} on ${{ matrix.operating-system }}

    runs-on: ${{ matrix.operating-system }}
    continue-on-error: true

    env:
      FAIL_ON_LOW_COVERAGE: ${{ matrix.fail_on_low_coverage }}

    strategy:
      fail-fast: false
      matrix:
        fail_on_low_coverage: [true]
        java_version: [""]

        include:
          - ruby: head
            operating-system: ubuntu-latest
            fail_on_low_coverage: true

          - ruby: head
            operating-system: windows-latest
            fail_on_low_coverage: true

          - ruby: truffleruby-head
            operating-system: ubuntu-latest
            fail_on_low_coverage: false

          - ruby: jruby-9.4
            operating-system: windows-latest
            fail_on_low_coverage: false
            java_version: "21"

          - ruby: jruby-head
            operating-system: ubuntu-latest
            fail_on_low_coverage: false
            java_version: "21"

          - ruby: jruby-head
            operating-system: windows-latest
            fail_on_low_coverage: false
            java_version: "21"

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Initialize Java
        if: matrix.java_version != ''
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: ${{ matrix.java_version }}

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

      - name: Run rake
        run: bundle exec rake
