name: test

on:
  push:
  pull_request:
  schedule:
    - cron: '15 11 * * 0'
  workflow_dispatch:

env:
  JAVA_OPTS: '-Xms60M -Xmx1G'

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

  test:
    needs: ruby-versions
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
        os: [ ubuntu-latest, macos-latest, windows-latest ]
        include:
          # jruby-10.0.2.0 does not support Data instances with ivars
          - { os: windows-latest, ruby: jruby-head }
          - { os: macos-latest, ruby: jruby-head }
          - { os: ubuntu-latest, ruby: jruby-head }
          - { os: windows-latest, ruby: ucrt }
          - { os: windows-latest, ruby: mingw }
          - { os: windows-latest, ruby: mswin }
          - { os: macos-15-intel, ruby: 2.5 }
        exclude:
          # CRuby < 2.6 does not support macos-arm64
          - { os: macos-latest, ruby: 2.5 }
          - { os: windows-latest, ruby: truffleruby }
          - { os: windows-latest, ruby: truffleruby-head }
    steps:
      - uses: actions/checkout@v7.0.1
      - name: Set up Ruby
        uses: ruby/setup-ruby-pkgs@v1
        with:
          ruby-version: ${{ matrix.ruby }}
          apt-get: "haveged libyaml-dev"
          brew: libyaml
          vcpkg: libyaml
      - name: Set JRuby ENV vars
        run: |
          echo 'JAVA_OPTS=-Xmx1g' >> $GITHUB_ENV
        if: ${{ ! startsWith(matrix.ruby, 'jruby') }}
      - name: Install dependencies
        run: bundle install --jobs 1
      - name: Run test
        id: test
        run: rake
      - name: Install gem
        run: rake install
        if: ${{ steps.test.outcome == 'success' }}

  test-ibm:
    if: github.repository == 'ruby/psych'
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-24.04-ppc64le
          - os: ubuntu-24.04-s390x
    steps:
      - uses: actions/checkout@v7.0.1
      - name: Set up Ruby
        run: |
          sudo apt-get update
          sudo apt-get install ruby-full bundler libyaml-dev
      - name: Install dependencies
        run: sudo bundle install --jobs $(nproc)
      - name: Run test
        id: test
        run: rake
      - name: Install gem
        run: sudo rake install
        if: ${{ steps.test.outcome == 'success' }}
