###
# Please keep /.mergify.yml synced!
name: CI

on:
  push:
    branches:
      - master
  pull_request:
  workflow_dispatch:

jobs:
  main:
    name: >-
      ${{ matrix.os }} ${{ matrix.ruby }}
    runs-on: ${{ matrix.os }}-latest
    env:
      # See https://github.com/tmm1/test-queue#environment-variables
      TEST_QUEUE_WORKERS: 2
    strategy:
      fail-fast: false
      matrix:
        # [ubuntu, macos, windows]
        os: [windows]
        ruby: ['2.6', '2.7', '3.0', '3.1', 'head']
        include:
          - os: windows
            ruby: mingw
        exclude:
          - os: windows
            ruby: head

    steps:
      - name: windows misc
        if: matrix.os == 'windows'
        run: |
          # set TMPDIR, git core.autocrlf
          echo "TMPDIR=$env:RUNNER_TEMP" >> $GITHUB_ENV
          git config --system core.autocrlf false
      - name: checkout
        uses: actions/checkout@v3
      - name: set up Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: ${{ matrix.ruby }}

      - name: install dependencies
        run: bundle install --jobs 3 --retry 3
      - name: spec
        run: bundle exec rake spec
      - name: ascii_spec
        run: bundle exec rake ascii_spec
      - name: internal_investigation
        run: bundle exec rake internal_investigation

  jruby:
    name: JRuby 9.3
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v3
      - name: set up Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: jruby-9.3

      - name: install dependencies
        run: bundle install --jobs 3 --retry 3
      - name: spec
        run: bundle exec rake spec
      - name: ascii_spec
        run: bundle exec rake ascii_spec
      - name: internal_investigation
        run: bundle exec rake internal_investigation

  rspec4:
    runs-on: ubuntu-latest
    name: RSpec 4
    steps:
      - uses: actions/checkout@v3
      - name: Use latest RSpec 4 from `4-0-dev` branch
        run: |
          sed -e "/'rspec', '~> 3/d" -i Gemfile
          cat << EOF > Gemfile.local
            gem 'rspec', github: 'rspec/rspec', branch: '4-0-dev'
            gem 'rspec-core', github: 'rspec/rspec-core', branch: '4-0-dev'
            gem 'rspec-expectations', github: 'rspec/rspec-expectations', branch: '4-0-dev'
            gem 'rspec-mocks', github: 'rspec/rspec-mocks', branch: '4-0-dev'
            gem 'rspec-support', github: 'rspec/rspec-support', branch: '4-0-dev'
          EOF
      - name: set up Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 2.7
          bundler-cache: true
      - name: spec
        run: bundle exec rspec
