name: Continuous Integration

on:
  pull_request:
    branches: [main]

  workflow_dispatch:

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

# Tested platforms / Ruby versions:
#  - Ubuntu: MRI (3.1, 3.2, 3.3, 3.4), TruffleRuby (24), JRuby (9.4)
#  - Windows: MRI (3.1)

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

    if: >-
      github.event_name == 'workflow_dispatch' ||
      (github.event_name == 'pull_request' && !startsWith(github.event.pull_request.head.ref, 'release-please--'))

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

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

    strategy:
      fail-fast: false
      matrix:
        ruby: ["3.1", "3.4"]
        operating-system: [ubuntu-latest]
        fail_on_low_coverage: [true]
        java_version: [""]
        include:
          - ruby: "3.1"
            operating-system: windows-latest
            fail_on_low_coverage: false
          - ruby: "jruby-9.4"
            operating-system: ubuntu-latest
            fail_on_low_coverage: false
          - ruby: "jruby-10.0"
            operating-system: ubuntu-latest
            fail_on_low_coverage: false
            java_version: "21"
          - ruby: "truffleruby-24"
            operating-system: ubuntu-latest
            fail_on_low_coverage: false

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

      # Install updated version of Java if matrix.java_version is set
      - 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
