name: CI

on:
  pull_request:
    branches: [main, 4.x]
  workflow_dispatch:

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

    # Skip this job if triggered by a release PR
    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: ${{ matrix.experimental == 'Yes' }}
    env: { JAVA_OPTS: -Djdk.io.File.enableADS=true }

    strategy:
      fail-fast: false
      matrix:
        # Only the latest versions of JRuby and TruffleRuby are tested
        ruby: ["3.2", "3.4", "4.0", "truffleruby-24.2.1", "jruby-10.0.0.1"]
        operating-system: [ubuntu-latest]
        experimental: [No]
        java_version: [""]
        include:
          - ruby: 3.2
            operating-system: windows-latest
            experimental: No

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

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

      - name: Setup Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: ${{ matrix.ruby }}
          bundler-cache: true # runs 'bundle install' and caches installed gems automatically

      - name: Run Build
        run: bundle exec rake default

      - name: Test Gem
        run: bundle exec rake test:gem
